blob: 4a6f7f440658d4461a1f441a78516efe13a2c855 [file] [log] [blame]
Josef "Jeff" Sipek42cf1192006-12-08 02:36:31 -08001#include <linux/module.h>
2#include <linux/fs.h>
3#include <linux/fs_stack.h>
4
5/* does _NOT_ require i_mutex to be held.
6 *
7 * This function cannot be inlined since i_size_{read,write} is rather
8 * heavy-weight on 32-bit systems
9 */
Erez Zadok1b8ab812009-12-03 21:56:09 -050010void fsstack_copy_inode_size(struct inode *dst, struct inode *src)
Josef "Jeff" Sipek42cf1192006-12-08 02:36:31 -080011{
Erez Zadok1b8ab812009-12-03 21:56:09 -050012 loff_t i_size;
13 blkcnt_t i_blocks;
14
15 /*
16 * i_size_read() includes its own seqlocking and protection from
17 * preemption (see include/linux/fs.h): we need nothing extra for
18 * that here, and prefer to avoid nesting locks than attempt to keep
19 * i_size and i_blocks in sync together.
20 */
21 i_size = i_size_read(src);
22
23 /*
24 * But if CONFIG_LBDAF (on 32-bit), we ought to make an effort to
25 * keep the two halves of i_blocks in sync despite SMP or PREEMPT -
26 * though stat's generic_fillattr() doesn't bother, and we won't be
27 * applying quotas (where i_blocks does become important) at the
28 * upper level.
29 *
30 * We don't actually know what locking is used at the lower level;
31 * but if it's a filesystem that supports quotas, it will be using
32 * i_lock as in inode_add_bytes(). tmpfs uses other locking, and
33 * its 32-bit is (just) able to exceed 2TB i_size with the aid of
34 * holes; but its i_blocks cannot carry into the upper long without
35 * almost 2TB swap - let's ignore that case.
36 */
37 if (sizeof(i_blocks) > sizeof(long))
38 spin_lock(&src->i_lock);
39 i_blocks = src->i_blocks;
40 if (sizeof(i_blocks) > sizeof(long))
41 spin_unlock(&src->i_lock);
42
43 /*
44 * If CONFIG_SMP or CONFIG_PREEMPT on 32-bit, it's vital for
45 * fsstack_copy_inode_size() to hold some lock around
46 * i_size_write(), otherwise i_size_read() may spin forever (see
47 * include/linux/fs.h). We don't necessarily hold i_mutex when this
48 * is called, so take i_lock for that case.
49 *
50 * And if CONFIG_LBADF (on 32-bit), continue our effort to keep the
51 * two halves of i_blocks in sync despite SMP or PREEMPT: use i_lock
52 * for that case too, and do both at once by combining the tests.
53 *
54 * There is none of this locking overhead in the 64-bit case.
55 */
56 if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long))
57 spin_lock(&dst->i_lock);
58 i_size_write(dst, i_size);
59 dst->i_blocks = i_blocks;
60 if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long))
61 spin_unlock(&dst->i_lock);
Josef "Jeff" Sipek42cf1192006-12-08 02:36:31 -080062}
63EXPORT_SYMBOL_GPL(fsstack_copy_inode_size);
64
Erez Zadok9afa2fb2009-12-02 19:51:54 -050065/* copy all attributes */
66void fsstack_copy_attr_all(struct inode *dest, const struct inode *src)
Josef "Jeff" Sipek42cf1192006-12-08 02:36:31 -080067{
Josef "Jeff" Sipek42cf1192006-12-08 02:36:31 -080068 dest->i_mode = src->i_mode;
69 dest->i_uid = src->i_uid;
70 dest->i_gid = src->i_gid;
71 dest->i_rdev = src->i_rdev;
72 dest->i_atime = src->i_atime;
73 dest->i_mtime = src->i_mtime;
74 dest->i_ctime = src->i_ctime;
75 dest->i_blkbits = src->i_blkbits;
76 dest->i_flags = src->i_flags;
Erez Zadok9afa2fb2009-12-02 19:51:54 -050077 dest->i_nlink = src->i_nlink;
Josef "Jeff" Sipek42cf1192006-12-08 02:36:31 -080078}
79EXPORT_SYMBOL_GPL(fsstack_copy_attr_all);