1274dcf55SMike Marshall /* 2274dcf55SMike Marshall * (C) 2001 Clemson University and The University of Chicago 3274dcf55SMike Marshall * 4274dcf55SMike Marshall * See COPYING in top-level directory. 5274dcf55SMike Marshall */ 6274dcf55SMike Marshall 7274dcf55SMike Marshall /* 8274dcf55SMike Marshall * Linux VFS namei operations. 9274dcf55SMike Marshall */ 10274dcf55SMike Marshall 11274dcf55SMike Marshall #include "protocol.h" 12575e9461SMike Marshall #include "orangefs-kernel.h" 13274dcf55SMike Marshall 14274dcf55SMike Marshall /* 15274dcf55SMike Marshall * Get a newly allocated inode to go with a negative dentry. 16274dcf55SMike Marshall */ 178bb8aefdSYi Liu static int orangefs_create(struct inode *dir, 18274dcf55SMike Marshall struct dentry *dentry, 19274dcf55SMike Marshall umode_t mode, 20274dcf55SMike Marshall bool exclusive) 21274dcf55SMike Marshall { 228bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 238bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 24274dcf55SMike Marshall struct inode *inode; 25274dcf55SMike Marshall int ret; 26274dcf55SMike Marshall 27f66debf1SAl Viro gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd\n", 285253487eSMike Marshall __func__, 29f66debf1SAl Viro dentry); 30274dcf55SMike Marshall 318bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_CREATE); 32274dcf55SMike Marshall if (!new_op) 33274dcf55SMike Marshall return -ENOMEM; 34274dcf55SMike Marshall 35274dcf55SMike Marshall new_op->upcall.req.create.parent_refn = parent->refn; 36274dcf55SMike Marshall 37274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.create.attributes, 388bb8aefdSYi Liu ORANGEFS_TYPE_METAFILE, mode); 39274dcf55SMike Marshall 40274dcf55SMike Marshall strncpy(new_op->upcall.req.create.d_name, 4147b4948fSMartin Brandenburg dentry->d_name.name, ORANGEFS_NAME_MAX); 42274dcf55SMike Marshall 43274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 44274dcf55SMike Marshall 45274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 46f66debf1SAl Viro "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n", 475253487eSMike Marshall __func__, 48f66debf1SAl Viro dentry, 49274dcf55SMike Marshall &new_op->downcall.resp.create.refn.khandle, 505253487eSMike Marshall new_op->downcall.resp.create.refn.fs_id, 515253487eSMike Marshall new_op, 525253487eSMike Marshall ret); 53274dcf55SMike Marshall 545253487eSMike Marshall if (ret < 0) 55274dcf55SMike Marshall goto out; 56274dcf55SMike Marshall 578bb8aefdSYi Liu inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, 58274dcf55SMike Marshall &new_op->downcall.resp.create.refn); 59274dcf55SMike Marshall if (IS_ERR(inode)) { 60f66debf1SAl Viro gossip_err("%s: Failed to allocate inode for file :%pd:\n", 615253487eSMike Marshall __func__, 62f66debf1SAl Viro dentry); 63274dcf55SMike Marshall ret = PTR_ERR(inode); 64274dcf55SMike Marshall goto out; 65274dcf55SMike Marshall } 66274dcf55SMike Marshall 67274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 68f66debf1SAl Viro "%s: Assigned inode :%pU: for file :%pd:\n", 695253487eSMike Marshall __func__, 705253487eSMike Marshall get_khandle_from_ino(inode), 71f66debf1SAl Viro dentry); 72274dcf55SMike Marshall 73274dcf55SMike Marshall d_instantiate(dentry, inode); 74274dcf55SMike Marshall unlock_new_inode(inode); 75804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 768bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 77*68a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 78274dcf55SMike Marshall 79274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 80f66debf1SAl Viro "%s: dentry instantiated for %pd\n", 815253487eSMike Marshall __func__, 82f66debf1SAl Viro dentry); 83274dcf55SMike Marshall 84274dcf55SMike Marshall SetMtimeFlag(parent); 85c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 86274dcf55SMike Marshall mark_inode_dirty_sync(dir); 87274dcf55SMike Marshall ret = 0; 88274dcf55SMike Marshall out: 89274dcf55SMike Marshall op_release(new_op); 905253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 91f66debf1SAl Viro "%s: %pd: returning %d\n", 925253487eSMike Marshall __func__, 93f66debf1SAl Viro dentry, 945253487eSMike Marshall ret); 95274dcf55SMike Marshall return ret; 96274dcf55SMike Marshall } 97274dcf55SMike Marshall 98274dcf55SMike Marshall /* 99274dcf55SMike Marshall * Attempt to resolve an object name (dentry->d_name), parent handle, and 100274dcf55SMike Marshall * fsid into a handle for the object. 101274dcf55SMike Marshall */ 1028bb8aefdSYi Liu static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry, 103274dcf55SMike Marshall unsigned int flags) 104274dcf55SMike Marshall { 1058bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 1068bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 107274dcf55SMike Marshall struct inode *inode; 108274dcf55SMike Marshall struct dentry *res; 109274dcf55SMike Marshall int ret = -EINVAL; 110274dcf55SMike Marshall 111274dcf55SMike Marshall /* 112274dcf55SMike Marshall * in theory we could skip a lookup here (if the intent is to 113274dcf55SMike Marshall * create) in order to avoid a potentially failed lookup, but 114274dcf55SMike Marshall * leaving it in can skip a valid lookup and try to create a file 115274dcf55SMike Marshall * that already exists (e.g. the vfs already handles checking for 116274dcf55SMike Marshall * -EEXIST on O_EXCL opens, which is broken if we skip this lookup 117274dcf55SMike Marshall * in the create path) 118274dcf55SMike Marshall */ 119f66debf1SAl Viro gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n", 120f66debf1SAl Viro __func__, dentry); 121274dcf55SMike Marshall 12247b4948fSMartin Brandenburg if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1)) 123274dcf55SMike Marshall return ERR_PTR(-ENAMETOOLONG); 124274dcf55SMike Marshall 1258bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP); 126274dcf55SMike Marshall if (!new_op) 127274dcf55SMike Marshall return ERR_PTR(-ENOMEM); 128274dcf55SMike Marshall 1297cec28e9SMike Marshall new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW; 130274dcf55SMike Marshall 131274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n", 132274dcf55SMike Marshall __FILE__, 133274dcf55SMike Marshall __func__, 134274dcf55SMike Marshall __LINE__, 135274dcf55SMike Marshall &parent->refn.khandle); 136274dcf55SMike Marshall new_op->upcall.req.lookup.parent_refn = parent->refn; 137274dcf55SMike Marshall 138274dcf55SMike Marshall strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name, 13947b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 140274dcf55SMike Marshall 141274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 1426ceaf781SMartin Brandenburg "%s: doing lookup on %s under %pU,%d\n", 143274dcf55SMike Marshall __func__, 144274dcf55SMike Marshall new_op->upcall.req.lookup.d_name, 145274dcf55SMike Marshall &new_op->upcall.req.lookup.parent_refn.khandle, 1466ceaf781SMartin Brandenburg new_op->upcall.req.lookup.parent_refn.fs_id); 147274dcf55SMike Marshall 148274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 149274dcf55SMike Marshall 150274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 151274dcf55SMike Marshall "Lookup Got %pU, fsid %d (ret=%d)\n", 152274dcf55SMike Marshall &new_op->downcall.resp.lookup.refn.khandle, 153274dcf55SMike Marshall new_op->downcall.resp.lookup.refn.fs_id, 154274dcf55SMike Marshall ret); 155274dcf55SMike Marshall 156274dcf55SMike Marshall if (ret < 0) { 157274dcf55SMike Marshall if (ret == -ENOENT) { 158274dcf55SMike Marshall /* 159274dcf55SMike Marshall * if no inode was found, add a negative dentry to 160274dcf55SMike Marshall * dcache anyway; if we don't, we don't hold expected 161274dcf55SMike Marshall * lookup semantics and we most noticeably break 162274dcf55SMike Marshall * during directory renames. 163274dcf55SMike Marshall * 164274dcf55SMike Marshall * however, if the operation failed or exited, do not 165274dcf55SMike Marshall * add the dentry (e.g. in the case that a touch is 166274dcf55SMike Marshall * issued on a file that already exists that was 167274dcf55SMike Marshall * interrupted during this lookup -- no need to add 168274dcf55SMike Marshall * another negative dentry for an existing file) 169274dcf55SMike Marshall */ 170274dcf55SMike Marshall 171274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 1728bb8aefdSYi Liu "orangefs_lookup: Adding *negative* dentry " 173f66debf1SAl Viro "%p for %pd\n", 174274dcf55SMike Marshall dentry, 175f66debf1SAl Viro dentry); 176274dcf55SMike Marshall 177274dcf55SMike Marshall d_add(dentry, NULL); 178274dcf55SMike Marshall res = NULL; 179274dcf55SMike Marshall goto out; 180274dcf55SMike Marshall } 181274dcf55SMike Marshall 182274dcf55SMike Marshall /* must be a non-recoverable error */ 183274dcf55SMike Marshall res = ERR_PTR(ret); 184274dcf55SMike Marshall goto out; 185274dcf55SMike Marshall } 186274dcf55SMike Marshall 187804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 18831b7c1abSMartin Brandenburg 1898bb8aefdSYi Liu inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn); 190274dcf55SMike Marshall if (IS_ERR(inode)) { 191274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 192274dcf55SMike Marshall "error %ld from iget\n", PTR_ERR(inode)); 193274dcf55SMike Marshall res = ERR_CAST(inode); 194274dcf55SMike Marshall goto out; 195274dcf55SMike Marshall } 196274dcf55SMike Marshall 197274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 198274dcf55SMike Marshall "%s:%s:%d " 199274dcf55SMike Marshall "Found good inode [%lu] with count [%d]\n", 200274dcf55SMike Marshall __FILE__, 201274dcf55SMike Marshall __func__, 202274dcf55SMike Marshall __LINE__, 203274dcf55SMike Marshall inode->i_ino, 204274dcf55SMike Marshall (int)atomic_read(&inode->i_count)); 205274dcf55SMike Marshall 206274dcf55SMike Marshall /* update dentry/inode pair into dcache */ 207274dcf55SMike Marshall res = d_splice_alias(inode, dentry); 208274dcf55SMike Marshall 209274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 210274dcf55SMike Marshall "Lookup success (inode ct = %d)\n", 211274dcf55SMike Marshall (int)atomic_read(&inode->i_count)); 212274dcf55SMike Marshall out: 213274dcf55SMike Marshall op_release(new_op); 214274dcf55SMike Marshall return res; 215274dcf55SMike Marshall } 216274dcf55SMike Marshall 217274dcf55SMike Marshall /* return 0 on success; non-zero otherwise */ 2188bb8aefdSYi Liu static int orangefs_unlink(struct inode *dir, struct dentry *dentry) 219274dcf55SMike Marshall { 220274dcf55SMike Marshall struct inode *inode = dentry->d_inode; 2218bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 2228bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 223274dcf55SMike Marshall int ret; 224274dcf55SMike Marshall 225274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 226f66debf1SAl Viro "%s: called on %pd\n" 227274dcf55SMike Marshall " (inode %pU): Parent is %pU | fs_id %d\n", 228274dcf55SMike Marshall __func__, 229f66debf1SAl Viro dentry, 230274dcf55SMike Marshall get_khandle_from_ino(inode), 231274dcf55SMike Marshall &parent->refn.khandle, 232274dcf55SMike Marshall parent->refn.fs_id); 233274dcf55SMike Marshall 2348bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE); 235274dcf55SMike Marshall if (!new_op) 236274dcf55SMike Marshall return -ENOMEM; 237274dcf55SMike Marshall 238274dcf55SMike Marshall new_op->upcall.req.remove.parent_refn = parent->refn; 239274dcf55SMike Marshall strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name, 24047b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 241274dcf55SMike Marshall 2428bb8aefdSYi Liu ret = service_operation(new_op, "orangefs_unlink", 243274dcf55SMike Marshall get_interruptible_flag(inode)); 244274dcf55SMike Marshall 2455253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 2465253487eSMike Marshall "%s: service_operation returned:%d:\n", 2475253487eSMike Marshall __func__, 2485253487eSMike Marshall ret); 2495253487eSMike Marshall 250274dcf55SMike Marshall op_release(new_op); 251274dcf55SMike Marshall 252274dcf55SMike Marshall if (!ret) { 253274dcf55SMike Marshall drop_nlink(inode); 254274dcf55SMike Marshall 255274dcf55SMike Marshall SetMtimeFlag(parent); 256c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 257274dcf55SMike Marshall mark_inode_dirty_sync(dir); 258274dcf55SMike Marshall } 259274dcf55SMike Marshall return ret; 260274dcf55SMike Marshall } 261274dcf55SMike Marshall 2628bb8aefdSYi Liu static int orangefs_symlink(struct inode *dir, 263274dcf55SMike Marshall struct dentry *dentry, 264274dcf55SMike Marshall const char *symname) 265274dcf55SMike Marshall { 2668bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 2678bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 268274dcf55SMike Marshall struct inode *inode; 269274dcf55SMike Marshall int mode = 755; 270274dcf55SMike Marshall int ret; 271274dcf55SMike Marshall 272274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__); 273274dcf55SMike Marshall 274274dcf55SMike Marshall if (!symname) 275274dcf55SMike Marshall return -EINVAL; 276274dcf55SMike Marshall 277c62da585SMartin Brandenburg if (strlen(symname)+1 > ORANGEFS_NAME_MAX) 278c62da585SMartin Brandenburg return -ENAMETOOLONG; 279c62da585SMartin Brandenburg 2808bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK); 281274dcf55SMike Marshall if (!new_op) 282274dcf55SMike Marshall return -ENOMEM; 283274dcf55SMike Marshall 284274dcf55SMike Marshall new_op->upcall.req.sym.parent_refn = parent->refn; 285274dcf55SMike Marshall 286274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.sym.attributes, 2878bb8aefdSYi Liu ORANGEFS_TYPE_SYMLINK, 288274dcf55SMike Marshall mode); 289274dcf55SMike Marshall 290274dcf55SMike Marshall strncpy(new_op->upcall.req.sym.entry_name, 291274dcf55SMike Marshall dentry->d_name.name, 29247b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 29347b4948fSMartin Brandenburg strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX); 294274dcf55SMike Marshall 295274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 296274dcf55SMike Marshall 297274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 2988bb8aefdSYi Liu "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n", 299274dcf55SMike Marshall &new_op->downcall.resp.sym.refn.khandle, 300274dcf55SMike Marshall new_op->downcall.resp.sym.refn.fs_id, ret); 301274dcf55SMike Marshall 302274dcf55SMike Marshall if (ret < 0) { 303274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 304274dcf55SMike Marshall "%s: failed with error code %d\n", 305274dcf55SMike Marshall __func__, ret); 306274dcf55SMike Marshall goto out; 307274dcf55SMike Marshall } 308274dcf55SMike Marshall 3098bb8aefdSYi Liu inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, 310274dcf55SMike Marshall &new_op->downcall.resp.sym.refn); 311274dcf55SMike Marshall if (IS_ERR(inode)) { 312274dcf55SMike Marshall gossip_err 3138bb8aefdSYi Liu ("*** Failed to allocate orangefs symlink inode\n"); 314274dcf55SMike Marshall ret = PTR_ERR(inode); 315274dcf55SMike Marshall goto out; 316274dcf55SMike Marshall } 317274dcf55SMike Marshall 318274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 319274dcf55SMike Marshall "Assigned symlink inode new number of %pU\n", 320274dcf55SMike Marshall get_khandle_from_ino(inode)); 321274dcf55SMike Marshall 322274dcf55SMike Marshall d_instantiate(dentry, inode); 323274dcf55SMike Marshall unlock_new_inode(inode); 324804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 3258bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 326*68a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 327274dcf55SMike Marshall 328274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 329f66debf1SAl Viro "Inode (Symlink) %pU -> %pd\n", 330274dcf55SMike Marshall get_khandle_from_ino(inode), 331f66debf1SAl Viro dentry); 332274dcf55SMike Marshall 333274dcf55SMike Marshall SetMtimeFlag(parent); 334c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 335274dcf55SMike Marshall mark_inode_dirty_sync(dir); 336274dcf55SMike Marshall ret = 0; 337274dcf55SMike Marshall out: 338274dcf55SMike Marshall op_release(new_op); 339274dcf55SMike Marshall return ret; 340274dcf55SMike Marshall } 341274dcf55SMike Marshall 3428bb8aefdSYi Liu static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 343274dcf55SMike Marshall { 3448bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 3458bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 346274dcf55SMike Marshall struct inode *inode; 347274dcf55SMike Marshall int ret; 348274dcf55SMike Marshall 3498bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR); 350274dcf55SMike Marshall if (!new_op) 351274dcf55SMike Marshall return -ENOMEM; 352274dcf55SMike Marshall 353274dcf55SMike Marshall new_op->upcall.req.mkdir.parent_refn = parent->refn; 354274dcf55SMike Marshall 355274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes, 3568bb8aefdSYi Liu ORANGEFS_TYPE_DIRECTORY, mode); 357274dcf55SMike Marshall 358274dcf55SMike Marshall strncpy(new_op->upcall.req.mkdir.d_name, 35947b4948fSMartin Brandenburg dentry->d_name.name, ORANGEFS_NAME_MAX); 360274dcf55SMike Marshall 361274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 362274dcf55SMike Marshall 363274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 3648bb8aefdSYi Liu "Mkdir Got ORANGEFS handle %pU on fsid %d\n", 365274dcf55SMike Marshall &new_op->downcall.resp.mkdir.refn.khandle, 366274dcf55SMike Marshall new_op->downcall.resp.mkdir.refn.fs_id); 367274dcf55SMike Marshall 368274dcf55SMike Marshall if (ret < 0) { 369274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 370274dcf55SMike Marshall "%s: failed with error code %d\n", 371274dcf55SMike Marshall __func__, ret); 372274dcf55SMike Marshall goto out; 373274dcf55SMike Marshall } 374274dcf55SMike Marshall 3758bb8aefdSYi Liu inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, 376274dcf55SMike Marshall &new_op->downcall.resp.mkdir.refn); 377274dcf55SMike Marshall if (IS_ERR(inode)) { 3788bb8aefdSYi Liu gossip_err("*** Failed to allocate orangefs dir inode\n"); 379274dcf55SMike Marshall ret = PTR_ERR(inode); 380274dcf55SMike Marshall goto out; 381274dcf55SMike Marshall } 382274dcf55SMike Marshall 383274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 384274dcf55SMike Marshall "Assigned dir inode new number of %pU\n", 385274dcf55SMike Marshall get_khandle_from_ino(inode)); 386274dcf55SMike Marshall 387274dcf55SMike Marshall d_instantiate(dentry, inode); 388274dcf55SMike Marshall unlock_new_inode(inode); 389804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 3908bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 391*68a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 392274dcf55SMike Marshall 393274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 394f66debf1SAl Viro "Inode (Directory) %pU -> %pd\n", 395274dcf55SMike Marshall get_khandle_from_ino(inode), 396f66debf1SAl Viro dentry); 397274dcf55SMike Marshall 398274dcf55SMike Marshall /* 399274dcf55SMike Marshall * NOTE: we have no good way to keep nlink consistent for directories 400274dcf55SMike Marshall * across clients; keep constant at 1. 401274dcf55SMike Marshall */ 402274dcf55SMike Marshall SetMtimeFlag(parent); 403c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 404274dcf55SMike Marshall mark_inode_dirty_sync(dir); 405274dcf55SMike Marshall out: 406274dcf55SMike Marshall op_release(new_op); 407274dcf55SMike Marshall return ret; 408274dcf55SMike Marshall } 409274dcf55SMike Marshall 4108bb8aefdSYi Liu static int orangefs_rename(struct inode *old_dir, 411274dcf55SMike Marshall struct dentry *old_dentry, 412274dcf55SMike Marshall struct inode *new_dir, 4131cd66c93SMiklos Szeredi struct dentry *new_dentry, 4141cd66c93SMiklos Szeredi unsigned int flags) 415274dcf55SMike Marshall { 4168bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 417274dcf55SMike Marshall int ret; 418274dcf55SMike Marshall 4191cd66c93SMiklos Szeredi if (flags) 4201cd66c93SMiklos Szeredi return -EINVAL; 4211cd66c93SMiklos Szeredi 422274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 42396b0cffbSAl Viro "orangefs_rename: called (%pd2 => %pd2) ct=%d\n", 42496b0cffbSAl Viro old_dentry, new_dentry, d_count(new_dentry)); 425274dcf55SMike Marshall 4268bbb20a8SMartin Brandenburg ORANGEFS_I(new_dentry->d_parent->d_inode)->getattr_time = jiffies - 1; 42771680c18SMartin Brandenburg 4288bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_RENAME); 429274dcf55SMike Marshall if (!new_op) 430274dcf55SMike Marshall return -EINVAL; 431274dcf55SMike Marshall 4328bb8aefdSYi Liu new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn; 4338bb8aefdSYi Liu new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn; 434274dcf55SMike Marshall 435274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_old_name, 436274dcf55SMike Marshall old_dentry->d_name.name, 43747b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 438274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_new_name, 439274dcf55SMike Marshall new_dentry->d_name.name, 44047b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 441274dcf55SMike Marshall 442274dcf55SMike Marshall ret = service_operation(new_op, 4438bb8aefdSYi Liu "orangefs_rename", 444274dcf55SMike Marshall get_interruptible_flag(old_dentry->d_inode)); 445274dcf55SMike Marshall 446274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 4478bb8aefdSYi Liu "orangefs_rename: got downcall status %d\n", 448274dcf55SMike Marshall ret); 449274dcf55SMike Marshall 450274dcf55SMike Marshall if (new_dentry->d_inode) 451c2050a45SDeepa Dinamani new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode); 452274dcf55SMike Marshall 453274dcf55SMike Marshall op_release(new_op); 454274dcf55SMike Marshall return ret; 455274dcf55SMike Marshall } 456274dcf55SMike Marshall 4578bb8aefdSYi Liu /* ORANGEFS implementation of VFS inode operations for directories */ 4586f3fc107SAl Viro const struct inode_operations orangefs_dir_inode_operations = { 4598bb8aefdSYi Liu .lookup = orangefs_lookup, 4608bb8aefdSYi Liu .get_acl = orangefs_get_acl, 4618bb8aefdSYi Liu .set_acl = orangefs_set_acl, 4628bb8aefdSYi Liu .create = orangefs_create, 4638bb8aefdSYi Liu .unlink = orangefs_unlink, 4648bb8aefdSYi Liu .symlink = orangefs_symlink, 4658bb8aefdSYi Liu .mkdir = orangefs_mkdir, 4668bb8aefdSYi Liu .rmdir = orangefs_unlink, 4678bb8aefdSYi Liu .rename = orangefs_rename, 4688bb8aefdSYi Liu .setattr = orangefs_setattr, 4698bb8aefdSYi Liu .getattr = orangefs_getattr, 4708bb8aefdSYi Liu .listxattr = orangefs_listxattr, 471933287daSMartin Brandenburg .permission = orangefs_permission, 472274dcf55SMike Marshall }; 473