lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <e7b05432-97c8-d74c-0722-7e0943002c19@intel.com>
Date:   Wed, 28 Jul 2021 08:40:42 +0800
From:   kernel test robot <rong.a.chen@...el.com>
To:     Allison Henderson <allison.henderson@...cle.com>
Cc:     clang-built-linux <clang-built-linux@...glegroups.com>,
        kbuild-all@...ts.01.org, LKML <linux-kernel@...r.kernel.org>
Subject: [allisonhenderson-xfs_work:delayed_attrs_v22_extended 28/32]
 fs/xfs/xfs_inode.c:3287:3: warning: Value stored to 'error' is never read
 [clang-analyzer-deadcode.DeadStores]


tree:   https://github.com/allisonhenderson/xfs_work.git 
delayed_attrs_v22_extended
head:   aff89515c2d9aca9b24ac0296f3806af62cd9206
commit: 3818584f03ce2d5c1310199a6466aafdf22c8256 [28/32] xfs: Add parent 
pointers to rename
:::::: branch date: 18 hours ago
:::::: commit date: 18 hours ago
config: x86_64-randconfig-c001-20210727 (attached as .config)
compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 
c658b472f3e61e1818e1909bf02f3d65470018a5)
reproduce (this is a W=1 build):
         wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross 
-O ~/bin/make.cross
         chmod +x ~/bin/make.cross
         # install x86_64 cross compiling tool for clang build
         # apt-get install binutils-x86-64-linux-gnu
         # 
https://github.com/allisonhenderson/xfs_work/commit/3818584f03ce2d5c1310199a6466aafdf22c8256
         git remote add allisonhenderson-xfs_work 
https://github.com/allisonhenderson/xfs_work.git
         git fetch --no-tags allisonhenderson-xfs_work 
delayed_attrs_v22_extended
         git checkout 3818584f03ce2d5c1310199a6466aafdf22c8256
         # save the attached .config to linux build tree
         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross 
ARCH=x86_64 clang-analyzer
If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@...el.com>


clang-analyzer warnings: (new ones prefixed by >>)
                                       ^
    include/linux/kernel.h:495:61: note: expanded from macro 'container_of'
            BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) 
&&   \
                                                                       ^
    drivers/md/dm-zoned-target.c:481:29: note: Taking false branch
            struct dm_chunk_work *cw = container_of(work, struct 
dm_chunk_work, work);
                                       ^
    include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
            BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) 
&&   \
            ^
    include/linux/build_bug.h:39:37: note: expanded from macro 
'BUILD_BUG_ON_MSG'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
    include/linux/compiler_types.h:328:2: note: expanded from macro 
'compiletime_assert'
            _compiletime_assert(condition, msg, __compiletime_assert_, 
__COUNTER__)
            ^
    include/linux/compiler_types.h:316:2: note: expanded from macro 
'_compiletime_assert'
            __compiletime_assert(condition, msg, prefix, suffix)
            ^
    include/linux/compiler_types.h:308:3: note: expanded from macro 
