Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 2 | /* |
| 3 | * (C) 2001 Clemson University and The University of Chicago |
| 4 | * |
| 5 | * See COPYING in top-level directory. |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Linux VFS namei operations. |
| 10 | */ |
| 11 | |
| 12 | #include "protocol.h" |
Mike Marshall | 575e946 | 2015-12-04 12:56:14 -0500 | [diff] [blame] | 13 | #include "orangefs-kernel.h" |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 14 | |
| 15 | /* |
| 16 | * Get a newly allocated inode to go with a negative dentry. |
| 17 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 18 | static int orangefs_create(struct inode *dir, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 19 | struct dentry *dentry, |
| 20 | umode_t mode, |
| 21 | bool exclusive) |
| 22 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 23 | struct orangefs_inode_s *parent = ORANGEFS_I(dir); |
| 24 | struct orangefs_kernel_op_s *new_op; |
Martin Brandenburg | db0267e | 2017-11-10 12:08:01 -0500 | [diff] [blame] | 25 | struct orangefs_object_kref ref; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 26 | struct inode *inode; |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 27 | struct iattr iattr; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 28 | int ret; |
| 29 | |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 30 | gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd\n", |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 31 | __func__, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 32 | dentry); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 33 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 34 | new_op = op_alloc(ORANGEFS_VFS_OP_CREATE); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 35 | if (!new_op) |
| 36 | return -ENOMEM; |
| 37 | |
| 38 | new_op->upcall.req.create.parent_refn = parent->refn; |
| 39 | |
| 40 | fill_default_sys_attrs(new_op->upcall.req.create.attributes, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 41 | ORANGEFS_TYPE_METAFILE, mode); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 42 | |
| 43 | strncpy(new_op->upcall.req.create.d_name, |
Xiongfeng Wang | 6bdfb48 | 2018-01-08 20:22:33 +0800 | [diff] [blame] | 44 | dentry->d_name.name, ORANGEFS_NAME_MAX - 1); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 45 | |
| 46 | ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); |
| 47 | |
| 48 | gossip_debug(GOSSIP_NAME_DEBUG, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 49 | "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n", |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 50 | __func__, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 51 | dentry, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 52 | &new_op->downcall.resp.create.refn.khandle, |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 53 | new_op->downcall.resp.create.refn.fs_id, |
| 54 | new_op, |
| 55 | ret); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 56 | |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 57 | if (ret < 0) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 58 | goto out; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 59 | |
Martin Brandenburg | db0267e | 2017-11-10 12:08:01 -0500 | [diff] [blame] | 60 | ref = new_op->downcall.resp.create.refn; |
| 61 | op_release(new_op); |
| 62 | |
| 63 | inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, &ref); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 64 | if (IS_ERR(inode)) { |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 65 | gossip_err("%s: Failed to allocate inode for file :%pd:\n", |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 66 | __func__, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 67 | dentry); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 68 | ret = PTR_ERR(inode); |
| 69 | goto out; |
| 70 | } |
| 71 | |
| 72 | gossip_debug(GOSSIP_NAME_DEBUG, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 73 | "%s: Assigned inode :%pU: for file :%pd:\n", |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 74 | __func__, |
| 75 | get_khandle_from_ino(inode), |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 76 | dentry); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 77 | |
Al Viro | 1e2e547 | 2018-05-04 08:23:01 -0400 | [diff] [blame] | 78 | d_instantiate_new(dentry, inode); |
Miklos Szeredi | 804b173 | 2016-10-17 10:14:23 +0200 | [diff] [blame] | 79 | orangefs_set_timeout(dentry); |
Martin Brandenburg | 8bbb20a | 2016-07-28 14:46:36 -0400 | [diff] [blame] | 80 | ORANGEFS_I(inode)->getattr_time = jiffies - 1; |
Martin Brandenburg | 68a24a6 | 2017-04-25 15:38:03 -0400 | [diff] [blame] | 81 | ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 82 | |
| 83 | gossip_debug(GOSSIP_NAME_DEBUG, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 84 | "%s: dentry instantiated for %pd\n", |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 85 | __func__, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 86 | dentry); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 87 | |
Deepa Dinamani | c2050a4 | 2016-09-14 07:48:06 -0700 | [diff] [blame] | 88 | dir->i_mtime = dir->i_ctime = current_time(dir); |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 89 | memset(&iattr, 0, sizeof iattr); |
| 90 | iattr.ia_valid |= ATTR_MTIME; |
| 91 | orangefs_inode_setattr(dir, &iattr); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 92 | mark_inode_dirty_sync(dir); |
| 93 | ret = 0; |
| 94 | out: |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 95 | gossip_debug(GOSSIP_NAME_DEBUG, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 96 | "%s: %pd: returning %d\n", |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 97 | __func__, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 98 | dentry, |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 99 | ret); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 100 | return ret; |
| 101 | } |
| 102 | |
| 103 | /* |
| 104 | * Attempt to resolve an object name (dentry->d_name), parent handle, and |
| 105 | * fsid into a handle for the object. |
| 106 | */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 107 | static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 108 | unsigned int flags) |
| 109 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 110 | struct orangefs_inode_s *parent = ORANGEFS_I(dir); |
| 111 | struct orangefs_kernel_op_s *new_op; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 112 | struct inode *inode; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 113 | int ret = -EINVAL; |
| 114 | |
| 115 | /* |
| 116 | * in theory we could skip a lookup here (if the intent is to |
| 117 | * create) in order to avoid a potentially failed lookup, but |
| 118 | * leaving it in can skip a valid lookup and try to create a file |
| 119 | * that already exists (e.g. the vfs already handles checking for |
| 120 | * -EEXIST on O_EXCL opens, which is broken if we skip this lookup |
| 121 | * in the create path) |
| 122 | */ |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 123 | gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n", |
| 124 | __func__, dentry); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 125 | |
Martin Brandenburg | 47b4948 | 2016-02-20 14:22:40 -0500 | [diff] [blame] | 126 | if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1)) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 127 | return ERR_PTR(-ENAMETOOLONG); |
| 128 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 129 | new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 130 | if (!new_op) |
| 131 | return ERR_PTR(-ENOMEM); |
| 132 | |
Mike Marshall | 7cec28e | 2015-12-11 10:46:22 -0500 | [diff] [blame] | 133 | new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 134 | |
| 135 | gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n", |
| 136 | __FILE__, |
| 137 | __func__, |
| 138 | __LINE__, |
| 139 | &parent->refn.khandle); |
| 140 | new_op->upcall.req.lookup.parent_refn = parent->refn; |
| 141 | |
| 142 | strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name, |
Xiongfeng Wang | 6bdfb48 | 2018-01-08 20:22:33 +0800 | [diff] [blame] | 143 | ORANGEFS_NAME_MAX - 1); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 144 | |
| 145 | gossip_debug(GOSSIP_NAME_DEBUG, |
Martin Brandenburg | 6ceaf78 | 2016-02-20 14:47:13 -0500 | [diff] [blame] | 146 | "%s: doing lookup on %s under %pU,%d\n", |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 147 | __func__, |
| 148 | new_op->upcall.req.lookup.d_name, |
| 149 | &new_op->upcall.req.lookup.parent_refn.khandle, |
Martin Brandenburg | 6ceaf78 | 2016-02-20 14:47:13 -0500 | [diff] [blame] | 150 | new_op->upcall.req.lookup.parent_refn.fs_id); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 151 | |
| 152 | ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); |
| 153 | |
| 154 | gossip_debug(GOSSIP_NAME_DEBUG, |
| 155 | "Lookup Got %pU, fsid %d (ret=%d)\n", |
| 156 | &new_op->downcall.resp.lookup.refn.khandle, |
| 157 | new_op->downcall.resp.lookup.refn.fs_id, |
| 158 | ret); |
| 159 | |
Al Viro | 04bb1ba | 2018-04-30 23:12:03 -0400 | [diff] [blame] | 160 | if (ret >= 0) { |
| 161 | orangefs_set_timeout(dentry); |
| 162 | inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn); |
| 163 | } else if (ret == -ENOENT) { |
| 164 | inode = NULL; |
| 165 | } else { |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 166 | /* must be a non-recoverable error */ |
Al Viro | 04bb1ba | 2018-04-30 23:12:03 -0400 | [diff] [blame] | 167 | inode = ERR_PTR(ret); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 168 | } |
| 169 | |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 170 | op_release(new_op); |
Al Viro | 04bb1ba | 2018-04-30 23:12:03 -0400 | [diff] [blame] | 171 | return d_splice_alias(inode, dentry); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | /* return 0 on success; non-zero otherwise */ |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 175 | static int orangefs_unlink(struct inode *dir, struct dentry *dentry) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 176 | { |
| 177 | struct inode *inode = dentry->d_inode; |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 178 | struct orangefs_inode_s *parent = ORANGEFS_I(dir); |
| 179 | struct orangefs_kernel_op_s *new_op; |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 180 | struct iattr iattr; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 181 | int ret; |
| 182 | |
| 183 | gossip_debug(GOSSIP_NAME_DEBUG, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 184 | "%s: called on %pd\n" |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 185 | " (inode %pU): Parent is %pU | fs_id %d\n", |
| 186 | __func__, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 187 | dentry, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 188 | get_khandle_from_ino(inode), |
| 189 | &parent->refn.khandle, |
| 190 | parent->refn.fs_id); |
| 191 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 192 | new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 193 | if (!new_op) |
| 194 | return -ENOMEM; |
| 195 | |
| 196 | new_op->upcall.req.remove.parent_refn = parent->refn; |
| 197 | strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name, |
Xiongfeng Wang | 6bdfb48 | 2018-01-08 20:22:33 +0800 | [diff] [blame] | 198 | ORANGEFS_NAME_MAX - 1); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 199 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 200 | ret = service_operation(new_op, "orangefs_unlink", |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 201 | get_interruptible_flag(inode)); |
| 202 | |
Mike Marshall | 5253487 | 2016-02-16 17:09:09 -0500 | [diff] [blame] | 203 | gossip_debug(GOSSIP_NAME_DEBUG, |
| 204 | "%s: service_operation returned:%d:\n", |
| 205 | __func__, |
| 206 | ret); |
| 207 | |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 208 | op_release(new_op); |
| 209 | |
| 210 | if (!ret) { |
| 211 | drop_nlink(inode); |
| 212 | |
Deepa Dinamani | c2050a4 | 2016-09-14 07:48:06 -0700 | [diff] [blame] | 213 | dir->i_mtime = dir->i_ctime = current_time(dir); |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 214 | memset(&iattr, 0, sizeof iattr); |
| 215 | iattr.ia_valid |= ATTR_MTIME; |
| 216 | orangefs_inode_setattr(dir, &iattr); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 217 | mark_inode_dirty_sync(dir); |
| 218 | } |
| 219 | return ret; |
| 220 | } |
| 221 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 222 | static int orangefs_symlink(struct inode *dir, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 223 | struct dentry *dentry, |
| 224 | const char *symname) |
| 225 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 226 | struct orangefs_inode_s *parent = ORANGEFS_I(dir); |
| 227 | struct orangefs_kernel_op_s *new_op; |
Martin Brandenburg | db0267e | 2017-11-10 12:08:01 -0500 | [diff] [blame] | 228 | struct orangefs_object_kref ref; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 229 | struct inode *inode; |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 230 | struct iattr iattr; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 231 | int mode = 755; |
| 232 | int ret; |
| 233 | |
| 234 | gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__); |
| 235 | |
| 236 | if (!symname) |
| 237 | return -EINVAL; |
| 238 | |
Martin Brandenburg | c62da58 | 2016-02-29 16:07:35 -0500 | [diff] [blame] | 239 | if (strlen(symname)+1 > ORANGEFS_NAME_MAX) |
| 240 | return -ENAMETOOLONG; |
| 241 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 242 | new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 243 | if (!new_op) |
| 244 | return -ENOMEM; |
| 245 | |
| 246 | new_op->upcall.req.sym.parent_refn = parent->refn; |
| 247 | |
| 248 | fill_default_sys_attrs(new_op->upcall.req.sym.attributes, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 249 | ORANGEFS_TYPE_SYMLINK, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 250 | mode); |
| 251 | |
| 252 | strncpy(new_op->upcall.req.sym.entry_name, |
| 253 | dentry->d_name.name, |
Xiongfeng Wang | 6bdfb48 | 2018-01-08 20:22:33 +0800 | [diff] [blame] | 254 | ORANGEFS_NAME_MAX - 1); |
| 255 | strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX - 1); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 256 | |
| 257 | ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); |
| 258 | |
| 259 | gossip_debug(GOSSIP_NAME_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 260 | "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n", |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 261 | &new_op->downcall.resp.sym.refn.khandle, |
| 262 | new_op->downcall.resp.sym.refn.fs_id, ret); |
| 263 | |
| 264 | if (ret < 0) { |
| 265 | gossip_debug(GOSSIP_NAME_DEBUG, |
| 266 | "%s: failed with error code %d\n", |
| 267 | __func__, ret); |
| 268 | goto out; |
| 269 | } |
| 270 | |
Martin Brandenburg | db0267e | 2017-11-10 12:08:01 -0500 | [diff] [blame] | 271 | ref = new_op->downcall.resp.sym.refn; |
| 272 | op_release(new_op); |
| 273 | |
| 274 | inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 275 | if (IS_ERR(inode)) { |
| 276 | gossip_err |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 277 | ("*** Failed to allocate orangefs symlink inode\n"); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 278 | ret = PTR_ERR(inode); |
| 279 | goto out; |
| 280 | } |
Martin Brandenburg | f6a4b4c | 2018-05-31 16:36:58 +0000 | [diff] [blame] | 281 | /* |
| 282 | * This is necessary because orangefs_inode_getattr will not |
| 283 | * re-read symlink size as it is impossible for it to change. |
| 284 | * Invalidating the cache does not help. orangefs_new_inode |
| 285 | * does not set the correct size (it does not know symname). |
| 286 | */ |
| 287 | inode->i_size = strlen(symname); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 288 | |
| 289 | gossip_debug(GOSSIP_NAME_DEBUG, |
| 290 | "Assigned symlink inode new number of %pU\n", |
| 291 | get_khandle_from_ino(inode)); |
| 292 | |
Al Viro | 1e2e547 | 2018-05-04 08:23:01 -0400 | [diff] [blame] | 293 | d_instantiate_new(dentry, inode); |
Miklos Szeredi | 804b173 | 2016-10-17 10:14:23 +0200 | [diff] [blame] | 294 | orangefs_set_timeout(dentry); |
Martin Brandenburg | 8bbb20a | 2016-07-28 14:46:36 -0400 | [diff] [blame] | 295 | ORANGEFS_I(inode)->getattr_time = jiffies - 1; |
Martin Brandenburg | 68a24a6 | 2017-04-25 15:38:03 -0400 | [diff] [blame] | 296 | ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 297 | |
| 298 | gossip_debug(GOSSIP_NAME_DEBUG, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 299 | "Inode (Symlink) %pU -> %pd\n", |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 300 | get_khandle_from_ino(inode), |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 301 | dentry); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 302 | |
Deepa Dinamani | c2050a4 | 2016-09-14 07:48:06 -0700 | [diff] [blame] | 303 | dir->i_mtime = dir->i_ctime = current_time(dir); |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 304 | memset(&iattr, 0, sizeof iattr); |
| 305 | iattr.ia_valid |= ATTR_MTIME; |
| 306 | orangefs_inode_setattr(dir, &iattr); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 307 | mark_inode_dirty_sync(dir); |
| 308 | ret = 0; |
| 309 | out: |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 310 | return ret; |
| 311 | } |
| 312 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 313 | static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 314 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 315 | struct orangefs_inode_s *parent = ORANGEFS_I(dir); |
| 316 | struct orangefs_kernel_op_s *new_op; |
Martin Brandenburg | db0267e | 2017-11-10 12:08:01 -0500 | [diff] [blame] | 317 | struct orangefs_object_kref ref; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 318 | struct inode *inode; |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 319 | struct iattr iattr; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 320 | int ret; |
| 321 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 322 | new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 323 | if (!new_op) |
| 324 | return -ENOMEM; |
| 325 | |
| 326 | new_op->upcall.req.mkdir.parent_refn = parent->refn; |
| 327 | |
| 328 | fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 329 | ORANGEFS_TYPE_DIRECTORY, mode); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 330 | |
| 331 | strncpy(new_op->upcall.req.mkdir.d_name, |
Xiongfeng Wang | 6bdfb48 | 2018-01-08 20:22:33 +0800 | [diff] [blame] | 332 | dentry->d_name.name, ORANGEFS_NAME_MAX - 1); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 333 | |
| 334 | ret = service_operation(new_op, __func__, get_interruptible_flag(dir)); |
| 335 | |
| 336 | gossip_debug(GOSSIP_NAME_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 337 | "Mkdir Got ORANGEFS handle %pU on fsid %d\n", |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 338 | &new_op->downcall.resp.mkdir.refn.khandle, |
| 339 | new_op->downcall.resp.mkdir.refn.fs_id); |
| 340 | |
| 341 | if (ret < 0) { |
| 342 | gossip_debug(GOSSIP_NAME_DEBUG, |
| 343 | "%s: failed with error code %d\n", |
| 344 | __func__, ret); |
| 345 | goto out; |
| 346 | } |
| 347 | |
Martin Brandenburg | db0267e | 2017-11-10 12:08:01 -0500 | [diff] [blame] | 348 | ref = new_op->downcall.resp.mkdir.refn; |
| 349 | op_release(new_op); |
| 350 | |
| 351 | inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 352 | if (IS_ERR(inode)) { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 353 | gossip_err("*** Failed to allocate orangefs dir inode\n"); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 354 | ret = PTR_ERR(inode); |
| 355 | goto out; |
| 356 | } |
| 357 | |
| 358 | gossip_debug(GOSSIP_NAME_DEBUG, |
| 359 | "Assigned dir inode new number of %pU\n", |
| 360 | get_khandle_from_ino(inode)); |
| 361 | |
Al Viro | 1e2e547 | 2018-05-04 08:23:01 -0400 | [diff] [blame] | 362 | d_instantiate_new(dentry, inode); |
Miklos Szeredi | 804b173 | 2016-10-17 10:14:23 +0200 | [diff] [blame] | 363 | orangefs_set_timeout(dentry); |
Martin Brandenburg | 8bbb20a | 2016-07-28 14:46:36 -0400 | [diff] [blame] | 364 | ORANGEFS_I(inode)->getattr_time = jiffies - 1; |
Martin Brandenburg | 68a24a6 | 2017-04-25 15:38:03 -0400 | [diff] [blame] | 365 | ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 366 | |
| 367 | gossip_debug(GOSSIP_NAME_DEBUG, |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 368 | "Inode (Directory) %pU -> %pd\n", |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 369 | get_khandle_from_ino(inode), |
Al Viro | f66debf | 2016-08-07 12:20:01 -0400 | [diff] [blame] | 370 | dentry); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 371 | |
| 372 | /* |
| 373 | * NOTE: we have no good way to keep nlink consistent for directories |
| 374 | * across clients; keep constant at 1. |
| 375 | */ |
Deepa Dinamani | c2050a4 | 2016-09-14 07:48:06 -0700 | [diff] [blame] | 376 | dir->i_mtime = dir->i_ctime = current_time(dir); |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 377 | memset(&iattr, 0, sizeof iattr); |
| 378 | iattr.ia_valid |= ATTR_MTIME; |
| 379 | orangefs_inode_setattr(dir, &iattr); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 380 | mark_inode_dirty_sync(dir); |
| 381 | out: |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 382 | return ret; |
| 383 | } |
| 384 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 385 | static int orangefs_rename(struct inode *old_dir, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 386 | struct dentry *old_dentry, |
| 387 | struct inode *new_dir, |
Miklos Szeredi | 1cd66c9 | 2016-09-27 11:03:58 +0200 | [diff] [blame] | 388 | struct dentry *new_dentry, |
| 389 | unsigned int flags) |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 390 | { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 391 | struct orangefs_kernel_op_s *new_op; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 392 | int ret; |
| 393 | |
Miklos Szeredi | 1cd66c9 | 2016-09-27 11:03:58 +0200 | [diff] [blame] | 394 | if (flags) |
| 395 | return -EINVAL; |
| 396 | |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 397 | gossip_debug(GOSSIP_NAME_DEBUG, |
Al Viro | 96b0cff | 2016-05-29 15:00:34 -0400 | [diff] [blame] | 398 | "orangefs_rename: called (%pd2 => %pd2) ct=%d\n", |
| 399 | old_dentry, new_dentry, d_count(new_dentry)); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 400 | |
Martin Brandenburg | 8bbb20a | 2016-07-28 14:46:36 -0400 | [diff] [blame] | 401 | ORANGEFS_I(new_dentry->d_parent->d_inode)->getattr_time = jiffies - 1; |
Martin Brandenburg | 71680c1 | 2016-06-09 16:32:38 -0400 | [diff] [blame] | 402 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 403 | new_op = op_alloc(ORANGEFS_VFS_OP_RENAME); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 404 | if (!new_op) |
| 405 | return -EINVAL; |
| 406 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 407 | new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn; |
| 408 | new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn; |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 409 | |
| 410 | strncpy(new_op->upcall.req.rename.d_old_name, |
| 411 | old_dentry->d_name.name, |
Xiongfeng Wang | 6bdfb48 | 2018-01-08 20:22:33 +0800 | [diff] [blame] | 412 | ORANGEFS_NAME_MAX - 1); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 413 | strncpy(new_op->upcall.req.rename.d_new_name, |
| 414 | new_dentry->d_name.name, |
Xiongfeng Wang | 6bdfb48 | 2018-01-08 20:22:33 +0800 | [diff] [blame] | 415 | ORANGEFS_NAME_MAX - 1); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 416 | |
| 417 | ret = service_operation(new_op, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 418 | "orangefs_rename", |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 419 | get_interruptible_flag(old_dentry->d_inode)); |
| 420 | |
| 421 | gossip_debug(GOSSIP_NAME_DEBUG, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 422 | "orangefs_rename: got downcall status %d\n", |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 423 | ret); |
| 424 | |
| 425 | if (new_dentry->d_inode) |
Deepa Dinamani | c2050a4 | 2016-09-14 07:48:06 -0700 | [diff] [blame] | 426 | new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode); |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 427 | |
| 428 | op_release(new_op); |
| 429 | return ret; |
| 430 | } |
| 431 | |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 432 | /* ORANGEFS implementation of VFS inode operations for directories */ |
Al Viro | 6f3fc10 | 2016-05-14 18:46:32 -0400 | [diff] [blame] | 433 | const struct inode_operations orangefs_dir_inode_operations = { |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 434 | .lookup = orangefs_lookup, |
| 435 | .get_acl = orangefs_get_acl, |
| 436 | .set_acl = orangefs_set_acl, |
| 437 | .create = orangefs_create, |
| 438 | .unlink = orangefs_unlink, |
| 439 | .symlink = orangefs_symlink, |
| 440 | .mkdir = orangefs_mkdir, |
| 441 | .rmdir = orangefs_unlink, |
| 442 | .rename = orangefs_rename, |
| 443 | .setattr = orangefs_setattr, |
| 444 | .getattr = orangefs_getattr, |
Yi Liu | 8bb8aef | 2015-11-24 15:12:14 -0500 | [diff] [blame] | 445 | .listxattr = orangefs_listxattr, |
Martin Brandenburg | 933287d | 2016-01-30 13:46:54 -0500 | [diff] [blame] | 446 | .permission = orangefs_permission, |
Martin Brandenburg | a55f2d8 | 2017-11-07 15:01:40 -0500 | [diff] [blame] | 447 | .update_time = orangefs_update_time, |
Mike Marshall | 274dcf5 | 2015-07-17 10:38:13 -0400 | [diff] [blame] | 448 | }; |