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); 79274dcf55SMike Marshall 80274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 81f66debf1SAl Viro "%s: dentry instantiated for %pd\n", 825253487eSMike Marshall __func__, 83f66debf1SAl Viro dentry); 84274dcf55SMike Marshall 85a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 86*afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME; 87*afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(dir); 88*afd9fb2aSMartin Brandenburg __orangefs_setattr(dir, &iattr); 89274dcf55SMike Marshall ret = 0; 90274dcf55SMike Marshall out: 9134e6148aSMike Marshall op_release(new_op); 925253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 93f66debf1SAl Viro "%s: %pd: returning %d\n", 945253487eSMike Marshall __func__, 95f66debf1SAl Viro dentry, 965253487eSMike Marshall ret); 97274dcf55SMike Marshall return ret; 98274dcf55SMike Marshall } 99274dcf55SMike Marshall 100274dcf55SMike Marshall /* 101274dcf55SMike Marshall * Attempt to resolve an object name (dentry->d_name), parent handle, and 102274dcf55SMike Marshall * fsid into a handle for the object. 103274dcf55SMike Marshall */ 1048bb8aefdSYi Liu static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry, 105274dcf55SMike Marshall unsigned int flags) 106274dcf55SMike Marshall { 1078bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 1088bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 109274dcf55SMike Marshall struct inode *inode; 110274dcf55SMike Marshall int ret = -EINVAL; 111274dcf55SMike Marshall 112274dcf55SMike Marshall /* 113274dcf55SMike Marshall * in theory we could skip a lookup here (if the intent is to 114274dcf55SMike Marshall * create) in order to avoid a potentially failed lookup, but 115274dcf55SMike Marshall * leaving it in can skip a valid lookup and try to create a file 116274dcf55SMike Marshall * that already exists (e.g. the vfs already handles checking for 117274dcf55SMike Marshall * -EEXIST on O_EXCL opens, which is broken if we skip this lookup 118274dcf55SMike Marshall * in the create path) 119274dcf55SMike Marshall */ 120f66debf1SAl Viro gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n", 121f66debf1SAl Viro __func__, dentry); 122274dcf55SMike Marshall 12347b4948fSMartin Brandenburg if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1)) 124274dcf55SMike Marshall return ERR_PTR(-ENAMETOOLONG); 125274dcf55SMike Marshall 1268bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP); 127274dcf55SMike Marshall if (!new_op) 128274dcf55SMike Marshall return ERR_PTR(-ENOMEM); 129274dcf55SMike Marshall 1307cec28e9SMike Marshall new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW; 131274dcf55SMike Marshall 132274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n", 133274dcf55SMike Marshall __FILE__, 134274dcf55SMike Marshall __func__, 135274dcf55SMike Marshall __LINE__, 136274dcf55SMike Marshall &parent->refn.khandle); 137274dcf55SMike Marshall new_op->upcall.req.lookup.parent_refn = parent->refn; 138274dcf55SMike Marshall 139274dcf55SMike Marshall strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name, 1406bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 141274dcf55SMike Marshall 142274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 1436ceaf781SMartin Brandenburg "%s: doing lookup on %s under %pU,%d\n", 144274dcf55SMike Marshall __func__, 145274dcf55SMike Marshall new_op->upcall.req.lookup.d_name, 146274dcf55SMike Marshall &new_op->upcall.req.lookup.parent_refn.khandle, 1476ceaf781SMartin Brandenburg new_op->upcall.req.lookup.parent_refn.fs_id); 148274dcf55SMike Marshall 149274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 150274dcf55SMike Marshall 151274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 152274dcf55SMike Marshall "Lookup Got %pU, fsid %d (ret=%d)\n", 153274dcf55SMike Marshall &new_op->downcall.resp.lookup.refn.khandle, 154274dcf55SMike Marshall new_op->downcall.resp.lookup.refn.fs_id, 155274dcf55SMike Marshall ret); 156274dcf55SMike Marshall 15722fc9db2SMike Marshall if (ret == 0) { 158804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 1598bb8aefdSYi Liu inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn); 16004bb1ba1SAl Viro } else if (ret == -ENOENT) { 16104bb1ba1SAl Viro inode = NULL; 16204bb1ba1SAl Viro } else { 16304bb1ba1SAl Viro /* must be a non-recoverable error */ 16404bb1ba1SAl Viro inode = ERR_PTR(ret); 165274dcf55SMike Marshall } 166274dcf55SMike Marshall 167274dcf55SMike Marshall op_release(new_op); 16804bb1ba1SAl Viro return d_splice_alias(inode, dentry); 169274dcf55SMike Marshall } 170274dcf55SMike Marshall 171274dcf55SMike Marshall /* return 0 on success; non-zero otherwise */ 1728bb8aefdSYi Liu static int orangefs_unlink(struct inode *dir, struct dentry *dentry) 173274dcf55SMike Marshall { 174274dcf55SMike Marshall struct inode *inode = dentry->d_inode; 1758bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 1768bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 177a55f2d86SMartin Brandenburg struct iattr iattr; 178274dcf55SMike Marshall int ret; 179274dcf55SMike Marshall 180274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 181f66debf1SAl Viro "%s: called on %pd\n" 182274dcf55SMike Marshall " (inode %pU): Parent is %pU | fs_id %d\n", 183274dcf55SMike Marshall __func__, 184f66debf1SAl Viro dentry, 185274dcf55SMike Marshall get_khandle_from_ino(inode), 186274dcf55SMike Marshall &parent->refn.khandle, 187274dcf55SMike Marshall parent->refn.fs_id); 188274dcf55SMike Marshall 1898bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE); 190274dcf55SMike Marshall if (!new_op) 191274dcf55SMike Marshall return -ENOMEM; 192274dcf55SMike Marshall 193274dcf55SMike Marshall new_op->upcall.req.remove.parent_refn = parent->refn; 194274dcf55SMike Marshall strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name, 1956bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 196274dcf55SMike Marshall 1978bb8aefdSYi Liu ret = service_operation(new_op, "orangefs_unlink", 198274dcf55SMike Marshall get_interruptible_flag(inode)); 199274dcf55SMike Marshall 2005253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 2015253487eSMike Marshall "%s: service_operation returned:%d:\n", 2025253487eSMike Marshall __func__, 2035253487eSMike Marshall ret); 2045253487eSMike Marshall 205274dcf55SMike Marshall op_release(new_op); 206274dcf55SMike Marshall 207274dcf55SMike Marshall if (!ret) { 208274dcf55SMike Marshall drop_nlink(inode); 209274dcf55SMike Marshall 210a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 211*afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME; 212*afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(dir); 213*afd9fb2aSMartin Brandenburg __orangefs_setattr(dir, &iattr); 214274dcf55SMike Marshall } 215274dcf55SMike Marshall return ret; 216274dcf55SMike Marshall } 217274dcf55SMike Marshall 2188bb8aefdSYi Liu static int orangefs_symlink(struct inode *dir, 219274dcf55SMike Marshall struct dentry *dentry, 220274dcf55SMike Marshall const char *symname) 221274dcf55SMike Marshall { 2228bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 2238bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 224db0267e7SMartin Brandenburg struct orangefs_object_kref ref; 225274dcf55SMike Marshall struct inode *inode; 226a55f2d86SMartin Brandenburg struct iattr iattr; 227274dcf55SMike Marshall int mode = 755; 228274dcf55SMike Marshall int ret; 229274dcf55SMike Marshall 230274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__); 231274dcf55SMike Marshall 232274dcf55SMike Marshall if (!symname) 233274dcf55SMike Marshall return -EINVAL; 234274dcf55SMike Marshall 235c62da585SMartin Brandenburg if (strlen(symname)+1 > ORANGEFS_NAME_MAX) 236c62da585SMartin Brandenburg return -ENAMETOOLONG; 237c62da585SMartin Brandenburg 2388bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK); 239274dcf55SMike Marshall if (!new_op) 240274dcf55SMike Marshall return -ENOMEM; 241274dcf55SMike Marshall 242274dcf55SMike Marshall new_op->upcall.req.sym.parent_refn = parent->refn; 243274dcf55SMike Marshall 244274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.sym.attributes, 2458bb8aefdSYi Liu ORANGEFS_TYPE_SYMLINK, 246274dcf55SMike Marshall mode); 247274dcf55SMike Marshall 248274dcf55SMike Marshall strncpy(new_op->upcall.req.sym.entry_name, 249274dcf55SMike Marshall dentry->d_name.name, 2506bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 2516bdfb48dSXiongfeng Wang strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX - 1); 252274dcf55SMike Marshall 253274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 254274dcf55SMike Marshall 255274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 2568bb8aefdSYi Liu "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n", 257274dcf55SMike Marshall &new_op->downcall.resp.sym.refn.khandle, 258274dcf55SMike Marshall new_op->downcall.resp.sym.refn.fs_id, ret); 259274dcf55SMike Marshall 260274dcf55SMike Marshall if (ret < 0) { 261274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 262274dcf55SMike Marshall "%s: failed with error code %d\n", 263274dcf55SMike Marshall __func__, ret); 264274dcf55SMike Marshall goto out; 265274dcf55SMike Marshall } 266274dcf55SMike Marshall 267db0267e7SMartin Brandenburg ref = new_op->downcall.resp.sym.refn; 268db0267e7SMartin Brandenburg 269db0267e7SMartin Brandenburg inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref); 270274dcf55SMike Marshall if (IS_ERR(inode)) { 271274dcf55SMike Marshall gossip_err 2728bb8aefdSYi Liu ("*** Failed to allocate orangefs symlink inode\n"); 273274dcf55SMike Marshall ret = PTR_ERR(inode); 274274dcf55SMike Marshall goto out; 275274dcf55SMike Marshall } 276f6a4b4c9SMartin Brandenburg /* 277f6a4b4c9SMartin Brandenburg * This is necessary because orangefs_inode_getattr will not 278f6a4b4c9SMartin Brandenburg * re-read symlink size as it is impossible for it to change. 279f6a4b4c9SMartin Brandenburg * Invalidating the cache does not help. orangefs_new_inode 280f6a4b4c9SMartin Brandenburg * does not set the correct size (it does not know symname). 281f6a4b4c9SMartin Brandenburg */ 282f6a4b4c9SMartin Brandenburg inode->i_size = strlen(symname); 283274dcf55SMike Marshall 284274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 285274dcf55SMike Marshall "Assigned symlink inode new number of %pU\n", 286274dcf55SMike Marshall get_khandle_from_ino(inode)); 287274dcf55SMike Marshall 2881e2e547aSAl Viro d_instantiate_new(dentry, inode); 289804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 290274dcf55SMike Marshall 291274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 292f66debf1SAl Viro "Inode (Symlink) %pU -> %pd\n", 293274dcf55SMike Marshall get_khandle_from_ino(inode), 294f66debf1SAl Viro dentry); 295274dcf55SMike Marshall 296a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 297*afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME; 298*afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(dir); 299*afd9fb2aSMartin Brandenburg __orangefs_setattr(dir, &iattr); 300274dcf55SMike Marshall ret = 0; 301274dcf55SMike Marshall out: 30234e6148aSMike Marshall op_release(new_op); 303274dcf55SMike Marshall return ret; 304274dcf55SMike Marshall } 305274dcf55SMike Marshall 3068bb8aefdSYi Liu static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 307274dcf55SMike Marshall { 3088bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 3098bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 310db0267e7SMartin Brandenburg struct orangefs_object_kref ref; 311274dcf55SMike Marshall struct inode *inode; 312a55f2d86SMartin Brandenburg struct iattr iattr; 313274dcf55SMike Marshall int ret; 314274dcf55SMike Marshall 3158bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR); 316274dcf55SMike Marshall if (!new_op) 317274dcf55SMike Marshall return -ENOMEM; 318274dcf55SMike Marshall 319274dcf55SMike Marshall new_op->upcall.req.mkdir.parent_refn = parent->refn; 320274dcf55SMike Marshall 321274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes, 3228bb8aefdSYi Liu ORANGEFS_TYPE_DIRECTORY, mode); 323274dcf55SMike Marshall 324274dcf55SMike Marshall strncpy(new_op->upcall.req.mkdir.d_name, 3256bdfb48dSXiongfeng Wang dentry->d_name.name, ORANGEFS_NAME_MAX - 1); 326274dcf55SMike Marshall 327274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 328274dcf55SMike Marshall 329274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 3308bb8aefdSYi Liu "Mkdir Got ORANGEFS handle %pU on fsid %d\n", 331274dcf55SMike Marshall &new_op->downcall.resp.mkdir.refn.khandle, 332274dcf55SMike Marshall new_op->downcall.resp.mkdir.refn.fs_id); 333274dcf55SMike Marshall 334274dcf55SMike Marshall if (ret < 0) { 335274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 336274dcf55SMike Marshall "%s: failed with error code %d\n", 337274dcf55SMike Marshall __func__, ret); 338274dcf55SMike Marshall goto out; 339274dcf55SMike Marshall } 340274dcf55SMike Marshall 341db0267e7SMartin Brandenburg ref = new_op->downcall.resp.mkdir.refn; 342db0267e7SMartin Brandenburg 343db0267e7SMartin Brandenburg inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref); 344274dcf55SMike Marshall if (IS_ERR(inode)) { 3458bb8aefdSYi Liu gossip_err("*** Failed to allocate orangefs dir inode\n"); 346274dcf55SMike Marshall ret = PTR_ERR(inode); 347274dcf55SMike Marshall goto out; 348274dcf55SMike Marshall } 349274dcf55SMike Marshall 350274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 351274dcf55SMike Marshall "Assigned dir inode new number of %pU\n", 352274dcf55SMike Marshall get_khandle_from_ino(inode)); 353274dcf55SMike Marshall 3541e2e547aSAl Viro d_instantiate_new(dentry, inode); 355804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 356274dcf55SMike Marshall 357274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 358f66debf1SAl Viro "Inode (Directory) %pU -> %pd\n", 359274dcf55SMike Marshall get_khandle_from_ino(inode), 360f66debf1SAl Viro dentry); 361274dcf55SMike Marshall 362274dcf55SMike Marshall /* 363274dcf55SMike Marshall * NOTE: we have no good way to keep nlink consistent for directories 364274dcf55SMike Marshall * across clients; keep constant at 1. 365274dcf55SMike Marshall */ 366a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 367*afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME; 368*afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(dir); 369*afd9fb2aSMartin Brandenburg __orangefs_setattr(dir, &iattr); 370274dcf55SMike Marshall out: 37134e6148aSMike Marshall op_release(new_op); 372274dcf55SMike Marshall return ret; 373274dcf55SMike Marshall } 374274dcf55SMike Marshall 3758bb8aefdSYi Liu static int orangefs_rename(struct inode *old_dir, 376274dcf55SMike Marshall struct dentry *old_dentry, 377274dcf55SMike Marshall struct inode *new_dir, 3781cd66c93SMiklos Szeredi struct dentry *new_dentry, 3791cd66c93SMiklos Szeredi unsigned int flags) 380274dcf55SMike Marshall { 3818bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 3825e7f1d43SMartin Brandenburg struct iattr iattr; 383274dcf55SMike Marshall int ret; 384274dcf55SMike Marshall 3851cd66c93SMiklos Szeredi if (flags) 3861cd66c93SMiklos Szeredi return -EINVAL; 3871cd66c93SMiklos Szeredi 388274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 38996b0cffbSAl Viro "orangefs_rename: called (%pd2 => %pd2) ct=%d\n", 39096b0cffbSAl Viro old_dentry, new_dentry, d_count(new_dentry)); 391274dcf55SMike Marshall 3925e7f1d43SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 393*afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME; 394*afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(new_dir); 395*afd9fb2aSMartin Brandenburg __orangefs_setattr(new_dir, &iattr); 39671680c18SMartin Brandenburg 3978bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_RENAME); 398274dcf55SMike Marshall if (!new_op) 399274dcf55SMike Marshall return -EINVAL; 400274dcf55SMike Marshall 4018bb8aefdSYi Liu new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn; 4028bb8aefdSYi Liu new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn; 403274dcf55SMike Marshall 404274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_old_name, 405274dcf55SMike Marshall old_dentry->d_name.name, 4066bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 407274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_new_name, 408274dcf55SMike Marshall new_dentry->d_name.name, 4096bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1); 410274dcf55SMike Marshall 411274dcf55SMike Marshall ret = service_operation(new_op, 4128bb8aefdSYi Liu "orangefs_rename", 413274dcf55SMike Marshall get_interruptible_flag(old_dentry->d_inode)); 414274dcf55SMike Marshall 415274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 4168bb8aefdSYi Liu "orangefs_rename: got downcall status %d\n", 417274dcf55SMike Marshall ret); 418274dcf55SMike Marshall 419274dcf55SMike Marshall if (new_dentry->d_inode) 420c2050a45SDeepa Dinamani new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode); 421274dcf55SMike Marshall 422274dcf55SMike Marshall op_release(new_op); 423274dcf55SMike Marshall return ret; 424274dcf55SMike Marshall } 425274dcf55SMike Marshall 4268bb8aefdSYi Liu /* ORANGEFS implementation of VFS inode operations for directories */ 4276f3fc107SAl Viro const struct inode_operations orangefs_dir_inode_operations = { 4288bb8aefdSYi Liu .lookup = orangefs_lookup, 4298bb8aefdSYi Liu .get_acl = orangefs_get_acl, 4308bb8aefdSYi Liu .set_acl = orangefs_set_acl, 4318bb8aefdSYi Liu .create = orangefs_create, 4328bb8aefdSYi Liu .unlink = orangefs_unlink, 4338bb8aefdSYi Liu .symlink = orangefs_symlink, 4348bb8aefdSYi Liu .mkdir = orangefs_mkdir, 4358bb8aefdSYi Liu .rmdir = orangefs_unlink, 4368bb8aefdSYi Liu .rename = orangefs_rename, 4378bb8aefdSYi Liu .setattr = orangefs_setattr, 4388bb8aefdSYi Liu .getattr = orangefs_getattr, 4398bb8aefdSYi Liu .listxattr = orangefs_listxattr, 440933287daSMartin Brandenburg .permission = orangefs_permission, 441a55f2d86SMartin Brandenburg .update_time = orangefs_update_time, 442274dcf55SMike Marshall }; 443