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