delorie.com/archives/browse.cgi | search |
X-Recipient: | archive-cygwin AT delorie DOT com |
X-SWARE-Spam-Status: | No, hits=-9.0 required=5.0 tests=AWL,BAYES_00,KHOP_PGP_SIGNED,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RCVD_IN_HOSTKARMA_W,SPF_HELO_PASS,T_RP_MATCHES_RCVD,URI_HEX |
X-Spam-Check-By: | sourceware.org |
Message-ID: | <5004EF52.1000607@redhat.com> |
Date: | Mon, 16 Jul 2012 22:51:30 -0600 |
From: | Eric Blake <eblake AT redhat DOT com> |
User-Agent: | Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 |
MIME-Version: | 1.0 |
To: | cygwin <cygwin AT cygwin DOT com> |
Subject: | pread vs. git |
OpenPGP: | url=http://people.redhat.com/eblake/eblake.gpg |
X-IsSubscribed: | yes |
Mailing-List: | contact cygwin-help AT cygwin DOT com; run by ezmlm |
List-Id: | <cygwin.cygwin.com> |
List-Subscribe: | <mailto:cygwin-subscribe AT cygwin DOT com> |
List-Archive: | <http://sourceware.org/ml/cygwin/> |
List-Post: | <mailto:cygwin AT cygwin DOT com> |
List-Help: | <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> |
Sender: | cygwin-owner AT cygwin DOT com |
Mail-Followup-To: | cygwin AT cygwin DOT com |
Delivered-To: | mailing list cygwin AT cygwin DOT com |
--------------enig9E4D8B95239CEF1B8449F790 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Recent git added a hack to explicitly avoid cygwin's pread as unsafe: http://git.661346.n2.nabble.com/PATCH-v2-1-1-index-pack-Disable-threading-o= n-cygwin-td7562195.html Comments like this aren't very re-assuring either: http://sourceware.org/ml/cygwin/2011-06/msg00057.html or this big hairy comment in the source of fhandle_disk_file: Using this handle for pread/pwrite would break atomicity, because the read/write operation would have to be followed by a seek back to the old file position. What we do is to open another handle to the file on the first call to either pread or pwrite. This is used for any subsequent pread/pwrite. Thus the current file position of the "normal" file handle is not touched. FIXME: Note that this is just a hack. The problem with this approach is that a change to the file permissions might disallow to open the file with the required permissions to read or write. This appears to be a border case, but that's exactly what git does. It creates the file for reading and writing and after writing it, it chmods the file to read-only. Then it calls pread on the file to examine the content. This works, but if git would use the original handle to pwrite to the file, it would be broken with our approach. One way to implement this is to open the pread/pwrite handle right at file open time. We would simply maintain two handles, which wouldn't be much of a problem given how we do that for other fhandler types as well. However, ultimately fhandler_disk_file should become a derived class of fhandler_base_overlapped. Each raw_read or raw_write would fetch the actual file position, read/write from there, and then set the file position again. Fortunately, while the file position is not maintained by the I/O manager, it can be fetched and set to a new value by all processes holding a handle to that file object. Pread and pwrite differ from raw_read and raw_write just by not touching the current file pos. What still remains to make pread a first-class thread-safe implementation that obeys POSIX, so that I don't have to cripple my next build of git to avoid threaded pread? --=20 Eric Blake eblake AT redhat DOT com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enig9E4D8B95239CEF1B8449F790 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJQBO9SAAoJEKeha0olJ0NqJ6MH/jcfWHxiR5a6xWBEqPwaSwB1 Bh4934rUkXHzyCqnTtKlYETf8xgg+ud5UDtBKmGaGDJoBemxZsUlU5wg7g/IztoQ Xe934xRBYayLzymJMoOtPgNQDug2KiZ0WvNuLhbyZ8ZUfz0j4d9hb0oLKQ1sovwE zTf+MwaTQCdtjAmhMaaK+/vcld27rgCgEXcpIhqUlBKD8bSOQvyoMyk2yshZAhVx HkO1zhCYvz0tcXMp6v+bOtRgFDRWm7mFi0Q7s2TUbGOuRi8mskWChjQ14S9c2jZ9 L0VdRHsHXD8/Kw32j+Y/ELwMLfr555WbqnXvki67YnkkhReKgs9mpVbCi7cjRhE= =XOag -----END PGP SIGNATURE----- --------------enig9E4D8B95239CEF1B8449F790--
webmaster | delorie software privacy |
Copyright © 2019 by DJ Delorie | Updated Jul 2019 |