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; 25274dcf55SMike Marshall struct inode *inode; 26*a55f2d86SMartin Brandenburg struct iattr iattr; 27274dcf55SMike Marshall int ret; 28274dcf55SMike Marshall 29f66debf1SAl Viro gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd\n", 305253487eSMike Marshall __func__, 31f66debf1SAl Viro dentry); 32274dcf55SMike Marshall 338bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_CREATE); 34274dcf55SMike Marshall if (!new_op) 35274dcf55SMike Marshall return -ENOMEM; 36274dcf55SMike Marshall 37274dcf55SMike Marshall new_op->upcall.req.create.parent_refn = parent->refn; 38274dcf55SMike Marshall 39274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.create.attributes, 408bb8aefdSYi Liu ORANGEFS_TYPE_METAFILE, mode); 41274dcf55SMike Marshall 42274dcf55SMike Marshall strncpy(new_op->upcall.req.create.d_name, 4347b4948fSMartin Brandenburg dentry->d_name.name, ORANGEFS_NAME_MAX); 44274dcf55SMike Marshall 45274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 46274dcf55SMike Marshall 47274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 48f66debf1SAl Viro "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n", 495253487eSMike Marshall __func__, 50f66debf1SAl Viro dentry, 51274dcf55SMike Marshall &new_op->downcall.resp.create.refn.khandle, 525253487eSMike Marshall new_op->downcall.resp.create.refn.fs_id, 535253487eSMike Marshall new_op, 545253487eSMike Marshall ret); 55274dcf55SMike Marshall 565253487eSMike Marshall if (ret < 0) 57274dcf55SMike Marshall goto out; 58274dcf55SMike Marshall 598bb8aefdSYi Liu inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, 60274dcf55SMike Marshall &new_op->downcall.resp.create.refn); 61274dcf55SMike Marshall if (IS_ERR(inode)) { 62f66debf1SAl Viro gossip_err("%s: Failed to allocate inode for file :%pd:\n", 635253487eSMike Marshall __func__, 64f66debf1SAl Viro dentry); 65274dcf55SMike Marshall ret = PTR_ERR(inode); 66274dcf55SMike Marshall goto out; 67274dcf55SMike Marshall } 68274dcf55SMike Marshall 69274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 70f66debf1SAl Viro "%s: Assigned inode :%pU: for file :%pd:\n", 715253487eSMike Marshall __func__, 725253487eSMike Marshall get_khandle_from_ino(inode), 73f66debf1SAl Viro dentry); 74274dcf55SMike Marshall 75274dcf55SMike Marshall d_instantiate(dentry, inode); 76274dcf55SMike Marshall unlock_new_inode(inode); 77804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 788bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 7968a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 80274dcf55SMike Marshall 81274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 82f66debf1SAl Viro "%s: dentry instantiated for %pd\n", 835253487eSMike Marshall __func__, 84f66debf1SAl Viro dentry); 85274dcf55SMike Marshall 86c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 87*a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 88*a55f2d86SMartin Brandenburg iattr.ia_valid |= ATTR_MTIME; 89*a55f2d86SMartin Brandenburg orangefs_inode_setattr(dir, &iattr); 90274dcf55SMike Marshall mark_inode_dirty_sync(dir); 91274dcf55SMike Marshall ret = 0; 92274dcf55SMike Marshall out: 93274dcf55SMike Marshall op_release(new_op); 945253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 95f66debf1SAl Viro "%s: %pd: returning %d\n", 965253487eSMike Marshall __func__, 97f66debf1SAl Viro dentry, 985253487eSMike Marshall ret); 99274dcf55SMike Marshall return ret; 100274dcf55SMike Marshall } 101274dcf55SMike Marshall 102274dcf55SMike Marshall /* 103274dcf55SMike Marshall * Attempt to resolve an object name (dentry->d_name), parent handle, and 104274dcf55SMike Marshall * fsid into a handle for the object. 105274dcf55SMike Marshall */ 1068bb8aefdSYi Liu static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry, 107274dcf55SMike Marshall unsigned int flags) 108274dcf55SMike Marshall { 1098bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 1108bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 111274dcf55SMike Marshall struct inode *inode; 112274dcf55SMike Marshall struct dentry *res; 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, 14347b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 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 160274dcf55SMike Marshall if (ret < 0) { 161274dcf55SMike Marshall if (ret == -ENOENT) { 162274dcf55SMike Marshall /* 163274dcf55SMike Marshall * if no inode was found, add a negative dentry to 164274dcf55SMike Marshall * dcache anyway; if we don't, we don't hold expected 165274dcf55SMike Marshall * lookup semantics and we most noticeably break 166274dcf55SMike Marshall * during directory renames. 167274dcf55SMike Marshall * 168274dcf55SMike Marshall * however, if the operation failed or exited, do not 169274dcf55SMike Marshall * add the dentry (e.g. in the case that a touch is 170274dcf55SMike Marshall * issued on a file that already exists that was 171274dcf55SMike Marshall * interrupted during this lookup -- no need to add 172274dcf55SMike Marshall * another negative dentry for an existing file) 173274dcf55SMike Marshall */ 174274dcf55SMike Marshall 175274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 1768bb8aefdSYi Liu "orangefs_lookup: Adding *negative* dentry " 177f66debf1SAl Viro "%p for %pd\n", 178274dcf55SMike Marshall dentry, 179f66debf1SAl Viro dentry); 180274dcf55SMike Marshall 181274dcf55SMike Marshall d_add(dentry, NULL); 182274dcf55SMike Marshall res = NULL; 183274dcf55SMike Marshall goto out; 184274dcf55SMike Marshall } 185274dcf55SMike Marshall 186274dcf55SMike Marshall /* must be a non-recoverable error */ 187274dcf55SMike Marshall res = ERR_PTR(ret); 188274dcf55SMike Marshall goto out; 189274dcf55SMike Marshall } 190274dcf55SMike Marshall 191804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 19231b7c1abSMartin Brandenburg 1938bb8aefdSYi Liu inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn); 194274dcf55SMike Marshall if (IS_ERR(inode)) { 195274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 196274dcf55SMike Marshall "error %ld from iget\n", PTR_ERR(inode)); 197274dcf55SMike Marshall res = ERR_CAST(inode); 198274dcf55SMike Marshall goto out; 199274dcf55SMike Marshall } 200274dcf55SMike Marshall 201274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 202274dcf55SMike Marshall "%s:%s:%d " 203274dcf55SMike Marshall "Found good inode [%lu] with count [%d]\n", 204274dcf55SMike Marshall __FILE__, 205274dcf55SMike Marshall __func__, 206274dcf55SMike Marshall __LINE__, 207274dcf55SMike Marshall inode->i_ino, 208274dcf55SMike Marshall (int)atomic_read(&inode->i_count)); 209274dcf55SMike Marshall 210274dcf55SMike Marshall /* update dentry/inode pair into dcache */ 211274dcf55SMike Marshall res = d_splice_alias(inode, dentry); 212274dcf55SMike Marshall 213274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 214274dcf55SMike Marshall "Lookup success (inode ct = %d)\n", 215274dcf55SMike Marshall (int)atomic_read(&inode->i_count)); 216274dcf55SMike Marshall out: 217274dcf55SMike Marshall op_release(new_op); 218274dcf55SMike Marshall return res; 219274dcf55SMike Marshall } 220274dcf55SMike Marshall 221274dcf55SMike Marshall /* return 0 on success; non-zero otherwise */ 2228bb8aefdSYi Liu static int orangefs_unlink(struct inode *dir, struct dentry *dentry) 223274dcf55SMike Marshall { 224274dcf55SMike Marshall struct inode *inode = dentry->d_inode; 2258bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 2268bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 227*a55f2d86SMartin Brandenburg struct iattr iattr; 228274dcf55SMike Marshall int ret; 229274dcf55SMike Marshall 230274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 231f66debf1SAl Viro "%s: called on %pd\n" 232274dcf55SMike Marshall " (inode %pU): Parent is %pU | fs_id %d\n", 233274dcf55SMike Marshall __func__, 234f66debf1SAl Viro dentry, 235274dcf55SMike Marshall get_khandle_from_ino(inode), 236274dcf55SMike Marshall &parent->refn.khandle, 237274dcf55SMike Marshall parent->refn.fs_id); 238274dcf55SMike Marshall 2398bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE); 240274dcf55SMike Marshall if (!new_op) 241274dcf55SMike Marshall return -ENOMEM; 242274dcf55SMike Marshall 243274dcf55SMike Marshall new_op->upcall.req.remove.parent_refn = parent->refn; 244274dcf55SMike Marshall strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name, 24547b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 246274dcf55SMike Marshall 2478bb8aefdSYi Liu ret = service_operation(new_op, "orangefs_unlink", 248274dcf55SMike Marshall get_interruptible_flag(inode)); 249274dcf55SMike Marshall 2505253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 2515253487eSMike Marshall "%s: service_operation returned:%d:\n", 2525253487eSMike Marshall __func__, 2535253487eSMike Marshall ret); 2545253487eSMike Marshall 255274dcf55SMike Marshall op_release(new_op); 256274dcf55SMike Marshall 257274dcf55SMike Marshall if (!ret) { 258274dcf55SMike Marshall drop_nlink(inode); 259274dcf55SMike Marshall 260c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 261*a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 262*a55f2d86SMartin Brandenburg iattr.ia_valid |= ATTR_MTIME; 263*a55f2d86SMartin Brandenburg orangefs_inode_setattr(dir, &iattr); 264274dcf55SMike Marshall mark_inode_dirty_sync(dir); 265274dcf55SMike Marshall } 266274dcf55SMike Marshall return ret; 267274dcf55SMike Marshall } 268274dcf55SMike Marshall 2698bb8aefdSYi Liu static int orangefs_symlink(struct inode *dir, 270274dcf55SMike Marshall struct dentry *dentry, 271274dcf55SMike Marshall const char *symname) 272274dcf55SMike Marshall { 2738bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 2748bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 275274dcf55SMike Marshall struct inode *inode; 276*a55f2d86SMartin Brandenburg struct iattr iattr; 277274dcf55SMike Marshall int mode = 755; 278274dcf55SMike Marshall int ret; 279274dcf55SMike Marshall 280274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__); 281274dcf55SMike Marshall 282274dcf55SMike Marshall if (!symname) 283274dcf55SMike Marshall return -EINVAL; 284274dcf55SMike Marshall 285c62da585SMartin Brandenburg if (strlen(symname)+1 > ORANGEFS_NAME_MAX) 286c62da585SMartin Brandenburg return -ENAMETOOLONG; 287c62da585SMartin Brandenburg 2888bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK); 289274dcf55SMike Marshall if (!new_op) 290274dcf55SMike Marshall return -ENOMEM; 291274dcf55SMike Marshall 292274dcf55SMike Marshall new_op->upcall.req.sym.parent_refn = parent->refn; 293274dcf55SMike Marshall 294274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.sym.attributes, 2958bb8aefdSYi Liu ORANGEFS_TYPE_SYMLINK, 296274dcf55SMike Marshall mode); 297274dcf55SMike Marshall 298274dcf55SMike Marshall strncpy(new_op->upcall.req.sym.entry_name, 299274dcf55SMike Marshall dentry->d_name.name, 30047b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 30147b4948fSMartin Brandenburg strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX); 302274dcf55SMike Marshall 303274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 304274dcf55SMike Marshall 305274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 3068bb8aefdSYi Liu "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n", 307274dcf55SMike Marshall &new_op->downcall.resp.sym.refn.khandle, 308274dcf55SMike Marshall new_op->downcall.resp.sym.refn.fs_id, ret); 309274dcf55SMike Marshall 310274dcf55SMike Marshall if (ret < 0) { 311274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 312274dcf55SMike Marshall "%s: failed with error code %d\n", 313274dcf55SMike Marshall __func__, ret); 314274dcf55SMike Marshall goto out; 315274dcf55SMike Marshall } 316274dcf55SMike Marshall 3178bb8aefdSYi Liu inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, 318274dcf55SMike Marshall &new_op->downcall.resp.sym.refn); 319274dcf55SMike Marshall if (IS_ERR(inode)) { 320274dcf55SMike Marshall gossip_err 3218bb8aefdSYi Liu ("*** Failed to allocate orangefs symlink inode\n"); 322274dcf55SMike Marshall ret = PTR_ERR(inode); 323274dcf55SMike Marshall goto out; 324274dcf55SMike Marshall } 325274dcf55SMike Marshall 326274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 327274dcf55SMike Marshall "Assigned symlink inode new number of %pU\n", 328274dcf55SMike Marshall get_khandle_from_ino(inode)); 329274dcf55SMike Marshall 330274dcf55SMike Marshall d_instantiate(dentry, inode); 331274dcf55SMike Marshall unlock_new_inode(inode); 332804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 3338bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 33468a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 335274dcf55SMike Marshall 336274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 337f66debf1SAl Viro "Inode (Symlink) %pU -> %pd\n", 338274dcf55SMike Marshall get_khandle_from_ino(inode), 339f66debf1SAl Viro dentry); 340274dcf55SMike Marshall 341c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 342*a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 343*a55f2d86SMartin Brandenburg iattr.ia_valid |= ATTR_MTIME; 344*a55f2d86SMartin Brandenburg orangefs_inode_setattr(dir, &iattr); 345274dcf55SMike Marshall mark_inode_dirty_sync(dir); 346274dcf55SMike Marshall ret = 0; 347274dcf55SMike Marshall out: 348274dcf55SMike Marshall op_release(new_op); 349274dcf55SMike Marshall return ret; 350274dcf55SMike Marshall } 351274dcf55SMike Marshall 3528bb8aefdSYi Liu static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) 353274dcf55SMike Marshall { 3548bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir); 3558bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 356274dcf55SMike Marshall struct inode *inode; 357*a55f2d86SMartin Brandenburg struct iattr iattr; 358274dcf55SMike Marshall int ret; 359274dcf55SMike Marshall 3608bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR); 361274dcf55SMike Marshall if (!new_op) 362274dcf55SMike Marshall return -ENOMEM; 363274dcf55SMike Marshall 364274dcf55SMike Marshall new_op->upcall.req.mkdir.parent_refn = parent->refn; 365274dcf55SMike Marshall 366274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes, 3678bb8aefdSYi Liu ORANGEFS_TYPE_DIRECTORY, mode); 368274dcf55SMike Marshall 369274dcf55SMike Marshall strncpy(new_op->upcall.req.mkdir.d_name, 37047b4948fSMartin Brandenburg dentry->d_name.name, ORANGEFS_NAME_MAX); 371274dcf55SMike Marshall 372274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); 373274dcf55SMike Marshall 374274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 3758bb8aefdSYi Liu "Mkdir Got ORANGEFS handle %pU on fsid %d\n", 376274dcf55SMike Marshall &new_op->downcall.resp.mkdir.refn.khandle, 377274dcf55SMike Marshall new_op->downcall.resp.mkdir.refn.fs_id); 378274dcf55SMike Marshall 379274dcf55SMike Marshall if (ret < 0) { 380274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 381274dcf55SMike Marshall "%s: failed with error code %d\n", 382274dcf55SMike Marshall __func__, ret); 383274dcf55SMike Marshall goto out; 384274dcf55SMike Marshall } 385274dcf55SMike Marshall 3868bb8aefdSYi Liu inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, 387274dcf55SMike Marshall &new_op->downcall.resp.mkdir.refn); 388274dcf55SMike Marshall if (IS_ERR(inode)) { 3898bb8aefdSYi Liu gossip_err("*** Failed to allocate orangefs dir inode\n"); 390274dcf55SMike Marshall ret = PTR_ERR(inode); 391274dcf55SMike Marshall goto out; 392274dcf55SMike Marshall } 393274dcf55SMike Marshall 394274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 395274dcf55SMike Marshall "Assigned dir inode new number of %pU\n", 396274dcf55SMike Marshall get_khandle_from_ino(inode)); 397274dcf55SMike Marshall 398274dcf55SMike Marshall d_instantiate(dentry, inode); 399274dcf55SMike Marshall unlock_new_inode(inode); 400804b1737SMiklos Szeredi orangefs_set_timeout(dentry); 4018bbb20a8SMartin Brandenburg ORANGEFS_I(inode)->getattr_time = jiffies - 1; 40268a24a6cSMartin Brandenburg ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; 403274dcf55SMike Marshall 404274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 405f66debf1SAl Viro "Inode (Directory) %pU -> %pd\n", 406274dcf55SMike Marshall get_khandle_from_ino(inode), 407f66debf1SAl Viro dentry); 408274dcf55SMike Marshall 409274dcf55SMike Marshall /* 410274dcf55SMike Marshall * NOTE: we have no good way to keep nlink consistent for directories 411274dcf55SMike Marshall * across clients; keep constant at 1. 412274dcf55SMike Marshall */ 413c2050a45SDeepa Dinamani dir->i_mtime = dir->i_ctime = current_time(dir); 414*a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr); 415*a55f2d86SMartin Brandenburg iattr.ia_valid |= ATTR_MTIME; 416*a55f2d86SMartin Brandenburg orangefs_inode_setattr(dir, &iattr); 417274dcf55SMike Marshall mark_inode_dirty_sync(dir); 418274dcf55SMike Marshall out: 419274dcf55SMike Marshall op_release(new_op); 420274dcf55SMike Marshall return ret; 421274dcf55SMike Marshall } 422274dcf55SMike Marshall 4238bb8aefdSYi Liu static int orangefs_rename(struct inode *old_dir, 424274dcf55SMike Marshall struct dentry *old_dentry, 425274dcf55SMike Marshall struct inode *new_dir, 4261cd66c93SMiklos Szeredi struct dentry *new_dentry, 4271cd66c93SMiklos Szeredi unsigned int flags) 428274dcf55SMike Marshall { 4298bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op; 430274dcf55SMike Marshall int ret; 431274dcf55SMike Marshall 4321cd66c93SMiklos Szeredi if (flags) 4331cd66c93SMiklos Szeredi return -EINVAL; 4341cd66c93SMiklos Szeredi 435274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 43696b0cffbSAl Viro "orangefs_rename: called (%pd2 => %pd2) ct=%d\n", 43796b0cffbSAl Viro old_dentry, new_dentry, d_count(new_dentry)); 438274dcf55SMike Marshall 4398bbb20a8SMartin Brandenburg ORANGEFS_I(new_dentry->d_parent->d_inode)->getattr_time = jiffies - 1; 44071680c18SMartin Brandenburg 4418bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_RENAME); 442274dcf55SMike Marshall if (!new_op) 443274dcf55SMike Marshall return -EINVAL; 444274dcf55SMike Marshall 4458bb8aefdSYi Liu new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn; 4468bb8aefdSYi Liu new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn; 447274dcf55SMike Marshall 448274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_old_name, 449274dcf55SMike Marshall old_dentry->d_name.name, 45047b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 451274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_new_name, 452274dcf55SMike Marshall new_dentry->d_name.name, 45347b4948fSMartin Brandenburg ORANGEFS_NAME_MAX); 454274dcf55SMike Marshall 455274dcf55SMike Marshall ret = service_operation(new_op, 4568bb8aefdSYi Liu "orangefs_rename", 457274dcf55SMike Marshall get_interruptible_flag(old_dentry->d_inode)); 458274dcf55SMike Marshall 459274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, 4608bb8aefdSYi Liu "orangefs_rename: got downcall status %d\n", 461274dcf55SMike Marshall ret); 462274dcf55SMike Marshall 463274dcf55SMike Marshall if (new_dentry->d_inode) 464c2050a45SDeepa Dinamani new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode); 465274dcf55SMike Marshall 466274dcf55SMike Marshall op_release(new_op); 467274dcf55SMike Marshall return ret; 468274dcf55SMike Marshall } 469274dcf55SMike Marshall 4708bb8aefdSYi Liu /* ORANGEFS implementation of VFS inode operations for directories */ 4716f3fc107SAl Viro const struct inode_operations orangefs_dir_inode_operations = { 4728bb8aefdSYi Liu .lookup = orangefs_lookup, 4738bb8aefdSYi Liu .get_acl = orangefs_get_acl, 4748bb8aefdSYi Liu .set_acl = orangefs_set_acl, 4758bb8aefdSYi Liu .create = orangefs_create, 4768bb8aefdSYi Liu .unlink = orangefs_unlink, 4778bb8aefdSYi Liu .symlink = orangefs_symlink, 4788bb8aefdSYi Liu .mkdir = orangefs_mkdir, 4798bb8aefdSYi Liu .rmdir = orangefs_unlink, 4808bb8aefdSYi Liu .rename = orangefs_rename, 4818bb8aefdSYi Liu .setattr = orangefs_setattr, 4828bb8aefdSYi Liu .getattr = orangefs_getattr, 4838bb8aefdSYi Liu .listxattr = orangefs_listxattr, 484933287daSMartin Brandenburg .permission = orangefs_permission, 485*a55f2d86SMartin Brandenburg .update_time = orangefs_update_time, 486274dcf55SMike Marshall }; 487