Back to home page

LXR

 
 

    


0001 #include <linux/export.h>
0002 #include <linux/fs.h>
0003 #include <linux/fs_stack.h>
0004 
0005 /* does _NOT_ require i_mutex to be held.
0006  *
0007  * This function cannot be inlined since i_size_{read,write} is rather
0008  * heavy-weight on 32-bit systems
0009  */
0010 void fsstack_copy_inode_size(struct inode *dst, struct inode *src)
0011 {
0012     loff_t i_size;
0013     blkcnt_t i_blocks;
0014 
0015     /*
0016      * i_size_read() includes its own seqlocking and protection from
0017      * preemption (see include/linux/fs.h): we need nothing extra for
0018      * that here, and prefer to avoid nesting locks than attempt to keep
0019      * i_size and i_blocks in sync together.
0020      */
0021     i_size = i_size_read(src);
0022 
0023     /*
0024      * But if CONFIG_LBDAF (on 32-bit), we ought to make an effort to
0025      * keep the two halves of i_blocks in sync despite SMP or PREEMPT -
0026      * though stat's generic_fillattr() doesn't bother, and we won't be
0027      * applying quotas (where i_blocks does become important) at the
0028      * upper level.
0029      *
0030      * We don't actually know what locking is used at the lower level;
0031      * but if it's a filesystem that supports quotas, it will be using
0032      * i_lock as in inode_add_bytes().
0033      */
0034     if (sizeof(i_blocks) > sizeof(long))
0035         spin_lock(&src->i_lock);
0036     i_blocks = src->i_blocks;
0037     if (sizeof(i_blocks) > sizeof(long))
0038         spin_unlock(&src->i_lock);
0039 
0040     /*
0041      * If CONFIG_SMP or CONFIG_PREEMPT on 32-bit, it's vital for
0042      * fsstack_copy_inode_size() to hold some lock around
0043      * i_size_write(), otherwise i_size_read() may spin forever (see
0044      * include/linux/fs.h).  We don't necessarily hold i_mutex when this
0045      * is called, so take i_lock for that case.
0046      *
0047      * And if CONFIG_LBDAF (on 32-bit), continue our effort to keep the
0048      * two halves of i_blocks in sync despite SMP or PREEMPT: use i_lock
0049      * for that case too, and do both at once by combining the tests.
0050      *
0051      * There is none of this locking overhead in the 64-bit case.
0052      */
0053     if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long))
0054         spin_lock(&dst->i_lock);
0055     i_size_write(dst, i_size);
0056     dst->i_blocks = i_blocks;
0057     if (sizeof(i_size) > sizeof(long) || sizeof(i_blocks) > sizeof(long))
0058         spin_unlock(&dst->i_lock);
0059 }
0060 EXPORT_SYMBOL_GPL(fsstack_copy_inode_size);
0061 
0062 /* copy all attributes */
0063 void fsstack_copy_attr_all(struct inode *dest, const struct inode *src)
0064 {
0065     dest->i_mode = src->i_mode;
0066     dest->i_uid = src->i_uid;
0067     dest->i_gid = src->i_gid;
0068     dest->i_rdev = src->i_rdev;
0069     dest->i_atime = src->i_atime;
0070     dest->i_mtime = src->i_mtime;
0071     dest->i_ctime = src->i_ctime;
0072     dest->i_blkbits = src->i_blkbits;
0073     dest->i_flags = src->i_flags;
0074     set_nlink(dest, src->i_nlink);
0075 }
0076 EXPORT_SYMBOL_GPL(fsstack_copy_attr_all);