2 * (C) 2001 Clemson University and The University of Chicago
4 * See COPYING in top-level directory.
8 * Linux VFS namei operations.
12 #include "orangefs-kernel.h"
15 * Get a newly allocated inode to go with a negative dentry.
17 static int orangefs_create(struct inode *dir,
18 struct dentry *dentry,
22 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
23 struct orangefs_kernel_op_s *new_op;
27 gossip_debug(GOSSIP_NAME_DEBUG, "%s: %s\n",
31 new_op = op_alloc(ORANGEFS_VFS_OP_CREATE);
35 new_op->upcall.req.create.parent_refn = parent->refn;
37 fill_default_sys_attrs(new_op->upcall.req.create.attributes,
38 ORANGEFS_TYPE_METAFILE, mode);
40 strncpy(new_op->upcall.req.create.d_name,
41 dentry->d_name.name, ORANGEFS_NAME_MAX);
43 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
45 gossip_debug(GOSSIP_NAME_DEBUG,
46 "%s: %s: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n",
49 &new_op->downcall.resp.create.refn.khandle,
50 new_op->downcall.resp.create.refn.fs_id,
57 inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0,
58 &new_op->downcall.resp.create.refn);
60 gossip_err("%s: Failed to allocate inode for file :%s:\n",
67 gossip_debug(GOSSIP_NAME_DEBUG,
68 "%s: Assigned inode :%pU: for file :%s:\n",
70 get_khandle_from_ino(inode),
73 d_instantiate(dentry, inode);
74 unlock_new_inode(inode);
75 dentry->d_time = jiffies + HZ;
77 gossip_debug(GOSSIP_NAME_DEBUG,
78 "%s: dentry instantiated for %s\n",
83 dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
84 mark_inode_dirty_sync(dir);
88 gossip_debug(GOSSIP_NAME_DEBUG,
89 "%s: %s: returning %d\n",
97 * Attempt to resolve an object name (dentry->d_name), parent handle, and
98 * fsid into a handle for the object.
100 static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
103 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
104 struct orangefs_kernel_op_s *new_op;
110 * in theory we could skip a lookup here (if the intent is to
111 * create) in order to avoid a potentially failed lookup, but
112 * leaving it in can skip a valid lookup and try to create a file
113 * that already exists (e.g. the vfs already handles checking for
114 * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
115 * in the create path)
117 gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %s\n",
118 __func__, dentry->d_name.name);
120 if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1))
121 return ERR_PTR(-ENAMETOOLONG);
123 new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
125 return ERR_PTR(-ENOMEM);
127 new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
129 gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
133 &parent->refn.khandle);
134 new_op->upcall.req.lookup.parent_refn = parent->refn;
136 strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
139 gossip_debug(GOSSIP_NAME_DEBUG,
140 "%s: doing lookup on %s under %pU,%d\n",
142 new_op->upcall.req.lookup.d_name,
143 &new_op->upcall.req.lookup.parent_refn.khandle,
144 new_op->upcall.req.lookup.parent_refn.fs_id);
146 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
148 gossip_debug(GOSSIP_NAME_DEBUG,
149 "Lookup Got %pU, fsid %d (ret=%d)\n",
150 &new_op->downcall.resp.lookup.refn.khandle,
151 new_op->downcall.resp.lookup.refn.fs_id,
155 if (ret == -ENOENT) {
157 * if no inode was found, add a negative dentry to
158 * dcache anyway; if we don't, we don't hold expected
159 * lookup semantics and we most noticeably break
160 * during directory renames.
162 * however, if the operation failed or exited, do not
163 * add the dentry (e.g. in the case that a touch is
164 * issued on a file that already exists that was
165 * interrupted during this lookup -- no need to add
166 * another negative dentry for an existing file)
169 gossip_debug(GOSSIP_NAME_DEBUG,
170 "orangefs_lookup: Adding *negative* dentry "
173 dentry->d_name.name);
180 /* must be a non-recoverable error */
185 dentry->d_time = jiffies + HZ;
187 inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
189 gossip_debug(GOSSIP_NAME_DEBUG,
190 "error %ld from iget\n", PTR_ERR(inode));
191 res = ERR_CAST(inode);
195 gossip_debug(GOSSIP_NAME_DEBUG,
197 "Found good inode [%lu] with count [%d]\n",
202 (int)atomic_read(&inode->i_count));
204 /* update dentry/inode pair into dcache */
205 res = d_splice_alias(inode, dentry);
207 gossip_debug(GOSSIP_NAME_DEBUG,
208 "Lookup success (inode ct = %d)\n",
209 (int)atomic_read(&inode->i_count));
215 /* return 0 on success; non-zero otherwise */
216 static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
218 struct inode *inode = dentry->d_inode;
219 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
220 struct orangefs_kernel_op_s *new_op;
223 gossip_debug(GOSSIP_NAME_DEBUG,
225 " (inode %pU): Parent is %pU | fs_id %d\n",
228 get_khandle_from_ino(inode),
229 &parent->refn.khandle,
232 new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
236 new_op->upcall.req.remove.parent_refn = parent->refn;
237 strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
240 ret = service_operation(new_op, "orangefs_unlink",
241 get_interruptible_flag(inode));
243 gossip_debug(GOSSIP_NAME_DEBUG,
244 "%s: service_operation returned:%d:\n",
253 SetMtimeFlag(parent);
254 dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
255 mark_inode_dirty_sync(dir);
260 static int orangefs_symlink(struct inode *dir,
261 struct dentry *dentry,
264 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
265 struct orangefs_kernel_op_s *new_op;
270 gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
275 if (strlen(symname)+1 > ORANGEFS_NAME_MAX)
276 return -ENAMETOOLONG;
278 new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
282 new_op->upcall.req.sym.parent_refn = parent->refn;
284 fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
285 ORANGEFS_TYPE_SYMLINK,
288 strncpy(new_op->upcall.req.sym.entry_name,
291 strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX);
293 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
295 gossip_debug(GOSSIP_NAME_DEBUG,
296 "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
297 &new_op->downcall.resp.sym.refn.khandle,
298 new_op->downcall.resp.sym.refn.fs_id, ret);
301 gossip_debug(GOSSIP_NAME_DEBUG,
302 "%s: failed with error code %d\n",
307 inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0,
308 &new_op->downcall.resp.sym.refn);
311 ("*** Failed to allocate orangefs symlink inode\n");
312 ret = PTR_ERR(inode);
316 gossip_debug(GOSSIP_NAME_DEBUG,
317 "Assigned symlink inode new number of %pU\n",
318 get_khandle_from_ino(inode));
320 d_instantiate(dentry, inode);
321 unlock_new_inode(inode);
322 dentry->d_time = jiffies + HZ;
324 gossip_debug(GOSSIP_NAME_DEBUG,
325 "Inode (Symlink) %pU -> %s\n",
326 get_khandle_from_ino(inode),
327 dentry->d_name.name);
329 SetMtimeFlag(parent);
330 dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
331 mark_inode_dirty_sync(dir);
338 static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
340 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
341 struct orangefs_kernel_op_s *new_op;
345 new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
349 new_op->upcall.req.mkdir.parent_refn = parent->refn;
351 fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
352 ORANGEFS_TYPE_DIRECTORY, mode);
354 strncpy(new_op->upcall.req.mkdir.d_name,
355 dentry->d_name.name, ORANGEFS_NAME_MAX);
357 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
359 gossip_debug(GOSSIP_NAME_DEBUG,
360 "Mkdir Got ORANGEFS handle %pU on fsid %d\n",
361 &new_op->downcall.resp.mkdir.refn.khandle,
362 new_op->downcall.resp.mkdir.refn.fs_id);
365 gossip_debug(GOSSIP_NAME_DEBUG,
366 "%s: failed with error code %d\n",
371 inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0,
372 &new_op->downcall.resp.mkdir.refn);
374 gossip_err("*** Failed to allocate orangefs dir inode\n");
375 ret = PTR_ERR(inode);
379 gossip_debug(GOSSIP_NAME_DEBUG,
380 "Assigned dir inode new number of %pU\n",
381 get_khandle_from_ino(inode));
383 d_instantiate(dentry, inode);
384 unlock_new_inode(inode);
385 dentry->d_time = jiffies + HZ;
387 gossip_debug(GOSSIP_NAME_DEBUG,
388 "Inode (Directory) %pU -> %s\n",
389 get_khandle_from_ino(inode),
390 dentry->d_name.name);
393 * NOTE: we have no good way to keep nlink consistent for directories
394 * across clients; keep constant at 1.
396 SetMtimeFlag(parent);
397 dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
398 mark_inode_dirty_sync(dir);
404 static int orangefs_rename(struct inode *old_dir,
405 struct dentry *old_dentry,
406 struct inode *new_dir,
407 struct dentry *new_dentry)
409 struct orangefs_kernel_op_s *new_op;
412 gossip_debug(GOSSIP_NAME_DEBUG,
413 "orangefs_rename: called (%pd2 => %pd2) ct=%d\n",
414 old_dentry, new_dentry, d_count(new_dentry));
416 new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
420 new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn;
421 new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn;
423 strncpy(new_op->upcall.req.rename.d_old_name,
424 old_dentry->d_name.name,
426 strncpy(new_op->upcall.req.rename.d_new_name,
427 new_dentry->d_name.name,
430 ret = service_operation(new_op,
432 get_interruptible_flag(old_dentry->d_inode));
434 gossip_debug(GOSSIP_NAME_DEBUG,
435 "orangefs_rename: got downcall status %d\n",
438 if (new_dentry->d_inode)
439 new_dentry->d_inode->i_ctime = CURRENT_TIME;
445 /* ORANGEFS implementation of VFS inode operations for directories */
446 const struct inode_operations orangefs_dir_inode_operations = {
447 .lookup = orangefs_lookup,
448 .get_acl = orangefs_get_acl,
449 .set_acl = orangefs_set_acl,
450 .create = orangefs_create,
451 .unlink = orangefs_unlink,
452 .symlink = orangefs_symlink,
453 .mkdir = orangefs_mkdir,
454 .rmdir = orangefs_unlink,
455 .rename = orangefs_rename,
456 .setattr = orangefs_setattr,
457 .getattr = orangefs_getattr,
458 .setxattr = generic_setxattr,
459 .getxattr = generic_getxattr,
460 .removexattr = generic_removexattr,
461 .listxattr = orangefs_listxattr,
462 .permission = orangefs_permission,