Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] fs/stack.c: Copy i_nlink after all other attributes are copied

A user-specified get_nlinks may depend on other inode attributes.

Cc: Michael Halcrow <mhalcrow@us.ibm.com>
Signed-off-by: Erez Zadok <ezk@cs.sunysb.edu>
Signed-off-by: Josef 'Jeff' Sipek <jsipek@cs.sunysb.edu>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Erez Zadok and committed by
Linus Torvalds
a6e6df25 bc5393a6

+9 -5
+9 -5
fs/stack.c
··· 20 20 void fsstack_copy_attr_all(struct inode *dest, const struct inode *src, 21 21 int (*get_nlinks)(struct inode *)) 22 22 { 23 - if (!get_nlinks) 24 - dest->i_nlink = src->i_nlink; 25 - else 26 - dest->i_nlink = (*get_nlinks)(dest); 27 - 28 23 dest->i_mode = src->i_mode; 29 24 dest->i_uid = src->i_uid; 30 25 dest->i_gid = src->i_gid; ··· 29 34 dest->i_ctime = src->i_ctime; 30 35 dest->i_blkbits = src->i_blkbits; 31 36 dest->i_flags = src->i_flags; 37 + 38 + /* 39 + * Update the nlinks AFTER updating the above fields, because the 40 + * get_links callback may depend on them. 41 + */ 42 + if (!get_nlinks) 43 + dest->i_nlink = src->i_nlink; 44 + else 45 + dest->i_nlink = (*get_nlinks)(dest); 32 46 } 33 47 EXPORT_SYMBOL_GPL(fsstack_copy_attr_all);