Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-14 Thread Junio C Hamano
Duy Nguyen writes: > On Sat, Apr 12, 2014 at 11:19 AM, Junio C Hamano wrote: > >> In the spectrum between useful and insane, there is a point where we >> should just tell the insane: don't do it then. > > ... A process' dying is a > way of telling people "this is insane" without having to draw a

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-12 Thread Duy Nguyen
On Sat, Apr 12, 2014 at 11:19 AM, Junio C Hamano wrote: > Duy Nguyen writes: > >> On Sat, Apr 12, 2014 at 3:43 AM, Junio C Hamano wrote: >>> Having said that, nobody sane would be running two simultaneous >>> operations that are clearly write-oriented competing with each other >>> against the sa

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-12 Thread Junio C Hamano
Junio C Hamano writes: > What is the race under discussion about? It is about the index, > which corresponds one-to-one to the working tree, so in order for > the "race" to matter, you need to be racing against another process > that is not cooperating with you (e.g. a continuous and uncontrolle

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-11 Thread Junio C Hamano
Duy Nguyen writes: > On Sat, Apr 12, 2014 at 3:43 AM, Junio C Hamano wrote: >> Having said that, nobody sane would be running two simultaneous >> operations that are clearly write-oriented competing with each other >> against the same index file. > > When it comes to racing, sanity does not matt

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-11 Thread Duy Nguyen
On Sat, Apr 12, 2014 at 3:43 AM, Junio C Hamano wrote: > Having said that, nobody sane would be running two simultaneous > operations that are clearly write-oriented competing with each other > against the same index file. When it comes to racing, sanity does not matter much. People could just do

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-11 Thread Yiannis Marangos
On Fri, Apr 11, 2014 at 01:43:47PM -0700, Junio C Hamano wrote: > Having said that, nobody sane would be running two simultaneous > operations that are clearly write-oriented competing with each other > against the same index file. So in that sense that can be done as a > less urgent follow-up for

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-11 Thread Junio C Hamano
Junio C Hamano writes: > Yeah, I was hoping that the real write codepath (as opposed to "this > is read only and we read the index without holding a lock---now we > noticed that the index needs refreshing, and we know how the > resulting refreshed index should look like, perhaps we can write it >

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-11 Thread Junio C Hamano
Duy Nguyen writes: > On Fri, Apr 11, 2014 at 2:28 AM, Junio C Hamano wrote: >> Yiannis Marangos writes: >> >>> + n = xpread(fd, sha1, 20, st.st_size - 20); >>> + if (n != 20) >>> + goto out; >> >> I think it is possible for pread(2) to give you a short-read. >> >> The existi

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-11 Thread Yiannis Marangos
On Fri, Apr 11, 2014 at 09:47:09AM +0200, Torsten Bögershausen wrote: > 6. process A applies a commit: > - read the index into memory > - take the lock > - update the index file on disc > - release the lock So here we can have race condition. Maybe we should implement Duy

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-11 Thread Duy Nguyen
On Fri, Apr 11, 2014 at 2:28 AM, Junio C Hamano wrote: > +static int verify_index_from(const struct index_state *istate, const char > *path) > +{ > + int fd; > + ssize_t n; > + struct stat st; > + unsigned char sha1[20]; > + > + if (!istate->initialized) > +

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-11 Thread Torsten Bögershausen
On 2014-04-10 21.28, Junio C Hamano wrote: > Yiannis Marangos writes: > >> +n = xpread(fd, sha1, 20, st.st_size - 20); >> +if (n != 20) >> +goto out; > > I think it is possible for pread(2) to give you a short-read. > > The existing callers of emulated mmap and index-pack ar

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-10 Thread Duy Nguyen
On Fri, Apr 11, 2014 at 2:28 AM, Junio C Hamano wrote: > Yiannis Marangos writes: > >> + n = xpread(fd, sha1, 20, st.st_size - 20); >> + if (n != 20) >> + goto out; > > I think it is possible for pread(2) to give you a short-read. > > The existing callers of emulated mmap and

Re: [PATCH v7 2/2] Verify index file before we opportunistically update it

2014-04-10 Thread Junio C Hamano
Yiannis Marangos writes: > + n = xpread(fd, sha1, 20, st.st_size - 20); > + if (n != 20) > + goto out; I think it is possible for pread(2) to give you a short-read. The existing callers of emulated mmap and index-pack are prepared to handle a short-read correctly, but I do n