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