Re: 2.3.7: generic_write_page(): O_APPEND & inode->i_size not SMP

Andrea Arcangeli (andrea@suse.de)
Tue, 22 Jun 1999 02:28:59 +0200 (CEST)


On Mon, 21 Jun 1999, Manfred Spraul wrote:

>1) if 2 threads write to an O_APPEND file, then they could write to the same
>address:

They can't write over the same page at the same time though. Anyway I am
not sure if this is correct or not.

I seen also another problem of this kind. We may have a reader that will
read data in copy_to_user, while a writer is in the middle of the
copy_from_user. To avoid this we need a kind of read locking over the page
that may be shared by all readers.

>2) setting inode->i_size is not SMP safe.
>
>generic_file_read():
>1924 if (pos > inode->i_size)
>1925 inode->i_size = pos;
>1926

True, i_size is still protected only by the big kernel lock so this patch
follows:

Index: mm/filemap.c
===================================================================
RCS file: /var/cvs/linux/mm/filemap.c,v
retrieving revision 1.1.2.114
diff -u -r1.1.2.114 filemap.c
--- mm/filemap.c 1999/06/21 17:10:59 1.1.2.114
+++ mm/filemap.c 1999/06/22 00:19:40
@@ -1977,15 +1974,16 @@
pos += status;
buf += status;
}
- *ppos = pos;
- if (pos > inode->i_size)
- inode->i_size = pos;

if (page_cache)
page_cache_free(page_cache);

err = written ? written : status;
lock_kernel();
+
+ *ppos = pos;
+ if (pos > inode->i_size)
+ inode->i_size = pos;
out:
return err;
}

Andrea Arcangeli

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/