1*b2441318SGreg 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; 25274dcf55SMike Marshall struct inode *inode; 26274dcf55SMike Marshall int ret; 27274dcf55SMike Marshall 28f66debf1SAl Viro gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd\n", 295253487eSMike Marshall __func__, 30f66debf1SAl Viro dentry); 31274dcf55SMike Marshall 328bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_CREATE); 33274dcf55SMike Marshall if (!new_op) 34274dcf55SMike Marshall return -ENOMEM; 35274dcf55SMike Marshall 36274dcf55SMike Marshall new_op->upcall.req.create.parent_refn = parent->refn; 37274dcf55SMike Marshall 38274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.create.attributes, 398bb8aefdSYi Liu ORANGEFS_TYPE_METAFILE, mode); 40274dcf55SMike Marshall 41274dcf55SMike Marshall strncpy(new_op->upcall.req.create.d_name, 4247b4948fSMartin Brandenburg dentry->d_name.name, ORANGEFS_NAME_MAX); 43274dcf55SMike Marshall 44274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 45274dcf55SMike Marshall 46274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 47f66debf1SAl Viro "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n", 485253487eSMike Marshall __func__, 49f66debf1SAl Viro dentry, 50274dcf55SMike Marshall &new_op->downcall.resp.create.refn.khandle, 515253487eSMike Marshall new_op->downcall.resp.create.refn.fs_id, 525253487eSMike Marshall new_op, 535253487eSMike Marshall ret); 54274dcf55SMike Marshall 555253487eSMike Marshall if (ret < 0) 56274dcf55SMike Marshall goto out; 57274dcf55SMike Marshall 588bb8aefdSYi Liu inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, 59274dcf55SMike Marshall &new_op->downcall.resp.create.refn); 60274dcf55SMike Marshall if (IS_ERR(inode)) { 61f66debf1SAl Viro gossip_err("%s: Failed to allocate inode for file :%pd:\n", 625253487eSMike Marshall __func__, 63f66debf1SAl Viro dentry); 64274dcf55SMike Marshall ret = PTR_ERR(inode); 65274dcf55SMike Marshall goto out; 66274dcf55SMike Marshall } 67274dcf55SMike Marshall 68274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 69f66debf1SAl Viro "%s: Assigned inode :%pU: for file :%pd:\n", 705253487eSMike Marshall __func__, 715253487eSMike Marshall get_khandle_from_ino(inode), 72f66debf1SAl Viro dentry); 73274dcf55SMike Marshall 74274dcf55SMike Marshall d_instantiate(dentry, inode); 75274dcf55SMike Marshall unlock_new_inode(inode); 76804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 778bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 7868a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 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 85274dcf55SMike Marshall SetMtimeFlag(parent); 86c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 87274dcf55SMike Marshall mark_inode_dirty_sync(dir); 88274dcf55SMike Marshall ret = 0; 89274dcf55SMike Marshall out: 90274dcf55SMike Marshall op_release(new_op); 915253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 92f66debf1SAl Viro "%s: %pd: returning %d\n", 935253487eSMike Marshall __func__, 94f66debf1SAl Viro dentry, 955253487eSMike Marshall ret); 96274dcf55SMike Marshall return ret; 97274dcf55SMike Marshall } 98274dcf55SMike Marshall 99274dcf55SMike Marshall /* 100274dcf55SMike Marshall * Attempt to resolve an object name (dentry->d_name), parent handle, and 101274dcf55SMike Marshall * fsid into a handle for the object. 102274dcf55SMike Marshall */ 1038bb8aefdSYi Liu static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry, 104274dcf55SMike Marshall unsigned int flags) 105274dcf55SMike Marshall { 1068bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 1078bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 108274dcf55SMike Marshall struct inode *inode; 109274dcf55SMike Marshall struct dentry *res; 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, 14047b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 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 157274dcf55SMike Marshall if (ret < 0) { 158274dcf55SMike Marshall if (ret == -ENOENT) { 159274dcf55SMike Marshall /* 160274dcf55SMike Marshall * if no inode was found, add a negative dentry to 161274dcf55SMike Marshall * dcache anyway; if we don't, we don't hold expected 162274dcf55SMike Marshall * lookup semantics and we most noticeably break 163274dcf55SMike Marshall * during directory renames. 164274dcf55SMike Marshall * 165274dcf55SMike Marshall * however, if the operation failed or exited, do not 166274dcf55SMike Marshall * add the dentry (e.g. in the case that a touch is 167274dcf55SMike Marshall * issued on a file that already exists that was 168274dcf55SMike Marshall * interrupted during this lookup -- no need to add 169274dcf55SMike Marshall * another negative dentry for an existing file) 170274dcf55SMike Marshall */ 171274dcf55SMike Marshall 172274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 1738bb8aefdSYi Liu "orangefs_lookup: Adding *negative* dentry " 174f66debf1SAl Viro "%p for %pd\n", 175274dcf55SMike Marshall dentry, 176f66debf1SAl Viro dentry); 177274dcf55SMike Marshall 178274dcf55SMike Marshall d_add(dentry, NULL); 179274dcf55SMike Marshall res = NULL; 180274dcf55SMike Marshall goto out; 181274dcf55SMike Marshall } 182274dcf55SMike Marshall 183274dcf55SMike Marshall /* must be a non-recoverable error */ 184274dcf55SMike Marshall res = ERR_PTR(ret); 185274dcf55SMike Marshall goto out; 186274dcf55SMike Marshall } 187274dcf55SMike Marshall 188804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 18931b7c1abSMartin Brandenburg 1908bb8aefdSYi Liu inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn); 191274dcf55SMike Marshall if (IS_ERR(inode)) { 192274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 193274dcf55SMike Marshall "error %ld from iget\n", PTR_ERR(inode)); 194274dcf55SMike Marshall res = ERR_CAST(inode); 195274dcf55SMike Marshall goto out; 196274dcf55SMike Marshall } 197274dcf55SMike Marshall 198274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 199274dcf55SMike Marshall "%s:%s:%d " 200274dcf55SMike Marshall "Found good inode [%lu] with count [%d]\n", 201274dcf55SMike Marshall __FILE__, 202274dcf55SMike Marshall __func__, 203274dcf55SMike Marshall __LINE__, 204274dcf55SMike Marshall inode->i_ino, 205274dcf55SMike Marshall (int)atomic_read(&inode->i_count)); 206274dcf55SMike Marshall 207274dcf55SMike Marshall /* update dentry/inode pair into dcache */ 208274dcf55SMike Marshall res = d_splice_alias(inode, dentry); 209274dcf55SMike Marshall 210274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 211274dcf55SMike Marshall "Lookup success (inode ct = %d)\n", 212274dcf55SMike Marshall (int)atomic_read(&inode->i_count)); 213274dcf55SMike Marshall out: 214274dcf55SMike Marshall op_release(new_op); 215274dcf55SMike Marshall return res; 216274dcf55SMike Marshall } 217274dcf55SMike Marshall 218274dcf55SMike Marshall /* return 0 on success; non-zero otherwise */ 2198bb8aefdSYi Liu static int orangefs_unlink(struct inode *dir, struct dentry *dentry) 220274dcf55SMike Marshall { 221274dcf55SMike Marshall struct inode *inode = dentry->d_inode; 2228bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 2238bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 224274dcf55SMike Marshall int ret; 225274dcf55SMike Marshall 226274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 227f66debf1SAl Viro "%s: called on %pd\n" 228274dcf55SMike Marshall " (inode %pU): Parent is %pU | fs_id %d\n", 229274dcf55SMike Marshall __func__, 230f66debf1SAl Viro dentry, 231274dcf55SMike Marshall get_khandle_from_ino(inode), 232274dcf55SMike Marshall &parent->refn.khandle, 233274dcf55SMike Marshall parent->refn.fs_id); 234274dcf55SMike Marshall 2358bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE); 236274dcf55SMike Marshall if (!new_op) 237274dcf55SMike Marshall return -ENOMEM; 238274dcf55SMike Marshall 239274dcf55SMike Marshall new_op->upcall.req.remove.parent_refn = parent->refn; 240274dcf55SMike Marshall strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name, 24147b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 242274dcf55SMike Marshall 2438bb8aefdSYi Liu ret = service_operation(new_op, "orangefs_unlink", 244274dcf55SMike Marshall get_interruptible_flag(inode)); 245274dcf55SMike Marshall 2465253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 2475253487eSMike Marshall "%s: service_operation returned:%d:\n", 2485253487eSMike Marshall __func__, 2495253487eSMike Marshall ret); 2505253487eSMike Marshall 251274dcf55SMike Marshall op_release(new_op); 252274dcf55SMike Marshall 253274dcf55SMike Marshall if (!ret) { 254274dcf55SMike Marshall drop_nlink(inode); 255274dcf55SMike Marshall 256274dcf55SMike Marshall SetMtimeFlag(parent); 257c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 258274dcf55SMike Marshall mark_inode_dirty_sync(dir); 259274dcf55SMike Marshall } 260274dcf55SMike Marshall return ret; 261274dcf55SMike Marshall } 262274dcf55SMike Marshall 2638bb8aefdSYi Liu static int orangefs_symlink(struct inode *dir, 264274dcf55SMike Marshall struct dentry *dentry, 265274dcf55SMike Marshall const char *symname) 266274dcf55SMike Marshall { 2678bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 2688bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 269274dcf55SMike Marshall struct inode *inode; 270274dcf55SMike Marshall int mode = 755; 271274dcf55SMike Marshall int ret; 272274dcf55SMike Marshall 273274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__); 274274dcf55SMike Marshall 275274dcf55SMike Marshall if (!symname) 276274dcf55SMike Marshall return -EINVAL; 277274dcf55SMike Marshall 278c62da585SMartin Brandenburg if (strlen(symname)+1 > ORANGEFS_NAME_MAX) 279c62da585SMartin Brandenburg return -ENAMETOOLONG; 280c62da585SMartin Brandenburg 2818bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK); 282274dcf55SMike Marshall if (!new_op) 283274dcf55SMike Marshall return -ENOMEM; 284274dcf55SMike Marshall 285274dcf55SMike Marshall new_op->upcall.req.sym.parent_refn = parent->refn; 286274dcf55SMike Marshall 287274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.sym.attributes, 2888bb8aefdSYi Liu ORANGEFS_TYPE_SYMLINK, 289274dcf55SMike Marshall mode); 290274dcf55SMike Marshall 291274dcf55SMike Marshall strncpy(new_op->upcall.req.sym.entry_name, 292274dcf55SMike Marshall dentry->d_name.name, 29347b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 29447b4948fSMartin Brandenburg strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX); 295274dcf55SMike Marshall 296274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 297274dcf55SMike Marshall 298274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 2998bb8aefdSYi Liu "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n", 300274dcf55SMike Marshall &new_op->downcall.resp.sym.refn.khandle, 301274dcf55SMike Marshall new_op->downcall.resp.sym.refn.fs_id, ret); 302274dcf55SMike Marshall 303274dcf55SMike Marshall if (ret < 0) { 304274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 305274dcf55SMike Marshall "%s: failed with error code %d\n", 306274dcf55SMike Marshall __func__, ret); 307274dcf55SMike Marshall goto out; 308274dcf55SMike Marshall } 309274dcf55SMike Marshall 3108bb8aefdSYi Liu inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, 311274dcf55SMike Marshall &new_op->downcall.resp.sym.refn); 312274dcf55SMike Marshall if (IS_ERR(inode)) { 313274dcf55SMike Marshall gossip_err 3148bb8aefdSYi Liu ("*** Failed to allocate orangefs symlink inode\n"); 315274dcf55SMike Marshall ret = PTR_ERR(inode); 316274dcf55SMike Marshall goto out; 317274dcf55SMike Marshall } 318274dcf55SMike Marshall 319274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 320274dcf55SMike Marshall "Assigned symlink inode new number of %pU\n", 321274dcf55SMike Marshall get_khandle_from_ino(inode)); 322274dcf55SMike Marshall 323274dcf55SMike Marshall d_instantiate(dentry, inode); 324274dcf55SMike Marshall unlock_new_inode(inode); 325804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 3268bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 32768a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 328274dcf55SMike Marshall 329274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 330f66debf1SAl Viro "Inode (Symlink) %pU -> %pd\n", 331274dcf55SMike Marshall get_khandle_from_ino(inode), 332f66debf1SAl Viro dentry); 333274dcf55SMike Marshall 334274dcf55SMike Marshall SetMtimeFlag(parent); 335c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 336274dcf55SMike Marshall mark_inode_dirty_sync(dir); 337274dcf55SMike Marshall ret = 0; 338274dcf55SMike Marshall out: 339274dcf55SMike Marshall op_release(new_op); 340274dcf55SMike Marshall return ret; 341274dcf55SMike Marshall } 342274dcf55SMike Marshall 3438bb8aefdSYi Liu static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 344274dcf55SMike Marshall { 3458bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 3468bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 347274dcf55SMike Marshall struct inode *inode; 348274dcf55SMike Marshall int ret; 349274dcf55SMike Marshall 3508bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR); 351274dcf55SMike Marshall if (!new_op) 352274dcf55SMike Marshall return -ENOMEM; 353274dcf55SMike Marshall 354274dcf55SMike Marshall new_op->upcall.req.mkdir.parent_refn = parent->refn; 355274dcf55SMike Marshall 356274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes, 3578bb8aefdSYi Liu ORANGEFS_TYPE_DIRECTORY, mode); 358274dcf55SMike Marshall 359274dcf55SMike Marshall strncpy(new_op->upcall.req.mkdir.d_name, 36047b4948fSMartin Brandenburg dentry->d_name.name, ORANGEFS_NAME_MAX); 361274dcf55SMike Marshall 362274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 363274dcf55SMike Marshall 364274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 3658bb8aefdSYi Liu "Mkdir Got ORANGEFS handle %pU on fsid %d\n", 366274dcf55SMike Marshall &new_op->downcall.resp.mkdir.refn.khandle, 367274dcf55SMike Marshall new_op->downcall.resp.mkdir.refn.fs_id); 368274dcf55SMike Marshall 369274dcf55SMike Marshall if (ret < 0) { 370274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 371274dcf55SMike Marshall "%s: failed with error code %d\n", 372274dcf55SMike Marshall __func__, ret); 373274dcf55SMike Marshall goto out; 374274dcf55SMike Marshall } 375274dcf55SMike Marshall 3768bb8aefdSYi Liu inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, 377274dcf55SMike Marshall &new_op->downcall.resp.mkdir.refn); 378274dcf55SMike Marshall if (IS_ERR(inode)) { 3798bb8aefdSYi Liu gossip_err("*** Failed to allocate orangefs dir inode\n"); 380274dcf55SMike Marshall ret = PTR_ERR(inode); 381274dcf55SMike Marshall goto out; 382274dcf55SMike Marshall } 383274dcf55SMike Marshall 384274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 385274dcf55SMike Marshall "Assigned dir inode new number of %pU\n", 386274dcf55SMike Marshall get_khandle_from_ino(inode)); 387274dcf55SMike Marshall 388274dcf55SMike Marshall d_instantiate(dentry, inode); 389274dcf55SMike Marshall unlock_new_inode(inode); 390804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 3918bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 39268a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 393274dcf55SMike Marshall 394274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 395f66debf1SAl Viro "Inode (Directory) %pU -> %pd\n", 396274dcf55SMike Marshall get_khandle_from_ino(inode), 397f66debf1SAl Viro dentry); 398274dcf55SMike Marshall 399274dcf55SMike Marshall /* 400274dcf55SMike Marshall * NOTE: we have no good way to keep nlink consistent for directories 401274dcf55SMike Marshall * across clients; keep constant at 1. 402274dcf55SMike Marshall */ 403274dcf55SMike Marshall SetMtimeFlag(parent); 404c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 405274dcf55SMike Marshall mark_inode_dirty_sync(dir); 406274dcf55SMike Marshall out: 407274dcf55SMike Marshall op_release(new_op); 408274dcf55SMike Marshall return ret; 409274dcf55SMike Marshall } 410274dcf55SMike Marshall 4118bb8aefdSYi Liu static int orangefs_rename(struct inode *old_dir, 412274dcf55SMike Marshall struct dentry *old_dentry, 413274dcf55SMike Marshall struct inode *new_dir, 4141cd66c93SMiklos Szeredi struct dentry *new_dentry, 4151cd66c93SMiklos Szeredi unsigned int flags) 416274dcf55SMike Marshall { 4178bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 418274dcf55SMike Marshall int ret; 419274dcf55SMike Marshall 4201cd66c93SMiklos Szeredi if (flags) 4211cd66c93SMiklos Szeredi return -EINVAL; 4221cd66c93SMiklos Szeredi 423274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 42496b0cffbSAl Viro "orangefs_rename: called (%pd2 => %pd2) ct=%d\n", 42596b0cffbSAl Viro old_dentry, new_dentry, d_count(new_dentry)); 426274dcf55SMike Marshall 4278bbb20a8SMartin Brandenburg ORANGEFS_I(new_dentry->d_parent->d_inode)->getattr_time = jiffies - 1; 42871680c18SMartin Brandenburg 4298bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_RENAME); 430274dcf55SMike Marshall if (!new_op) 431274dcf55SMike Marshall return -EINVAL; 432274dcf55SMike Marshall 4338bb8aefdSYi Liu new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn; 4348bb8aefdSYi Liu new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn; 435274dcf55SMike Marshall 436274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_old_name, 437274dcf55SMike Marshall old_dentry->d_name.name, 43847b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 439274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_new_name, 440274dcf55SMike Marshall new_dentry->d_name.name, 44147b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 442274dcf55SMike Marshall 443274dcf55SMike Marshall ret = service_operation(new_op, 4448bb8aefdSYi Liu "orangefs_rename", 445274dcf55SMike Marshall get_interruptible_flag(old_dentry->d_inode)); 446274dcf55SMike Marshall 447274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 4488bb8aefdSYi Liu "orangefs_rename: got downcall status %d\n", 449274dcf55SMike Marshall ret); 450274dcf55SMike Marshall 451274dcf55SMike Marshall if (new_dentry->d_inode) 452c2050a45SDeepa Dinamani new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode); 453274dcf55SMike Marshall 454274dcf55SMike Marshall op_release(new_op); 455274dcf55SMike Marshall return ret; 456274dcf55SMike Marshall } 457274dcf55SMike Marshall 4588bb8aefdSYi Liu /* ORANGEFS implementation of VFS inode operations for directories */ 4596f3fc107SAl Viro const struct inode_operations orangefs_dir_inode_operations = { 4608bb8aefdSYi Liu .lookup = orangefs_lookup, 4618bb8aefdSYi Liu .get_acl = orangefs_get_acl, 4628bb8aefdSYi Liu .set_acl = orangefs_set_acl, 4638bb8aefdSYi Liu .create = orangefs_create, 4648bb8aefdSYi Liu .unlink = orangefs_unlink, 4658bb8aefdSYi Liu .symlink = orangefs_symlink, 4668bb8aefdSYi Liu .mkdir = orangefs_mkdir, 4678bb8aefdSYi Liu .rmdir = orangefs_unlink, 4688bb8aefdSYi Liu .rename = orangefs_rename, 4698bb8aefdSYi Liu .setattr = orangefs_setattr, 4708bb8aefdSYi Liu .getattr = orangefs_getattr, 4718bb8aefdSYi Liu .listxattr = orangefs_listxattr, 472933287daSMartin Brandenburg .permission = orangefs_permission, 473274dcf55SMike Marshall }; 474