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