1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 2274dcf55SMike Marshall /* 3274dcf55SMike Marshall * (C) 2001 Clemson University and The University of Chicago 4274dcf55SMike Marshall * 5274dcf55SMike Marshall * See COPYING in top-level directory. 6274dcf55SMike Marshall */ 7274dcf55SMike Marshall 8274dcf55SMike Marshall /* 9274dcf55SMike Marshall * Linux VFS namei operations. 10274dcf55SMike Marshall */ 11274dcf55SMike Marshall 12274dcf55SMike Marshall #include "protocol.h" 13575e9461SMike Marshall #include "orangefs-kernel.h" 14274dcf55SMike Marshall 15274dcf55SMike Marshall /* 16274dcf55SMike Marshall * Get a newly allocated inode to go with a negative dentry. 17274dcf55SMike Marshall */ 188bb8aefdSYi Liu static int orangefs_create(struct inode *dir, 19274dcf55SMike Marshall struct dentry *dentry, 20274dcf55SMike Marshall umode_t mode, 21274dcf55SMike Marshall bool exclusive) 22274dcf55SMike Marshall { 238bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 248bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 25db0267e7SMartin Brandenburg struct orangefs_object_kref ref; 26274dcf55SMike Marshall struct inode *inode; 27a55f2d86SMartin Brandenburg struct iattr iattr; 28274dcf55SMike Marshall int ret; 29274dcf55SMike Marshall 30f66debf1SAl Viro gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd\n", 315253487eSMike Marshall __func__, 32f66debf1SAl Viro dentry); 33274dcf55SMike Marshall 348bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_CREATE); 35274dcf55SMike Marshall if (!new_op) 36274dcf55SMike Marshall return -ENOMEM; 37274dcf55SMike Marshall 38274dcf55SMike Marshall new_op->upcall.req.create.parent_refn = parent->refn; 39274dcf55SMike Marshall 40274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.create.attributes, 418bb8aefdSYi Liu ORANGEFS_TYPE_METAFILE, mode); 42274dcf55SMike Marshall 43274dcf55SMike Marshall strncpy(new_op->upcall.req.create.d_name, 446bdfb48dSXiongfeng Wang dentry->d_name.name, ORANGEFS_NAME_MAX - 1); 45274dcf55SMike Marshall 46274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 47274dcf55SMike Marshall 48274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 49f66debf1SAl Viro "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n", 505253487eSMike Marshall __func__, 51f66debf1SAl Viro dentry, 52274dcf55SMike Marshall &new_op->downcall.resp.create.refn.khandle, 535253487eSMike Marshall new_op->downcall.resp.create.refn.fs_id, 545253487eSMike Marshall new_op, 555253487eSMike Marshall ret); 56274dcf55SMike Marshall 575253487eSMike Marshall if (ret < 0) 58274dcf55SMike Marshall goto out; 59274dcf55SMike Marshall 60db0267e7SMartin Brandenburg ref = new_op->downcall.resp.create.refn; 61db0267e7SMartin Brandenburg 62db0267e7SMartin Brandenburg inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, &ref); 63274dcf55SMike Marshall if (IS_ERR(inode)) { 64f66debf1SAl Viro gossip_err("%s: Failed to allocate inode for file :%pd:\n", 655253487eSMike Marshall __func__, 66f66debf1SAl Viro dentry); 67274dcf55SMike Marshall ret = PTR_ERR(inode); 68274dcf55SMike Marshall goto out; 69274dcf55SMike Marshall } 70274dcf55SMike Marshall 71274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 72f66debf1SAl Viro "%s: Assigned inode :%pU: for file :%pd:\n", 735253487eSMike Marshall __func__, 745253487eSMike Marshall get_khandle_from_ino(inode), 75f66debf1SAl Viro dentry); 76274dcf55SMike Marshall 771e2e547aSAl Viro d_instantiate_new(dentry, inode); 78804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 798bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 8068a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 81274dcf55SMike Marshall 82274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 83f66debf1SAl Viro "%s: dentry instantiated for %pd\n", 845253487eSMike Marshall __func__, 85f66debf1SAl Viro dentry); 86274dcf55SMike Marshall 87c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 88a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 89a55f2d86SMartin Brandenburg iattr.ia_valid |= ATTR_MTIME; 90a55f2d86SMartin Brandenburg orangefs_inode_setattr(dir, &iattr); 91274dcf55SMike Marshall mark_inode_dirty_sync(dir); 92274dcf55SMike Marshall ret = 0; 93274dcf55SMike Marshall out: 94*34e6148aSMike Marshall op_release(new_op); 955253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 96f66debf1SAl Viro "%s: %pd: returning %d\n", 975253487eSMike Marshall __func__, 98f66debf1SAl Viro dentry, 995253487eSMike Marshall ret); 100274dcf55SMike Marshall return ret; 101274dcf55SMike Marshall } 102274dcf55SMike Marshall 103274dcf55SMike Marshall /* 104274dcf55SMike Marshall * Attempt to resolve an object name (dentry->d_name), parent handle, and 105274dcf55SMike Marshall * fsid into a handle for the object. 106274dcf55SMike Marshall */ 1078bb8aefdSYi Liu static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry, 108274dcf55SMike Marshall unsigned int flags) 109274dcf55SMike Marshall { 1108bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 1118bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 112274dcf55SMike Marshall struct inode *inode; 113274dcf55SMike Marshall int ret = -EINVAL; 114274dcf55SMike Marshall 115274dcf55SMike Marshall /* 116274dcf55SMike Marshall * in theory we could skip a lookup here (if the intent is to 117274dcf55SMike Marshall * create) in order to avoid a potentially failed lookup, but 118274dcf55SMike Marshall * leaving it in can skip a valid lookup and try to create a file 119274dcf55SMike Marshall * that already exists (e.g. the vfs already handles checking for 120274dcf55SMike Marshall * -EEXIST on O_EXCL opens, which is broken if we skip this lookup 121274dcf55SMike Marshall * in the create path) 122274dcf55SMike Marshall */ 123f66debf1SAl Viro gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n", 124f66debf1SAl Viro __func__, dentry); 125274dcf55SMike Marshall 12647b4948fSMartin Brandenburg if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1)) 127274dcf55SMike Marshall return ERR_PTR(-ENAMETOOLONG); 128274dcf55SMike Marshall 1298bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP); 130274dcf55SMike Marshall if (!new_op) 131274dcf55SMike Marshall return ERR_PTR(-ENOMEM); 132274dcf55SMike Marshall 1337cec28e9SMike Marshall new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW; 134274dcf55SMike Marshall 135274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n", 136274dcf55SMike Marshall __FILE__, 137274dcf55SMike Marshall __func__, 138274dcf55SMike Marshall __LINE__, 139274dcf55SMike Marshall &parent->refn.khandle); 140274dcf55SMike Marshall new_op->upcall.req.lookup.parent_refn = parent->refn; 141274dcf55SMike Marshall 142274dcf55SMike Marshall strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name, 1436bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 144274dcf55SMike Marshall 145274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 1466ceaf781SMartin Brandenburg "%s: doing lookup on %s under %pU,%d\n", 147274dcf55SMike Marshall __func__, 148274dcf55SMike Marshall new_op->upcall.req.lookup.d_name, 149274dcf55SMike Marshall &new_op->upcall.req.lookup.parent_refn.khandle, 1506ceaf781SMartin Brandenburg new_op->upcall.req.lookup.parent_refn.fs_id); 151274dcf55SMike Marshall 152274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 153274dcf55SMike Marshall 154274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 155274dcf55SMike Marshall "Lookup Got %pU, fsid %d (ret=%d)\n", 156274dcf55SMike Marshall &new_op->downcall.resp.lookup.refn.khandle, 157274dcf55SMike Marshall new_op->downcall.resp.lookup.refn.fs_id, 158274dcf55SMike Marshall ret); 159274dcf55SMike Marshall 16004bb1ba1SAl Viro if (ret >= 0) { 161804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 1628bb8aefdSYi Liu inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn); 16304bb1ba1SAl Viro } else if (ret == -ENOENT) { 16404bb1ba1SAl Viro inode = NULL; 16504bb1ba1SAl Viro } else { 16604bb1ba1SAl Viro /* must be a non-recoverable error */ 16704bb1ba1SAl Viro inode = ERR_PTR(ret); 168274dcf55SMike Marshall } 169274dcf55SMike Marshall 170274dcf55SMike Marshall op_release(new_op); 17104bb1ba1SAl Viro return d_splice_alias(inode, dentry); 172274dcf55SMike Marshall } 173274dcf55SMike Marshall 174274dcf55SMike Marshall /* return 0 on success; non-zero otherwise */ 1758bb8aefdSYi Liu static int orangefs_unlink(struct inode *dir, struct dentry *dentry) 176274dcf55SMike Marshall { 177274dcf55SMike Marshall struct inode *inode = dentry->d_inode; 1788bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 1798bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 180a55f2d86SMartin Brandenburg struct iattr iattr; 181274dcf55SMike Marshall int ret; 182274dcf55SMike Marshall 183274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 184f66debf1SAl Viro "%s: called on %pd\n" 185274dcf55SMike Marshall " (inode %pU): Parent is %pU | fs_id %d\n", 186274dcf55SMike Marshall __func__, 187f66debf1SAl Viro dentry, 188274dcf55SMike Marshall get_khandle_from_ino(inode), 189274dcf55SMike Marshall &parent->refn.khandle, 190274dcf55SMike Marshall parent->refn.fs_id); 191274dcf55SMike Marshall 1928bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE); 193274dcf55SMike Marshall if (!new_op) 194274dcf55SMike Marshall return -ENOMEM; 195274dcf55SMike Marshall 196274dcf55SMike Marshall new_op->upcall.req.remove.parent_refn = parent->refn; 197274dcf55SMike Marshall strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name, 1986bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 199274dcf55SMike Marshall 2008bb8aefdSYi Liu ret = service_operation(new_op, "orangefs_unlink", 201274dcf55SMike Marshall get_interruptible_flag(inode)); 202274dcf55SMike Marshall 2035253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 2045253487eSMike Marshall "%s: service_operation returned:%d:\n", 2055253487eSMike Marshall __func__, 2065253487eSMike Marshall ret); 2075253487eSMike Marshall 208274dcf55SMike Marshall op_release(new_op); 209274dcf55SMike Marshall 210274dcf55SMike Marshall if (!ret) { 211274dcf55SMike Marshall drop_nlink(inode); 212274dcf55SMike Marshall 213c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 214a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 215a55f2d86SMartin Brandenburg iattr.ia_valid |= ATTR_MTIME; 216a55f2d86SMartin Brandenburg orangefs_inode_setattr(dir, &iattr); 217274dcf55SMike Marshall mark_inode_dirty_sync(dir); 218274dcf55SMike Marshall } 219274dcf55SMike Marshall return ret; 220274dcf55SMike Marshall } 221274dcf55SMike Marshall 2228bb8aefdSYi Liu static int orangefs_symlink(struct inode *dir, 223274dcf55SMike Marshall struct dentry *dentry, 224274dcf55SMike Marshall const char *symname) 225274dcf55SMike Marshall { 2268bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 2278bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 228db0267e7SMartin Brandenburg struct orangefs_object_kref ref; 229274dcf55SMike Marshall struct inode *inode; 230a55f2d86SMartin Brandenburg struct iattr iattr; 231274dcf55SMike Marshall int mode = 755; 232274dcf55SMike Marshall int ret; 233274dcf55SMike Marshall 234274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__); 235274dcf55SMike Marshall 236274dcf55SMike Marshall if (!symname) 237274dcf55SMike Marshall return -EINVAL; 238274dcf55SMike Marshall 239c62da585SMartin Brandenburg if (strlen(symname)+1 > ORANGEFS_NAME_MAX) 240c62da585SMartin Brandenburg return -ENAMETOOLONG; 241c62da585SMartin Brandenburg 2428bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK); 243274dcf55SMike Marshall if (!new_op) 244274dcf55SMike Marshall return -ENOMEM; 245274dcf55SMike Marshall 246274dcf55SMike Marshall new_op->upcall.req.sym.parent_refn = parent->refn; 247274dcf55SMike Marshall 248274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.sym.attributes, 2498bb8aefdSYi Liu ORANGEFS_TYPE_SYMLINK, 250274dcf55SMike Marshall mode); 251274dcf55SMike Marshall 252274dcf55SMike Marshall strncpy(new_op->upcall.req.sym.entry_name, 253274dcf55SMike Marshall dentry->d_name.name, 2546bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 2556bdfb48dSXiongfeng Wang strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX - 1); 256274dcf55SMike Marshall 257274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 258274dcf55SMike Marshall 259274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 2608bb8aefdSYi Liu "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n", 261274dcf55SMike Marshall &new_op->downcall.resp.sym.refn.khandle, 262274dcf55SMike Marshall new_op->downcall.resp.sym.refn.fs_id, ret); 263274dcf55SMike Marshall 264274dcf55SMike Marshall if (ret < 0) { 265274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 266274dcf55SMike Marshall "%s: failed with error code %d\n", 267274dcf55SMike Marshall __func__, ret); 268274dcf55SMike Marshall goto out; 269274dcf55SMike Marshall } 270274dcf55SMike Marshall 271db0267e7SMartin Brandenburg ref = new_op->downcall.resp.sym.refn; 272db0267e7SMartin Brandenburg 273db0267e7SMartin Brandenburg inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref); 274274dcf55SMike Marshall if (IS_ERR(inode)) { 275274dcf55SMike Marshall gossip_err 2768bb8aefdSYi Liu ("*** Failed to allocate orangefs symlink inode\n"); 277274dcf55SMike Marshall ret = PTR_ERR(inode); 278274dcf55SMike Marshall goto out; 279274dcf55SMike Marshall } 280f6a4b4c9SMartin Brandenburg /* 281f6a4b4c9SMartin Brandenburg * This is necessary because orangefs_inode_getattr will not 282f6a4b4c9SMartin Brandenburg * re-read symlink size as it is impossible for it to change. 283f6a4b4c9SMartin Brandenburg * Invalidating the cache does not help. orangefs_new_inode 284f6a4b4c9SMartin Brandenburg * does not set the correct size (it does not know symname). 285f6a4b4c9SMartin Brandenburg */ 286f6a4b4c9SMartin Brandenburg inode->i_size = strlen(symname); 287274dcf55SMike Marshall 288274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 289274dcf55SMike Marshall "Assigned symlink inode new number of %pU\n", 290274dcf55SMike Marshall get_khandle_from_ino(inode)); 291274dcf55SMike Marshall 2921e2e547aSAl Viro d_instantiate_new(dentry, inode); 293804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 2948bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 29568a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 296274dcf55SMike Marshall 297274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 298f66debf1SAl Viro "Inode (Symlink) %pU -> %pd\n", 299274dcf55SMike Marshall get_khandle_from_ino(inode), 300f66debf1SAl Viro dentry); 301274dcf55SMike Marshall 302c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 303a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 304a55f2d86SMartin Brandenburg iattr.ia_valid |= ATTR_MTIME; 305a55f2d86SMartin Brandenburg orangefs_inode_setattr(dir, &iattr); 306274dcf55SMike Marshall mark_inode_dirty_sync(dir); 307274dcf55SMike Marshall ret = 0; 308274dcf55SMike Marshall out: 309*34e6148aSMike Marshall op_release(new_op); 310274dcf55SMike Marshall return ret; 311274dcf55SMike Marshall } 312274dcf55SMike Marshall 3138bb8aefdSYi Liu static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 314274dcf55SMike Marshall { 3158bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 3168bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 317db0267e7SMartin Brandenburg struct orangefs_object_kref ref; 318274dcf55SMike Marshall struct inode *inode; 319a55f2d86SMartin Brandenburg struct iattr iattr; 320274dcf55SMike Marshall int ret; 321274dcf55SMike Marshall 3228bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR); 323274dcf55SMike Marshall if (!new_op) 324274dcf55SMike Marshall return -ENOMEM; 325274dcf55SMike Marshall 326274dcf55SMike Marshall new_op->upcall.req.mkdir.parent_refn = parent->refn; 327274dcf55SMike Marshall 328274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes, 3298bb8aefdSYi Liu ORANGEFS_TYPE_DIRECTORY, mode); 330274dcf55SMike Marshall 331274dcf55SMike Marshall strncpy(new_op->upcall.req.mkdir.d_name, 3326bdfb48dSXiongfeng Wang dentry->d_name.name, ORANGEFS_NAME_MAX - 1); 333274dcf55SMike Marshall 334274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 335274dcf55SMike Marshall 336274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 3378bb8aefdSYi Liu "Mkdir Got ORANGEFS handle %pU on fsid %d\n", 338274dcf55SMike Marshall &new_op->downcall.resp.mkdir.refn.khandle, 339274dcf55SMike Marshall new_op->downcall.resp.mkdir.refn.fs_id); 340274dcf55SMike Marshall 341274dcf55SMike Marshall if (ret < 0) { 342274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 343274dcf55SMike Marshall "%s: failed with error code %d\n", 344274dcf55SMike Marshall __func__, ret); 345274dcf55SMike Marshall goto out; 346274dcf55SMike Marshall } 347274dcf55SMike Marshall 348db0267e7SMartin Brandenburg ref = new_op->downcall.resp.mkdir.refn; 349db0267e7SMartin Brandenburg 350db0267e7SMartin Brandenburg inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref); 351274dcf55SMike Marshall if (IS_ERR(inode)) { 3528bb8aefdSYi Liu gossip_err("*** Failed to allocate orangefs dir inode\n"); 353274dcf55SMike Marshall ret = PTR_ERR(inode); 354274dcf55SMike Marshall goto out; 355274dcf55SMike Marshall } 356274dcf55SMike Marshall 357274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 358274dcf55SMike Marshall "Assigned dir inode new number of %pU\n", 359274dcf55SMike Marshall get_khandle_from_ino(inode)); 360274dcf55SMike Marshall 3611e2e547aSAl Viro d_instantiate_new(dentry, inode); 362804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 3638bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 36468a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 365274dcf55SMike Marshall 366274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 367f66debf1SAl Viro "Inode (Directory) %pU -> %pd\n", 368274dcf55SMike Marshall get_khandle_from_ino(inode), 369f66debf1SAl Viro dentry); 370274dcf55SMike Marshall 371274dcf55SMike Marshall /* 372274dcf55SMike Marshall * NOTE: we have no good way to keep nlink consistent for directories 373274dcf55SMike Marshall * across clients; keep constant at 1. 374274dcf55SMike Marshall */ 375c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 376a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 377a55f2d86SMartin Brandenburg iattr.ia_valid |= ATTR_MTIME; 378a55f2d86SMartin Brandenburg orangefs_inode_setattr(dir, &iattr); 379274dcf55SMike Marshall mark_inode_dirty_sync(dir); 380274dcf55SMike Marshall out: 381*34e6148aSMike Marshall op_release(new_op); 382274dcf55SMike Marshall return ret; 383274dcf55SMike Marshall } 384274dcf55SMike Marshall 3858bb8aefdSYi Liu static int orangefs_rename(struct inode *old_dir, 386274dcf55SMike Marshall struct dentry *old_dentry, 387274dcf55SMike Marshall struct inode *new_dir, 3881cd66c93SMiklos Szeredi struct dentry *new_dentry, 3891cd66c93SMiklos Szeredi unsigned int flags) 390274dcf55SMike Marshall { 3918bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 392274dcf55SMike Marshall int ret; 393274dcf55SMike Marshall 3941cd66c93SMiklos Szeredi if (flags) 3951cd66c93SMiklos Szeredi return -EINVAL; 3961cd66c93SMiklos Szeredi 397274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 39896b0cffbSAl Viro "orangefs_rename: called (%pd2 => %pd2) ct=%d\n", 39996b0cffbSAl Viro old_dentry, new_dentry, d_count(new_dentry)); 400274dcf55SMike Marshall 4018bbb20a8SMartin Brandenburg ORANGEFS_I(new_dentry->d_parent->d_inode)->getattr_time = jiffies - 1; 40271680c18SMartin Brandenburg 4038bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_RENAME); 404274dcf55SMike Marshall if (!new_op) 405274dcf55SMike Marshall return -EINVAL; 406274dcf55SMike Marshall 4078bb8aefdSYi Liu new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn; 4088bb8aefdSYi Liu new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn; 409274dcf55SMike Marshall 410274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_old_name, 411274dcf55SMike Marshall old_dentry->d_name.name, 4126bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 413274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_new_name, 414274dcf55SMike Marshall new_dentry->d_name.name, 4156bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 416274dcf55SMike Marshall 417274dcf55SMike Marshall ret = service_operation(new_op, 4188bb8aefdSYi Liu "orangefs_rename", 419274dcf55SMike Marshall get_interruptible_flag(old_dentry->d_inode)); 420274dcf55SMike Marshall 421274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 4228bb8aefdSYi Liu "orangefs_rename: got downcall status %d\n", 423274dcf55SMike Marshall ret); 424274dcf55SMike Marshall 425274dcf55SMike Marshall if (new_dentry->d_inode) 426c2050a45SDeepa Dinamani new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode); 427274dcf55SMike Marshall 428274dcf55SMike Marshall op_release(new_op); 429274dcf55SMike Marshall return ret; 430274dcf55SMike Marshall } 431274dcf55SMike Marshall 4328bb8aefdSYi Liu /* ORANGEFS implementation of VFS inode operations for directories */ 4336f3fc107SAl Viro const struct inode_operations orangefs_dir_inode_operations = { 4348bb8aefdSYi Liu .lookup = orangefs_lookup, 4358bb8aefdSYi Liu .get_acl = orangefs_get_acl, 4368bb8aefdSYi Liu .set_acl = orangefs_set_acl, 4378bb8aefdSYi Liu .create = orangefs_create, 4388bb8aefdSYi Liu .unlink = orangefs_unlink, 4398bb8aefdSYi Liu .symlink = orangefs_symlink, 4408bb8aefdSYi Liu .mkdir = orangefs_mkdir, 4418bb8aefdSYi Liu .rmdir = orangefs_unlink, 4428bb8aefdSYi Liu .rename = orangefs_rename, 4438bb8aefdSYi Liu .setattr = orangefs_setattr, 4448bb8aefdSYi Liu .getattr = orangefs_getattr, 4458bb8aefdSYi Liu .listxattr = orangefs_listxattr, 446933287daSMartin Brandenburg .permission = orangefs_permission, 447a55f2d86SMartin Brandenburg .update_time = orangefs_update_time, 448274dcf55SMike Marshall }; 449