'__compiletime_assert'
                    if (!(condition)) 
     \
                    ^
    drivers/md/dm-zoned-target.c:481:29: note: Loop condition is false. 
  Exiting loop
            struct dm_chunk_work *cw = container_of(work, struct 
dm_chunk_work, work);
                                       ^
    include/linux/kernel.h:495:2: note: expanded from macro 'container_of'
            BUILD_BUG_ON_MSG(!__same_type(*(ptr), ((type *)0)->member) 
&&   \
            ^
    include/linux/build_bug.h:39:37: note: expanded from macro 
'BUILD_BUG_ON_MSG'
    #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
                                        ^
    include/linux/compiler_types.h:328:2: note: expanded from macro 
'compiletime_assert'
            _compiletime_assert(condition, msg, __compiletime_assert_, 
__COUNTER__)
            ^
    include/linux/compiler_types.h:316:2: note: expanded from macro 
'_compiletime_assert'
            __compiletime_assert(condition, msg, prefix, suffix)
            ^
    include/linux/compiler_types.h:306:2: note: expanded from macro 
'__compiletime_assert'
            do { 
     \
            ^
    drivers/md/dm-zoned-target.c:488:2: note: Loop condition is true. 
Entering loop body
            while ((bio = bio_list_pop(&cw->bio_list))) {
            ^
    drivers/md/dm-zoned-target.c:492:3: note: Calling 'dmz_put_chunk_work'
                    dmz_put_chunk_work(cw);
                    ^~~~~~~~~~~~~~~~~~~~~~
    drivers/md/dm-zoned-target.c:469:6: note: Assuming the condition is true
            if (refcount_dec_and_test(&cw->refcount)) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/md/dm-zoned-target.c:469:2: note: Taking true branch
            if (refcount_dec_and_test(&cw->refcount)) {
            ^
    drivers/md/dm-zoned-target.c:470:3: note: Taking false branch
                    WARN_ON(!bio_list_empty(&cw->bio_list));
                    ^
    include/asm-generic/bug.h:122:2: note: expanded from macro 'WARN_ON'
            if (unlikely(__ret_warn_on)) 
     \
            ^
    drivers/md/dm-zoned-target.c:472:3: note: Memory is released
                    kfree(cw);
                    ^~~~~~~~~
    drivers/md/dm-zoned-target.c:492:3: note: Returning; memory was 
released via 1st parameter
                    dmz_put_chunk_work(cw);
                    ^~~~~~~~~~~~~~~~~~~~~~
    drivers/md/dm-zoned-target.c:488:16: note: Calling 'bio_list_pop'
            while ((bio = bio_list_pop(&cw->bio_list))) {
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    include/linux/bio.h:657:20: note: Use of memory after it is freed
            struct bio *bio = bl->head;
                              ^~~~~~~~
    Suppressed 6 warnings (6 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    12 warnings generated.
    fs/xfs/xfs_iops.c:704:11: warning: Value stored to 'uid' during its 
initialization is never read [clang-analyzer-deadcode.DeadStores]
            kuid_t                  uid = GLOBAL_ROOT_UID, iuid = 
GLOBAL_ROOT_UID;
                                    ^~~
    fs/xfs/xfs_iops.c:704:11: note: Value stored to 'uid' during its 
initialization is never read
            kuid_t                  uid = GLOBAL_ROOT_UID, iuid = 
GLOBAL_ROOT_UID;
                                    ^~~
    fs/xfs/xfs_iops.c:704:34: warning: Value stored to 'iuid' during its 
initialization is never read [clang-analyzer-deadcode.DeadStores]
            kuid_t                  uid = GLOBAL_ROOT_UID, iuid = 
GLOBAL_ROOT_UID;
                                                           ^~~~
    fs/xfs/xfs_iops.c:704:34: note: Value stored to 'iuid' during its 
initialization is never read
            kuid_t                  uid = GLOBAL_ROOT_UID, iuid = 
GLOBAL_ROOT_UID;
                                                           ^~~~
    fs/xfs/xfs_iops.c:705:11: warning: Value stored to 'gid' during its 
initialization is never read [clang-analyzer-deadcode.DeadStores]
            kgid_t                  gid = GLOBAL_ROOT_GID, igid = 
GLOBAL_ROOT_GID;
                                    ^~~
    fs/xfs/xfs_iops.c:705:11: note: Value stored to 'gid' during its 
initialization is never read
            kgid_t                  gid = GLOBAL_ROOT_GID, igid = 
GLOBAL_ROOT_GID;
                                    ^~~
    fs/xfs/xfs_iops.c:705:34: warning: Value stored to 'igid' during its 
initialization is never read [clang-analyzer-deadcode.DeadStores]
            kgid_t                  gid = GLOBAL_ROOT_GID, igid = 
GLOBAL_ROOT_GID;
                                                           ^~~~
    fs/xfs/xfs_iops.c:705:34: note: Value stored to 'igid' during its 
initialization is never read
            kgid_t                  gid = GLOBAL_ROOT_GID, igid = 
GLOBAL_ROOT_GID;
                                                           ^~~~
    Suppressed 8 warnings (8 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    9 warnings generated.
>> fs/xfs/xfs_inode.c:3287:3: warning: Value stored to 'error' is never read [clang-analyzer-deadcode.DeadStores]
                    error = xfs_cross_rename(tp, src_dp, src_name, src_ip,
                    ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    fs/xfs/xfs_inode.c:3287:3: note: Value stored to 'error' is never read
                    error = xfs_cross_rename(tp, src_dp, src_name, src_ip,
                    ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Suppressed 8 warnings (8 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    8 warnings generated.
    Suppressed 8 warnings (8 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    8 warnings generated.
    Suppressed 8 warnings (8 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    8 warnings generated.
    Suppressed 8 warnings (8 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    8 warnings generated.
    Suppressed 8 warnings (8 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    8 warnings generated.
    Suppressed 8 warnings (8 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    5 warnings generated.
    Suppressed 5 warnings (5 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    8 warnings generated.
    drivers/input/touchscreen/edt-ft5x06.c:705:21: warning: Value stored 
to 'client' during its initialization is never read 
[clang-analyzer-deadcode.DeadStores]
            struct i2c_client *client = tsdata->client;
                               ^~~~~~   ~~~~~~~~~~~~~~
    drivers/input/touchscreen/edt-ft5x06.c:705:21: note: Value stored to 
'client' during its initialization is never read
            struct i2c_client *client = tsdata->client;
                               ^~~~~~   ~~~~~~~~~~~~~~
    Suppressed 7 warnings (7 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    5 warnings generated.
    Suppressed 5 warnings (5 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    7 warnings generated.
    Suppressed 7 warnings (7 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    5 warnings generated.
    Suppressed 5 warnings (5 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    7 warnings generated.
    Suppressed 7 warnings (7 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    7 warnings generated.
    Suppressed 7 warnings (7 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    6 warnings generated.
    Suppressed 6 warnings (6 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    5 warnings generated.
    Suppressed 5 warnings (5 in non-user code).
    Use -header-filter=.* to display errors from all non-system headers. 
Use -system-headers to display errors from system headers as well.
    6 warnings generated.
    drivers/md/dm-snap-persistent.c:632:6: warning: Branch condition 
evaluates to a garbage value [clang-analyzer-core.uninitialized.Branch]
            if (new_snapshot) {
                ^~~~~~~~~~~~
    drivers/md/dm-snap-persistent.c:609:9: note: 'new_snapshot' declared 
without an initial value
            int r, new_snapshot;
                   ^~~~~~~~~~~~
    drivers/md/dm-snap-persistent.c:615:6: note: Calling 'read_header'
            r = read_header(ps, &new_snapshot);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/md/dm-snap-persistent.c:315:6: note: Assuming field 
'chunk_size' is not equal to 0
            if (!ps->store->chunk_size) {
                ^~~~~~~~~~~~~~~~~~~~~~
    drivers/md/dm-snap-persistent.c:315:2: note: Taking false branch
            if (!ps->store->chunk_size) {
            ^
    drivers/md/dm-snap-persistent.c:325:6: note: Calling 'IS_ERR'
            if (IS_ERR(ps->io_client))
                ^~~~~~~~~~~~~~~~~~~~~
    include/linux/err.h:36:9: note: Assuming the condition is true
            return IS_ERR_VALUE((unsigned long)ptr);
                   ^
    include/linux/err.h:22:34: note: expanded from macro 'IS_ERR_VALUE'
    #define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= 
(unsigned long)-MAX_ERRNO)
 
~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    include/linux/compiler.h:48:41: note: expanded from macro 'unlikely'
    #  define unlikely(x)   (__branch_check__(x, 0, 
__builtin_constant_p(x)))
                             ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    include/linux/compiler.h:33:34: note: expanded from macro 
'__branch_check__'
                            ______r = __builtin_expect(!!(x), expect); 
     \
                                                          ^
    include/linux/err.h:36:2: note: Returning the value 1, which 
participates in a condition later
            return IS_ERR_VALUE((unsigned long)ptr);
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    drivers/md/dm-snap-persistent.c:325:6: note: Returning from 'IS_ERR'
            if (IS_ERR(ps->io_client))
                ^~~~~~~~~~~~~~~~~~~~~
    drivers/md/dm-snap-persistent.c:325:2: note: Taking true branch
            if (IS_ERR(ps->io_client))
            ^
    drivers/md/dm-snap-persistent.c:326:3: note: Returning without 
writing to 'ps->callbacks', which participates in a condition later
                    return PTR_ERR(ps->io_client);
                    ^
    drivers/md/dm-snap-persistent.c:326:3: note: Returning without 
writing to '*new_snapshot'
    drivers/md/dm-snap-persistent.c:326:3: note: Returning value, which 
participates in a condition later

vim +/error +3287 fs/xfs/xfs_inode.c

7dcf5c3e4527cf Dave Chinner      2015-03-25  3155  f6bba2017afb3b Dave 
Chinner      2013-08-12  3156  /*
f6bba2017afb3b Dave Chinner      2013-08-12  3157   * xfs_rename
f6bba2017afb3b Dave Chinner      2013-08-12  3158   */
f6bba2017afb3b Dave Chinner      2013-08-12  3159  int
f6bba2017afb3b Dave Chinner      2013-08-12  3160  xfs_rename(
f736d93d76d3e9 Christoph Hellwig 2021-01-21  3161  	struct 
user_namespace		*mnt_userns,
7dcf5c3e4527cf Dave Chinner      2015-03-25  3162  	struct xfs_inode	 
*src_dp,
f6bba2017afb3b Dave Chinner      2013-08-12  3163  	struct xfs_name		 
*src_name,
7dcf5c3e4527cf Dave Chinner      2015-03-25  3164  	struct xfs_inode	 
*src_ip,
7dcf5c3e4527cf Dave Chinner      2015-03-25  3165  	struct xfs_inode	 
*target_dp,
f6bba2017afb3b Dave Chinner      2013-08-12  3166  	struct xfs_name		 
*target_name,
7dcf5c3e4527cf Dave Chinner      2015-03-25  3167  	struct xfs_inode	 
*target_ip,
d31a1825450062 Carlos Maiolino   2014-12-24  3168  	unsigned int			flags)
f6bba2017afb3b Dave Chinner      2013-08-12  3169  {
7dcf5c3e4527cf Dave Chinner      2015-03-25  3170  	struct xfs_mount	 
*mp = src_dp->i_mount;
7dcf5c3e4527cf Dave Chinner      2015-03-25  3171  	struct xfs_trans		*tp;
7dcf5c3e4527cf Dave Chinner      2015-03-25  3172  	struct xfs_inode	 
*wip = NULL;		/* whiteout inode */
7dcf5c3e4527cf Dave Chinner      2015-03-25  3173  	struct xfs_inode	 
*inodes[__XFS_SORT_INODES];
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3174  	int				i;
95afcf5c7bca93 Dave Chinner      2015-03-25  3175  	int				num_inodes = 
__XFS_SORT_INODES;
2b93681f593577 Dave Chinner      2015-03-25  3176  	bool				new_parent = 
(src_dp != target_dp);
c19b3b05ae440d Dave Chinner      2016-02-09  3177  	bool			 
src_is_directory = S_ISDIR(VFS_I(src_ip)->i_mode);
f6bba2017afb3b Dave Chinner      2013-08-12  3178  	int				spaceres;
7dcf5c3e4527cf Dave Chinner      2015-03-25  3179  	int				error;
3818584f03ce2d Allison Henderson 2021-03-24  3180  	struct 
xfs_parent_name_rec	new_rec;
3818584f03ce2d Allison Henderson 2021-03-24  3181  	struct 
xfs_parent_name_rec	old_rec;
3818584f03ce2d Allison Henderson 2021-03-24  3182  	xfs_dir2_dataptr_t	 
new_diroffset;
3818584f03ce2d Allison Henderson 2021-03-24  3183  	xfs_dir2_dataptr_t	 
old_diroffset;
3818584f03ce2d Allison Henderson 2021-03-24  3184  	struct xfs_da_args	 
new_args = {
3818584f03ce2d Allison Henderson 2021-03-24  3185  		.dp		= src_ip,
3818584f03ce2d Allison Henderson 2021-03-24  3186  		.geo		= mp->m_attr_geo,
3818584f03ce2d Allison Henderson 2021-03-24  3187  		.whichfork	= 
XFS_ATTR_FORK,
3818584f03ce2d Allison Henderson 2021-03-24  3188  		.attr_filter	= 
XFS_ATTR_PARENT,
3818584f03ce2d Allison Henderson 2021-03-24  3189  		.op_flags	= 
XFS_DA_OP_OKNOENT,
3818584f03ce2d Allison Henderson 2021-03-24  3190  		.name		= (const 
uint8_t *)&new_rec,
3818584f03ce2d Allison Henderson 2021-03-24  3191  		.namelen	= 
sizeof(new_rec),
3818584f03ce2d Allison Henderson 2021-03-24  3192  		.value		= (void 
*)target_name->name,
3818584f03ce2d Allison Henderson 2021-03-24  3193  		.valuelen	= 
target_name->len,
3818584f03ce2d Allison Henderson 2021-03-24  3194  	};
3818584f03ce2d Allison Henderson 2021-03-24  3195  	struct xfs_da_args	 
old_args = {
3818584f03ce2d Allison Henderson 2021-03-24  3196  		.dp		= src_ip,
3818584f03ce2d Allison Henderson 2021-03-24  3197  		.geo		= mp->m_attr_geo,
3818584f03ce2d Allison Henderson 2021-03-24  3198  		.whichfork	= 
XFS_ATTR_FORK,
3818584f03ce2d Allison Henderson 2021-03-24  3199  		.attr_filter	= 
XFS_ATTR_PARENT,
3818584f03ce2d Allison Henderson 2021-03-24  3200  		.op_flags	= 
XFS_DA_OP_OKNOENT,
3818584f03ce2d Allison Henderson 2021-03-24  3201  		.name		= (const 
uint8_t *)&old_rec,
3818584f03ce2d Allison Henderson 2021-03-24  3202  		.namelen	= 
sizeof(old_rec),
3818584f03ce2d Allison Henderson 2021-03-24  3203  		.value		= NULL,
3818584f03ce2d Allison Henderson 2021-03-24  3204  		.valuelen	= 0,
3818584f03ce2d Allison Henderson 2021-03-24  3205  	};
f6bba2017afb3b Dave Chinner      2013-08-12  3206  f6bba2017afb3b Dave 
Chinner      2013-08-12  3207  	trace_xfs_rename(src_dp, target_dp, 
src_name, target_name);
f6bba2017afb3b Dave Chinner      2013-08-12  3208  eeacd3217b8fa8 Dave 
Chinner      2015-03-25  3209  	if ((flags & RENAME_EXCHANGE) && !target_ip)
eeacd3217b8fa8 Dave Chinner      2015-03-25  3210  		return -EINVAL;
eeacd3217b8fa8 Dave Chinner      2015-03-25  3211  7dcf5c3e4527cf Dave 
Chinner      2015-03-25  3212  	/*
7dcf5c3e4527cf Dave Chinner      2015-03-25  3213  	 * If we are doing a 
whiteout operation, allocate the whiteout inode
7dcf5c3e4527cf Dave Chinner      2015-03-25  3214  	 * we will be 
placing at the target and ensure the type is set
7dcf5c3e4527cf Dave Chinner      2015-03-25  3215  	 * appropriately.
7dcf5c3e4527cf Dave Chinner      2015-03-25  3216  	 */
7dcf5c3e4527cf Dave Chinner      2015-03-25  3217  	if (flags & 
RENAME_WHITEOUT) {
7dcf5c3e4527cf Dave Chinner      2015-03-25  3218  		ASSERT(!(flags & 
(RENAME_NOREPLACE | RENAME_EXCHANGE)));
f736d93d76d3e9 Christoph Hellwig 2021-01-21  3219  		error = 
xfs_rename_alloc_whiteout(mnt_userns, target_dp, &wip);
7dcf5c3e4527cf Dave Chinner      2015-03-25  3220  		if (error)
7dcf5c3e4527cf Dave Chinner      2015-03-25  3221  			return error;
f6bba2017afb3b Dave Chinner      2013-08-12  3222  7dcf5c3e4527cf Dave 
Chinner      2015-03-25  3223  		/* setup target dirent info as whiteout */
7dcf5c3e4527cf Dave Chinner      2015-03-25  3224  		src_name->type = 
XFS_DIR3_FT_CHRDEV;
7dcf5c3e4527cf Dave Chinner      2015-03-25  3225  	}
f6bba2017afb3b Dave Chinner      2013-08-12  3226  7dcf5c3e4527cf Dave 
Chinner      2015-03-25  3227  	xfs_sort_for_rename(src_dp, target_dp, 
src_ip, target_ip, wip,
f6bba2017afb3b Dave Chinner      2013-08-12  3228  				inodes, &num_inodes);
3818584f03ce2d Allison Henderson 2021-03-24  3229  	if 
(xfs_hasdelattr(mp)) {
3818584f03ce2d Allison Henderson 2021-03-24  3230  		error = 
xfs_attr_use_log_assist(mp);
3818584f03ce2d Allison Henderson 2021-03-24  3231  		if (error)
3818584f03ce2d Allison Henderson 2021-03-24  3232  			goto out_release_wip;
3818584f03ce2d Allison Henderson 2021-03-24  3233  	}
f6bba2017afb3b Dave Chinner      2013-08-12  3234  f6bba2017afb3b Dave 
Chinner      2013-08-12  3235  	spaceres = XFS_RENAME_SPACE_RES(mp, 
target_name->len);
253f4911f297b8 Christoph Hellwig 2016-04-06  3236  	error = 
xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, spaceres, 0, 0, &tp);
2451337dd04390 Dave Chinner      2014-06-25  3237  	if (error == -ENOSPC) {
f6bba2017afb3b Dave Chinner      2013-08-12  3238  		spaceres = 0;
253f4911f297b8 Christoph Hellwig 2016-04-06  3239  		error = 
xfs_trans_alloc(mp, &M_RES(mp)->tr_rename, 0, 0, 0,
253f4911f297b8 Christoph Hellwig 2016-04-06  3240  				&tp);
f6bba2017afb3b Dave Chinner      2013-08-12  3241  	}
445883e8133975 Dave Chinner      2015-03-25  3242  	if (error)
3818584f03ce2d Allison Henderson 2021-03-24  3243  		goto drop_incompat;
f6bba2017afb3b Dave Chinner      2013-08-12  3244  f6bba2017afb3b Dave 
Chinner      2013-08-12  3245  	/*
f6bba2017afb3b Dave Chinner      2013-08-12  3246  	 * Attach the dquots 
to the inodes
f6bba2017afb3b Dave Chinner      2013-08-12  3247  	 */
f6bba2017afb3b Dave Chinner      2013-08-12  3248  	error = 
xfs_qm_vop_rename_dqattach(inodes);
445883e8133975 Dave Chinner      2015-03-25  3249  	if (error)
445883e8133975 Dave Chinner      2015-03-25  3250  		goto out_trans_cancel;
f6bba2017afb3b Dave Chinner      2013-08-12  3251  f6bba2017afb3b Dave 
Chinner      2013-08-12  3252  	/*
f6bba2017afb3b Dave Chinner      2013-08-12  3253  	 * Lock all the 
participating inodes. Depending upon whether
f6bba2017afb3b Dave Chinner      2013-08-12  3254  	 * the target_name 
exists in the target directory, and
f6bba2017afb3b Dave Chinner      2013-08-12  3255  	 * whether the 
target directory is the same as the source
f6bba2017afb3b Dave Chinner      2013-08-12  3256  	 * directory, we can 
lock from 2 to 4 inodes.
f6bba2017afb3b Dave Chinner      2013-08-12  3257  	 */
f6bba2017afb3b Dave Chinner      2013-08-12  3258 
xfs_lock_inodes(inodes, num_inodes, XFS_ILOCK_EXCL);
f6bba2017afb3b Dave Chinner      2013-08-12  3259  f6bba2017afb3b Dave 
Chinner      2013-08-12  3260  	/*
f6bba2017afb3b Dave Chinner      2013-08-12  3261  	 * Join all the 
inodes to the transaction. From this point on,
f6bba2017afb3b Dave Chinner      2013-08-12  3262  	 * we can rely on 
either trans_commit or trans_cancel to unlock
f6bba2017afb3b Dave Chinner      2013-08-12  3263  	 * them.
f6bba2017afb3b Dave Chinner      2013-08-12  3264  	 */
3818584f03ce2d Allison Henderson 2021-03-24  3265  	xfs_trans_ijoin(tp, 
src_dp, 0);
f6bba2017afb3b Dave Chinner      2013-08-12  3266  	if (new_parent)
3818584f03ce2d Allison Henderson 2021-03-24  3267  		xfs_trans_ijoin(tp, 
target_dp, 0);
3818584f03ce2d Allison Henderson 2021-03-24  3268  	xfs_trans_ijoin(tp, 
src_ip, 0);
f6bba2017afb3b Dave Chinner      2013-08-12  3269  	if (target_ip)
3818584f03ce2d Allison Henderson 2021-03-24  3270  		xfs_trans_ijoin(tp, 
target_ip, 0);
7dcf5c3e4527cf Dave Chinner      2015-03-25  3271  	if (wip)
3818584f03ce2d Allison Henderson 2021-03-24  3272  		xfs_trans_ijoin(tp, 
wip, 0);
f6bba2017afb3b Dave Chinner      2013-08-12  3273  f6bba2017afb3b Dave 
Chinner      2013-08-12  3274  	/*
f6bba2017afb3b Dave Chinner      2013-08-12  3275  	 * If we are using 
project inheritance, we only allow renames
f6bba2017afb3b Dave Chinner      2013-08-12  3276  	 * into our tree 
when the project IDs are the same; else the
f6bba2017afb3b Dave Chinner      2013-08-12  3277  	 * tree quota 
mechanism would be circumvented.
f6bba2017afb3b Dave Chinner      2013-08-12  3278  	 */
db07349da2f564 Christoph Hellwig 2021-03-29  3279  	if 
(unlikely((target_dp->i_diflags & XFS_DIFLAG_PROJINHERIT) &&
ceaf603c7024d3 Christoph Hellwig 2021-03-29  3280  		 
target_dp->i_projid != src_ip->i_projid)) {
2451337dd04390 Dave Chinner      2014-06-25  3281  		error = -EXDEV;
3818584f03ce2d Allison Henderson 2021-03-24  3282  		goto out_unlock;
f6bba2017afb3b Dave Chinner      2013-08-12  3283  	}
f6bba2017afb3b Dave Chinner      2013-08-12  3284  eeacd3217b8fa8 Dave 
Chinner      2015-03-25  3285  	/* RENAME_EXCHANGE is unique from here 
on. */
3818584f03ce2d Allison Henderson 2021-03-24  3286  	if (flags & 
RENAME_EXCHANGE) {
3818584f03ce2d Allison Henderson 2021-03-24 @3287  		error = 
xfs_cross_rename(tp, src_dp, src_name, src_ip,
d31a1825450062 Carlos Maiolino   2014-12-24  3288  					target_dp, 
target_name, target_ip,
f16dea54b789aa Brian Foster      2018-07-11  3289  					spaceres);
3818584f03ce2d Allison Henderson 2021-03-24  3290  		goto out_pptr;
3818584f03ce2d Allison Henderson 2021-03-24  3291  	}
f6bba2017afb3b Dave Chinner      2013-08-12  3292  	/*
bc56ad8c74b858 kaixuxia          2019-09-03  3293  	 * Check for 
expected errors before we dirty the transaction
bc56ad8c74b858 kaixuxia          2019-09-03  3294  	 * so we can return 
an error without a transaction abort.
02092a2f034fde Chandan Babu R    2021-01-22  3295  	 *
02092a2f034fde Chandan Babu R    2021-01-22  3296  	 * Extent count 
overflow check:
02092a2f034fde Chandan Babu R    2021-01-22  3297  	 *
02092a2f034fde Chandan Babu R    2021-01-22  3298  	 * From the 
perspective of src_dp, a rename operation is essentially a
02092a2f034fde Chandan Babu R    2021-01-22  3299  	 * directory entry 
remove operation. Hence the only place where we check
02092a2f034fde Chandan Babu R    2021-01-22  3300  	 * for extent count 
overflow for src_dp is in
02092a2f034fde Chandan Babu R    2021-01-22  3301  	 * 
xfs_bmap_del_extent_real(). xfs_bmap_del_extent_real() returns
02092a2f034fde Chandan Babu R    2021-01-22  3302  	 * -ENOSPC when it 
detects a possible extent count overflow and in
02092a2f034fde Chandan Babu R    2021-01-22  3303  	 * response, the 
higher layers of directory handling code do the
02092a2f034fde Chandan Babu R    2021-01-22  3304  	 * following:
02092a2f034fde Chandan Babu R    2021-01-22  3305  	 * 1. Data/Free 
blocks: XFS lets these blocks linger until a
02092a2f034fde Chandan Babu R    2021-01-22  3306  	 *    future remove 
operation removes them.
02092a2f034fde Chandan Babu R    2021-01-22  3307  	 * 2. Dabtree 
blocks: XFS swaps the blocks with the last block in the
02092a2f034fde Chandan Babu R    2021-01-22  3308  	 *    Leaf space and 
unmaps the last block.
02092a2f034fde Chandan Babu R    2021-01-22  3309  	 *
02092a2f034fde Chandan Babu R    2021-01-22  3310  	 * For target_dp, 
there are two cases depending on whether the
02092a2f034fde Chandan Babu R    2021-01-22  3311  	 * destination 
directory entry exists or not.
02092a2f034fde Chandan Babu R    2021-01-22  3312  	 *
02092a2f034fde Chandan Babu R    2021-01-22  3313  	 * When destination 
directory entry does not exist (i.e. target_ip ==
02092a2f034fde Chandan Babu R    2021-01-22  3314  	 * NULL), extent 
count overflow check is performed only when transaction
02092a2f034fde Chandan Babu R    2021-01-22  3315  	 * has a non-zero 
sized space reservation associated with it.  With a
02092a2f034fde Chandan Babu R    2021-01-22  3316  	 * zero-sized space 
reservation, XFS allows a rename operation to
02092a2f034fde Chandan Babu R    2021-01-22  3317  	 * continue only 
when the directory has sufficient free space in its
02092a2f034fde Chandan Babu R    2021-01-22  3318  	 * data/leaf/free 
space blocks to hold the new entry.
02092a2f034fde Chandan Babu R    2021-01-22  3319  	 *
02092a2f034fde Chandan Babu R    2021-01-22  3320  	 * When destination 
directory entry exists (i.e. target_ip != NULL), all
02092a2f034fde Chandan Babu R    2021-01-22  3321  	 * we need to do is 
change the inode number associated with the already
02092a2f034fde Chandan Babu R    2021-01-22  3322  	 * existing entry. 
Hence there is no need to perform an extent count
02092a2f034fde Chandan Babu R    2021-01-22  3323  	 * overflow check.
f6bba2017afb3b Dave Chinner      2013-08-12  3324  	 */
f6bba2017afb3b Dave Chinner      2013-08-12  3325  	if (target_ip == NULL) {
f6bba2017afb3b Dave Chinner      2013-08-12  3326  		/*
f6bba2017afb3b Dave Chinner      2013-08-12  3327  		 * If there's no 
space reservation, check the entry will
f6bba2017afb3b Dave Chinner      2013-08-12  3328  		 * fit before 
actually inserting it.
f6bba2017afb3b Dave Chinner      2013-08-12  3329  		 */
94f3cad555d660 Eric Sandeen      2014-09-09  3330  		if (!spaceres) {
94f3cad555d660 Eric Sandeen      2014-09-09  3331  			error = 
xfs_dir_canenter(tp, target_dp, target_name);
f6bba2017afb3b Dave Chinner      2013-08-12  3332  			if (error)
3818584f03ce2d Allison Henderson 2021-03-24  3333  				goto out_unlock;
02092a2f034fde Chandan Babu R    2021-01-22  3334  		} else {
02092a2f034fde Chandan Babu R    2021-01-22  3335  			error = 
xfs_iext_count_may_overflow(target_dp,
02092a2f034fde Chandan Babu R    2021-01-22  3336  					XFS_DATA_FORK,
02092a2f034fde Chandan Babu R    2021-01-22  3337  				 
XFS_IEXT_DIR_MANIP_CNT(mp));
02092a2f034fde Chandan Babu R    2021-01-22  3338  			if (error)
02092a2f034fde Chandan Babu R    2021-01-22  3339  				goto 
out_trans_cancel;
94f3cad555d660 Eric Sandeen      2014-09-09  3340  		}
bc56ad8c74b858 kaixuxia          2019-09-03  3341  	} else {
bc56ad8c74b858 kaixuxia          2019-09-03  3342  		/*
bc56ad8c74b858 kaixuxia          2019-09-03  3343  		 * If target exists 
and it's a directory, check that whether
bc56ad8c74b858 kaixuxia          2019-09-03  3344  		 * it can be destroyed.
bc56ad8c74b858 kaixuxia          2019-09-03  3345  		 */
bc56ad8c74b858 kaixuxia          2019-09-03  3346  		if 
(S_ISDIR(VFS_I(target_ip)->i_mode) &&
bc56ad8c74b858 kaixuxia          2019-09-03  3347  		 
(!xfs_dir_isempty(target_ip) ||
bc56ad8c74b858 kaixuxia          2019-09-03  3348  		 
(VFS_I(target_ip)->i_nlink > 2))) {
bc56ad8c74b858 kaixuxia          2019-09-03  3349  			error = -EEXIST;
bc56ad8c74b858 kaixuxia          2019-09-03  3350  			goto out_trans_cancel;
bc56ad8c74b858 kaixuxia          2019-09-03  3351  		}
bc56ad8c74b858 kaixuxia          2019-09-03  3352  	}
bc56ad8c74b858 kaixuxia          2019-09-03  3353  6da1b4b1ab36d8 
Darrick J. Wong   2021-01-22  3354  	/*
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3355  	 * Lock the AGI 
buffers we need to handle bumping the nlink of the
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3356  	 * whiteout inode 
off the unlinked list and to handle dropping the
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3357  	 * nlink of the 
target inode.  Per locking order rules, do this in
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3358  	 * increasing AG 
order and before directory block allocation tries to
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3359  	 * grab AGFs because 
we grab AGIs before AGFs.
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3360  	 *
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3361  	 * The (vfs) caller 
must ensure that if src is a directory then
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3362  	 * target_ip is 
either null or an empty directory.
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3363  	 */
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3364  	for (i = 0; i < 
num_inodes && inodes[i] != NULL; i++) {
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3365  		if (inodes[i] == wip ||
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3366  		    (inodes[i] == 
target_ip &&
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3367  		 
(VFS_I(target_ip)->i_nlink == 1 || src_is_directory))) {
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3368  			struct xfs_buf	*bp;
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3369  			xfs_agnumber_t	agno;
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3370  6da1b4b1ab36d8 
Darrick J. Wong   2021-01-22  3371  			agno = XFS_INO_TO_AGNO(mp, 
inodes[i]->i_ino);
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3372  			error = 
xfs_read_agi(mp, tp, agno, &bp);
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3373  			if (error)
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3374  				goto 
out_trans_cancel;
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3375  		}
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3376  	}
6da1b4b1ab36d8 Darrick J. Wong   2021-01-22  3377  bc56ad8c74b858 
kaixuxia          2019-09-03  3378  	/*
bc56ad8c74b858 kaixuxia          2019-09-03  3379  	 * Directory entry 
creation below may acquire the AGF. Remove
bc56ad8c74b858 kaixuxia          2019-09-03  3380  	 * the whiteout from 
the unlinked list first to preserve correct
bc56ad8c74b858 kaixuxia          2019-09-03  3381  	 * AGI/AGF locking 
order. This dirties the transaction so failures
bc56ad8c74b858 kaixuxia          2019-09-03  3382  	 * after this point 
will abort and log recovery will clean up the
bc56ad8c74b858 kaixuxia          2019-09-03  3383  	 * mess.
bc56ad8c74b858 kaixuxia          2019-09-03  3384  	 *
bc56ad8c74b858 kaixuxia          2019-09-03  3385  	 * For whiteouts, we 
need to bump the link count on the whiteout
bc56ad8c74b858 kaixuxia          2019-09-03  3386  	 * inode. After this 
point, we have a real link, clear the tmpfile
bc56ad8c74b858 kaixuxia          2019-09-03  3387  	 * state flag from 
the inode so it doesn't accidentally get misused
bc56ad8c74b858 kaixuxia          2019-09-03  3388  	 * in future.
bc56ad8c74b858 kaixuxia          2019-09-03  3389  	 */
bc56ad8c74b858 kaixuxia          2019-09-03  3390  	if (wip) {
f40aadb2bb64fe Dave Chinner      2021-06-02  3391  		struct xfs_perag	*pag;
f40aadb2bb64fe Dave Chinner      2021-06-02  3392  bc56ad8c74b858 
kaixuxia          2019-09-03  3393  		ASSERT(VFS_I(wip)->i_nlink == 0);
f40aadb2bb64fe Dave Chinner      2021-06-02  3394  f40aadb2bb64fe Dave 
Chinner      2021-06-02  3395  		pag = xfs_perag_get(mp, 
XFS_INO_TO_AGNO(mp, wip->i_ino));
f40aadb2bb64fe Dave Chinner      2021-06-02  3396  		error = 
xfs_iunlink_remove(tp, pag, wip);
f40aadb2bb64fe Dave Chinner      2021-06-02  3397  		xfs_perag_put(pag);
bc56ad8c74b858 kaixuxia          2019-09-03  3398  		if (error)
bc56ad8c74b858 kaixuxia          2019-09-03  3399  			goto out_trans_cancel;
bc56ad8c74b858 kaixuxia          2019-09-03  3400  bc56ad8c74b858 
kaixuxia          2019-09-03  3401  		xfs_bumplink(tp, wip);
bc56ad8c74b858 kaixuxia          2019-09-03  3402  		VFS_I(wip)->i_state 
&= ~I_LINKABLE;
bc56ad8c74b858 kaixuxia          2019-09-03  3403  	}
bc56ad8c74b858 kaixuxia          2019-09-03  3404  bc56ad8c74b858 
kaixuxia          2019-09-03  3405  	/*
bc56ad8c74b858 kaixuxia          2019-09-03  3406  	 * Set up the target.
bc56ad8c74b858 kaixuxia          2019-09-03  3407  	 */
bc56ad8c74b858 kaixuxia          2019-09-03  3408  	if (target_ip == NULL) {
f6bba2017afb3b Dave Chinner      2013-08-12  3409  		/*
f6bba2017afb3b Dave Chinner      2013-08-12  3410  		 * If target does 
not exist and the rename crosses
f6bba2017afb3b Dave Chinner      2013-08-12  3411  		 * directories, 
adjust the target directory link count
f6bba2017afb3b Dave Chinner      2013-08-12  3412  		 * to account for 
the ".." reference from the new entry.
f6bba2017afb3b Dave Chinner      2013-08-12  3413  		 */
f6bba2017afb3b Dave Chinner      2013-08-12  3414  		error = 
xfs_dir_createname(tp, target_dp, target_name,
3818584f03ce2d Allison Henderson 2021-03-24  3415  					 
src_ip->i_ino, spaceres, &new_diroffset);
f6bba2017afb3b Dave Chinner      2013-08-12  3416  		if (error)
c8eac49ef798a7 Brian Foster      2018-07-24  3417  			goto out_trans_cancel;
f6bba2017afb3b Dave Chinner      2013-08-12  3418  f6bba2017afb3b Dave 
Chinner      2013-08-12  3419  		xfs_trans_ichgtime(tp, target_dp,
f6bba2017afb3b Dave Chinner      2013-08-12  3420  					XFS_ICHGTIME_MOD 
| XFS_ICHGTIME_CHG);
f6bba2017afb3b Dave Chinner      2013-08-12  3421  f6bba2017afb3b Dave 
Chinner      2013-08-12  3422  		if (new_parent && src_is_directory) {
910832697cf855 Eric Sandeen      2019-05-01  3423  			xfs_bumplink(tp, 
target_dp);
f6bba2017afb3b Dave Chinner      2013-08-12  3424  		}
f6bba2017afb3b Dave Chinner      2013-08-12  3425  	} else { /* 
target_ip != NULL */
f6bba2017afb3b Dave Chinner      2013-08-12  3426  		/*
f6bba2017afb3b Dave Chinner      2013-08-12  3427  		 * Link the source 
inode under the target name.
f6bba2017afb3b Dave Chinner      2013-08-12  3428  		 * If the source 
inode is a directory and we are moving
f6bba2017afb3b Dave Chinner      2013-08-12  3429  		 * it across 
directories, its ".." entry will be
f6bba2017afb3b Dave Chinner      2013-08-12  3430  		 * inconsistent 
until we replace that down below.
f6bba2017afb3b Dave Chinner      2013-08-12  3431  		 *
f6bba2017afb3b Dave Chinner      2013-08-12  3432  		 * In case there is 
already an entry with the same
f6bba2017afb3b Dave Chinner      2013-08-12  3433  		 * name at the 
destination directory, remove it first.
f6bba2017afb3b Dave Chinner      2013-08-12  3434  		 */
f6bba2017afb3b Dave Chinner      2013-08-12  3435  		error = 
xfs_dir_replace(tp, target_dp, target_name,
3818584f03ce2d Allison Henderson 2021-03-24  3436  					src_ip->i_ino, 
spaceres, &new_diroffset);
f6bba2017afb3b Dave Chinner      2013-08-12  3437  		if (error)
c8eac49ef798a7 Brian Foster      2018-07-24  3438  			goto out_trans_cancel;
f6bba2017afb3b Dave Chinner      2013-08-12  3439  f6bba2017afb3b Dave 
Chinner      2013-08-12  3440  		xfs_trans_ichgtime(tp, target_dp,
f6bba2017afb3b Dave Chinner      2013-08-12  3441  					XFS_ICHGTIME_MOD 
| XFS_ICHGTIME_CHG);
f6bba2017afb3b Dave Chinner      2013-08-12  3442  f6bba2017afb3b Dave 
Chinner      2013-08-12  3443  		/*
f6bba2017afb3b Dave Chinner      2013-08-12  3444  		 * Decrement the 
link count on the target since the target
f6bba2017afb3b Dave Chinner      2013-08-12  3445  		 * dir no longer 
points to it.
f6bba2017afb3b Dave Chinner      2013-08-12  3446  		 */
f6bba2017afb3b Dave Chinner      2013-08-12  3447  		error = 
xfs_droplink(tp, target_ip);
f6bba2017afb3b Dave Chinner      2013-08-12  3448  		if (error)
c8eac49ef798a7 Brian Foster      2018-07-24  3449  			goto out_trans_cancel;
f6bba2017afb3b Dave Chinner      2013-08-12  3450  f6bba2017afb3b Dave 
Chinner      2013-08-12  3451  		if (src_is_directory) {
f6bba2017afb3b Dave Chinner      2013-08-12  3452  			/*
f6bba2017afb3b Dave Chinner      2013-08-12  3453  			 * Drop the link 
from the old "." entry.
f6bba2017afb3b Dave Chinner      2013-08-12  3454  			 */
f6bba2017afb3b Dave Chinner      2013-08-12  3455  			error = 
xfs_droplink(tp, target_ip);
f6bba2017afb3b Dave Chinner      2013-08-12  3456  			if (error)
c8eac49ef798a7 Brian Foster      2018-07-24  3457  				goto 
out_trans_cancel;
f6bba2017afb3b Dave Chinner      2013-08-12  3458  		}
f6bba2017afb3b Dave Chinner      2013-08-12  3459  	} /* target_ip != 
NULL */
f6bba2017afb3b Dave Chinner      2013-08-12  3460  f6bba2017afb3b Dave 
Chinner      2013-08-12  3461  	/*
f6bba2017afb3b Dave Chinner      2013-08-12  3462  	 * Remove the source.
f6bba2017afb3b Dave Chinner      2013-08-12  3463  	 */
f6bba2017afb3b Dave Chinner      2013-08-12  3464  	if (new_parent && 
src_is_directory) {
f6bba2017afb3b Dave Chinner      2013-08-12  3465  		/*
f6bba2017afb3b Dave Chinner      2013-08-12  3466  		 * Rewrite the ".." 
entry to point to the new
f6bba2017afb3b Dave Chinner      2013-08-12  3467  		 * directory.
f6bba2017afb3b Dave Chinner      2013-08-12  3468  		 */
f6bba2017afb3b Dave Chinner      2013-08-12  3469  		error = 
xfs_dir_replace(tp, src_ip, &xfs_name_dotdot,
3818584f03ce2d Allison Henderson 2021-03-24  3470  				 
target_dp->i_ino, spaceres, &new_diroffset);
2451337dd04390 Dave Chinner      2014-06-25  3471  		ASSERT(error != 
-EEXIST);
f6bba2017afb3b Dave Chinner      2013-08-12  3472  		if (error)
c8eac49ef798a7 Brian Foster      2018-07-24  3473  			goto out_trans_cancel;
f6bba2017afb3b Dave Chinner      2013-08-12  3474  	}
f6bba2017afb3b Dave Chinner      2013-08-12  3475  f6bba2017afb3b Dave 
Chinner      2013-08-12  3476  	/*
f6bba2017afb3b Dave Chinner      2013-08-12  3477  	 * We always want to 
hit the ctime on the source inode.
f6bba2017afb3b Dave Chinner      2013-08-12  3478  	 *
f6bba2017afb3b Dave Chinner      2013-08-12  3479  	 * This isn't 
strictly required by the standards since the source
f6bba2017afb3b Dave Chinner      2013-08-12  3480  	 * inode isn't 
really being changed, but old unix file systems did
f6bba2017afb3b Dave Chinner      2013-08-12  3481  	 * it and some 
incremental backup programs won't work without it.
f6bba2017afb3b Dave Chinner      2013-08-12  3482  	 */
f6bba2017afb3b Dave Chinner      2013-08-12  3483 
xfs_trans_ichgtime(tp, src_ip, XFS_ICHGTIME_CHG);
f6bba2017afb3b Dave Chinner      2013-08-12  3484 
xfs_trans_log_inode(tp, src_ip, XFS_ILOG_CORE);
f6bba2017afb3b Dave Chinner      2013-08-12  3485  f6bba2017afb3b Dave 
Chinner      2013-08-12  3486  	/*
f6bba2017afb3b Dave Chinner      2013-08-12  3487  	 * Adjust the link 
count on src_dp.  This is necessary when
f6bba2017afb3b Dave Chinner      2013-08-12  3488  	 * renaming a 
directory, either within one parent when
f6bba2017afb3b Dave Chinner      2013-08-12  3489  	 * the target 
existed, or across two parent directories.
f6bba2017afb3b Dave Chinner      2013-08-12  3490  	 */
f6bba2017afb3b Dave Chinner      2013-08-12  3491  	if (src_is_directory 
&& (new_parent || target_ip != NULL)) {
f6bba2017afb3b Dave Chinner      2013-08-12  3492  f6bba2017afb3b Dave 
Chinner      2013-08-12  3493  		/*
f6bba2017afb3b Dave Chinner      2013-08-12  3494  		 * Decrement link 
count on src_directory since the
f6bba2017afb3b Dave Chinner      2013-08-12  3495  		 * entry that's 
moved no longer points to it.
f6bba2017afb3b Dave Chinner      2013-08-12  3496  		 */
f6bba2017afb3b Dave Chinner      2013-08-12  3497  		error = 
xfs_droplink(tp, src_dp);
f6bba2017afb3b Dave Chinner      2013-08-12  3498  		if (error)
c8eac49ef798a7 Brian Foster      2018-07-24  3499  			goto out_trans_cancel;
f6bba2017afb3b Dave Chinner      2013-08-12  3500  	}
f6bba2017afb3b Dave Chinner      2013-08-12  3501  7dcf5c3e4527cf Dave 
Chinner      2015-03-25  3502  	/*
7dcf5c3e4527cf Dave Chinner      2015-03-25  3503  	 * For whiteouts, we 
only need to update the source dirent with the
7dcf5c3e4527cf Dave Chinner      2015-03-25  3504  	 * inode number of 
the whiteout inode rather than removing it
7dcf5c3e4527cf Dave Chinner      2015-03-25  3505  	 * altogether.
7dcf5c3e4527cf Dave Chinner      2015-03-25  3506  	 */
7dcf5c3e4527cf Dave Chinner      2015-03-25  3507  	if (wip) {
7dcf5c3e4527cf Dave Chinner      2015-03-25  3508  		error = 
xfs_dir_replace(tp, src_dp, src_name, wip->i_ino,
3818584f03ce2d Allison Henderson 2021-03-24  3509  					spaceres, 
&old_diroffset);
02092a2f034fde Chandan Babu R    2021-01-22  3510  	} else {
02092a2f034fde Chandan Babu R    2021-01-22  3511  		/*
02092a2f034fde Chandan Babu R    2021-01-22  3512  		 * NOTE: We don't 
need to check for extent count overflow here
02092a2f034fde Chandan Babu R    2021-01-22  3513  		 * because the dir 
remove name code will leave the dir block in
02092a2f034fde Chandan Babu R    2021-01-22  3514  		 * place if the 
extent count would overflow.
02092a2f034fde Chandan Babu R    2021-01-22  3515  		 */
f6bba2017afb3b Dave Chinner      2013-08-12  3516  		error = 
xfs_dir_removename(tp, src_dp, src_name, src_ip->i_ino,
3818584f03ce2d Allison Henderson 2021-03-24  3517  					   spaceres, 
&old_diroffset);
02092a2f034fde Chandan Babu R    2021-01-22  3518  	}
02092a2f034fde Chandan Babu R    2021-01-22  3519  f6bba2017afb3b Dave 
Chinner      2013-08-12  3520  	if (error)
c8eac49ef798a7 Brian Foster      2018-07-24  3521  		goto out_trans_cancel;
f6bba2017afb3b Dave Chinner      2013-08-12  3522  3818584f03ce2d 
Allison Henderson 2021-03-24  3523  out_pptr:
3818584f03ce2d Allison Henderson 2021-03-24  3524  	if 
(xfs_sb_version_hasparent(&mp->m_sb)) {
3818584f03ce2d Allison Henderson 2021-03-24  3525  		new_args.trans	= tp;
3818584f03ce2d Allison Henderson 2021-03-24  3526  	 
xfs_init_parent_name_rec(&new_rec, target_dp, new_diroffset);
3818584f03ce2d Allison Henderson 2021-03-24  3527  		new_args.hashval = 
xfs_da_hashname(new_args.name,
3818584f03ce2d Allison Henderson 2021-03-24  3528  						 
new_args.namelen);
3818584f03ce2d Allison Henderson 2021-03-24  3529  		error = 
xfs_attr_set_deferred(&new_args);
3818584f03ce2d Allison Henderson 2021-03-24  3530  		if (error)
3818584f03ce2d Allison Henderson 2021-03-24  3531  			goto out_trans_cancel;
3818584f03ce2d Allison Henderson 2021-03-24  3532  3818584f03ce2d 
Allison Henderson 2021-03-24  3533  		old_args.trans	= tp;
3818584f03ce2d Allison Henderson 2021-03-24  3534  	 
xfs_init_parent_name_rec(&old_rec, src_dp, old_diroffset);
3818584f03ce2d Allison Henderson 2021-03-24  3535  		old_args.hashval = 
xfs_da_hashname(old_args.name,
3818584f03ce2d Allison Henderson 2021-03-24  3536  						 
old_args.namelen);
3818584f03ce2d Allison Henderson 2021-03-24  3537  		error = 
xfs_attr_remove_deferred(&old_args);
3818584f03ce2d Allison Henderson 2021-03-24  3538  		if (error)
3818584f03ce2d Allison Henderson 2021-03-24  3539  			goto out_trans_cancel;
3818584f03ce2d Allison Henderson 2021-03-24  3540  	}
3818584f03ce2d Allison Henderson 2021-03-24  3541  f6bba2017afb3b Dave 
Chinner      2013-08-12  3542  	xfs_trans_ichgtime(tp, src_dp, 
XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
f6bba2017afb3b Dave Chinner      2013-08-12  3543 
xfs_trans_log_inode(tp, src_dp, XFS_ILOG_CORE);
f6bba2017afb3b Dave Chinner      2013-08-12  3544  	if (new_parent)
f6bba2017afb3b Dave Chinner      2013-08-12  3545  	 
xfs_trans_log_inode(tp, target_dp, XFS_ILOG_CORE);
f6bba2017afb3b Dave Chinner      2013-08-12  3546  c9cfdb38117217 Brian 
Foster      2018-07-11  3547  	error = xfs_finish_rename(tp);
3818584f03ce2d Allison Henderson 2021-03-24  3548  3818584f03ce2d 
Allison Henderson 2021-03-24  3549  out_unlock:
7dcf5c3e4527cf Dave Chinner      2015-03-25  3550  	if (wip)
44a8736bd20a08 Darrick J. Wong   2018-07-25  3551  		xfs_irele(wip);
3818584f03ce2d Allison Henderson 2021-03-24  3552  	if (wip)
3818584f03ce2d Allison Henderson 2021-03-24  3553  		xfs_iunlock(wip, 
XFS_ILOCK_EXCL);
3818584f03ce2d Allison Henderson 2021-03-24  3554  	if (target_ip)
3818584f03ce2d Allison Henderson 2021-03-24  3555  	 
xfs_iunlock(target_ip, XFS_ILOCK_EXCL);
3818584f03ce2d Allison Henderson 2021-03-24  3556  	xfs_iunlock(src_ip, 
XFS_ILOCK_EXCL);
3818584f03ce2d Allison Henderson 2021-03-24  3557  	if (new_parent)
3818584f03ce2d Allison Henderson 2021-03-24  3558  	 
xfs_iunlock(target_dp, XFS_ILOCK_EXCL);
3818584f03ce2d Allison Henderson 2021-03-24  3559  	xfs_iunlock(src_dp, 
XFS_ILOCK_EXCL);
3818584f03ce2d Allison Henderson 2021-03-24  3560  7dcf5c3e4527cf Dave 
Chinner      2015-03-25  3561  	return error;
f6bba2017afb3b Dave Chinner      2013-08-12  3562  445883e8133975 Dave 
Chinner      2015-03-25  3563  out_trans_cancel:
4906e21545814e Christoph Hellwig 2015-06-04  3564  	xfs_trans_cancel(tp);
3818584f03ce2d Allison Henderson 2021-03-24  3565  drop_incompat:
3818584f03ce2d Allison Henderson 2021-03-24  3566  	if (xfs_hasdelattr(mp))
3818584f03ce2d Allison Henderson 2021-03-24  3567  	 
xlog_drop_incompat_feat(mp->m_log);
253f4911f297b8 Christoph Hellwig 2016-04-06  3568  out_release_wip:
7dcf5c3e4527cf Dave Chinner      2015-03-25  3569  	if (wip)
44a8736bd20a08 Darrick J. Wong   2018-07-25  3570  		xfs_irele(wip);
f6bba2017afb3b Dave Chinner      2013-08-12  3571  	return error;
f6bba2017afb3b Dave Chinner      2013-08-12  3572  }
f6bba2017afb3b Dave Chinner      2013-08-12  3573
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org


Download attachment ".config.gz" of type "application/gzip" (34139 bytes)

View attachment "Attached Message Part" of type "text/plain" (151 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