2 * (C) 2001 Clemson University and The University of Chicago
4 * See COPYING in top-level directory.
8 * Linux VFS namei operations.
12 #include "pvfs2-kernel.h"
15 * Get a newly allocated inode to go with a negative dentry.
17 static int pvfs2_create(struct inode *dir,
18 struct dentry *dentry,
22 struct pvfs2_inode_s *parent = PVFS2_I(dir);
23 struct pvfs2_kernel_op_s *new_op;
27 gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
29 new_op = op_alloc(PVFS2_VFS_OP_CREATE);
33 new_op->upcall.req.create.parent_refn = parent->refn;
35 fill_default_sys_attrs(new_op->upcall.req.create.attributes,
36 PVFS_TYPE_METAFILE, mode);
38 strncpy(new_op->upcall.req.create.d_name,
39 dentry->d_name.name, PVFS2_NAME_LEN);
41 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
43 gossip_debug(GOSSIP_NAME_DEBUG,
44 "Create Got PVFS2 handle %pU on fsid %d (ret=%d)\n",
45 &new_op->downcall.resp.create.refn.khandle,
46 new_op->downcall.resp.create.refn.fs_id, ret);
49 gossip_debug(GOSSIP_NAME_DEBUG,
50 "%s: failed with error code %d\n",
55 inode = pvfs2_new_inode(dir->i_sb, dir, S_IFREG | mode, 0,
56 &new_op->downcall.resp.create.refn);
58 gossip_err("*** Failed to allocate pvfs2 file inode\n");
63 gossip_debug(GOSSIP_NAME_DEBUG,
64 "Assigned file inode new number of %pU\n",
65 get_khandle_from_ino(inode));
67 d_instantiate(dentry, inode);
68 unlock_new_inode(inode);
70 gossip_debug(GOSSIP_NAME_DEBUG,
71 "Inode (Regular File) %pU -> %s\n",
72 get_khandle_from_ino(inode),
76 dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
77 mark_inode_dirty_sync(dir);
81 gossip_debug(GOSSIP_NAME_DEBUG, "%s: returning %d\n", __func__, ret);
86 * Attempt to resolve an object name (dentry->d_name), parent handle, and
87 * fsid into a handle for the object.
89 static struct dentry *pvfs2_lookup(struct inode *dir, struct dentry *dentry,
92 struct pvfs2_inode_s *parent = PVFS2_I(dir);
93 struct pvfs2_kernel_op_s *new_op;
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)
106 gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %s\n",
107 __func__, dentry->d_name.name);
109 if (dentry->d_name.len > (PVFS2_NAME_LEN - 1))
110 return ERR_PTR(-ENAMETOOLONG);
112 new_op = op_alloc(PVFS2_VFS_OP_LOOKUP);
114 return ERR_PTR(-ENOMEM);
116 new_op->upcall.req.lookup.sym_follow = flags & LOOKUP_FOLLOW;
118 gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
122 &parent->refn.khandle);
123 new_op->upcall.req.lookup.parent_refn = parent->refn;
125 strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
128 gossip_debug(GOSSIP_NAME_DEBUG,
129 "%s: doing lookup on %s under %pU,%d (follow=%s)\n",
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 ==
135 PVFS2_LOOKUP_LINK_FOLLOW) ? "yes" : "no"));
137 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
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,
146 if (ret == -ENOENT) {
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.
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)
160 gossip_debug(GOSSIP_NAME_DEBUG,
161 "pvfs2_lookup: Adding *negative* dentry "
164 dentry->d_name.name);
171 /* must be a non-recoverable error */
176 inode = pvfs2_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
178 gossip_debug(GOSSIP_NAME_DEBUG,
179 "error %ld from iget\n", PTR_ERR(inode));
180 res = ERR_CAST(inode);
184 gossip_debug(GOSSIP_NAME_DEBUG,
186 "Found good inode [%lu] with count [%d]\n",
191 (int)atomic_read(&inode->i_count));
193 /* update dentry/inode pair into dcache */
194 res = d_splice_alias(inode, dentry);
196 gossip_debug(GOSSIP_NAME_DEBUG,
197 "Lookup success (inode ct = %d)\n",
198 (int)atomic_read(&inode->i_count));
204 /* return 0 on success; non-zero otherwise */
205 static int pvfs2_unlink(struct inode *dir, struct dentry *dentry)
207 struct inode *inode = dentry->d_inode;
208 struct pvfs2_inode_s *parent = PVFS2_I(dir);
209 struct pvfs2_kernel_op_s *new_op;
212 gossip_debug(GOSSIP_NAME_DEBUG,
214 " (inode %pU): Parent is %pU | fs_id %d\n",
217 get_khandle_from_ino(inode),
218 &parent->refn.khandle,
221 new_op = op_alloc(PVFS2_VFS_OP_REMOVE);
225 new_op->upcall.req.remove.parent_refn = parent->refn;
226 strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
229 ret = service_operation(new_op, "pvfs2_unlink",
230 get_interruptible_flag(inode));
232 /* when request is serviced properly, free req op struct */
238 SetMtimeFlag(parent);
239 dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
240 mark_inode_dirty_sync(dir);
246 * PVFS2 does not support hard links.
248 static int pvfs2_link(struct dentry *old_dentry,
250 struct dentry *dentry)
256 * PVFS2 does not support special files.
258 static int pvfs2_mknod(struct inode *dir,
259 struct dentry *dentry,
266 static int pvfs2_symlink(struct inode *dir,
267 struct dentry *dentry,
270 struct pvfs2_inode_s *parent = PVFS2_I(dir);
271 struct pvfs2_kernel_op_s *new_op;
276 gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
281 new_op = op_alloc(PVFS2_VFS_OP_SYMLINK);
285 new_op->upcall.req.sym.parent_refn = parent->refn;
287 fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
291 strncpy(new_op->upcall.req.sym.entry_name,
294 strncpy(new_op->upcall.req.sym.target, symname, PVFS2_NAME_LEN);
296 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
298 gossip_debug(GOSSIP_NAME_DEBUG,
299 "Symlink Got PVFS2 handle %pU on fsid %d (ret=%d)\n",
300 &new_op->downcall.resp.sym.refn.khandle,
301 new_op->downcall.resp.sym.refn.fs_id, ret);
304 gossip_debug(GOSSIP_NAME_DEBUG,
305 "%s: failed with error code %d\n",
310 inode = pvfs2_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0,
311 &new_op->downcall.resp.sym.refn);
314 ("*** Failed to allocate pvfs2 symlink inode\n");
315 ret = PTR_ERR(inode);
319 gossip_debug(GOSSIP_NAME_DEBUG,
320 "Assigned symlink inode new number of %pU\n",
321 get_khandle_from_ino(inode));
323 d_instantiate(dentry, inode);
324 unlock_new_inode(inode);
326 gossip_debug(GOSSIP_NAME_DEBUG,
327 "Inode (Symlink) %pU -> %s\n",
328 get_khandle_from_ino(inode),
329 dentry->d_name.name);
331 SetMtimeFlag(parent);
332 dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
333 mark_inode_dirty_sync(dir);
340 static int pvfs2_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
342 struct pvfs2_inode_s *parent = PVFS2_I(dir);
343 struct pvfs2_kernel_op_s *new_op;
347 new_op = op_alloc(PVFS2_VFS_OP_MKDIR);
351 new_op->upcall.req.mkdir.parent_refn = parent->refn;
353 fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
354 PVFS_TYPE_DIRECTORY, mode);
356 strncpy(new_op->upcall.req.mkdir.d_name,
357 dentry->d_name.name, PVFS2_NAME_LEN);
359 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
361 gossip_debug(GOSSIP_NAME_DEBUG,
362 "Mkdir Got PVFS2 handle %pU on fsid %d\n",
363 &new_op->downcall.resp.mkdir.refn.khandle,
364 new_op->downcall.resp.mkdir.refn.fs_id);
367 gossip_debug(GOSSIP_NAME_DEBUG,
368 "%s: failed with error code %d\n",
373 inode = pvfs2_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0,
374 &new_op->downcall.resp.mkdir.refn);
376 gossip_err("*** Failed to allocate pvfs2 dir inode\n");
377 ret = PTR_ERR(inode);
381 gossip_debug(GOSSIP_NAME_DEBUG,
382 "Assigned dir inode new number of %pU\n",
383 get_khandle_from_ino(inode));
385 d_instantiate(dentry, inode);
386 unlock_new_inode(inode);
388 gossip_debug(GOSSIP_NAME_DEBUG,
389 "Inode (Directory) %pU -> %s\n",
390 get_khandle_from_ino(inode),
391 dentry->d_name.name);
394 * NOTE: we have no good way to keep nlink consistent for directories
395 * across clients; keep constant at 1.
397 SetMtimeFlag(parent);
398 dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
399 mark_inode_dirty_sync(dir);
405 static int pvfs2_rename(struct inode *old_dir,
406 struct dentry *old_dentry,
407 struct inode *new_dir,
408 struct dentry *new_dentry)
410 struct pvfs2_kernel_op_s *new_op;
413 gossip_debug(GOSSIP_NAME_DEBUG,
414 "pvfs2_rename: called (%s/%s => %s/%s) ct=%d\n",
415 old_dentry->d_parent->d_name.name,
416 old_dentry->d_name.name,
417 new_dentry->d_parent->d_name.name,
418 new_dentry->d_name.name,
419 d_count(new_dentry));
421 new_op = op_alloc(PVFS2_VFS_OP_RENAME);
425 new_op->upcall.req.rename.old_parent_refn = PVFS2_I(old_dir)->refn;
426 new_op->upcall.req.rename.new_parent_refn = PVFS2_I(new_dir)->refn;
428 strncpy(new_op->upcall.req.rename.d_old_name,
429 old_dentry->d_name.name,
431 strncpy(new_op->upcall.req.rename.d_new_name,
432 new_dentry->d_name.name,
435 ret = service_operation(new_op,
437 get_interruptible_flag(old_dentry->d_inode));
439 gossip_debug(GOSSIP_NAME_DEBUG,
440 "pvfs2_rename: got downcall status %d\n",
443 if (new_dentry->d_inode)
444 new_dentry->d_inode->i_ctime = CURRENT_TIME;
450 /* PVFS2 implementation of VFS inode operations for directories */
451 struct inode_operations pvfs2_dir_inode_operations = {
452 .lookup = pvfs2_lookup,
453 .get_acl = pvfs2_get_acl,
454 .set_acl = pvfs2_set_acl,
455 .create = pvfs2_create,
457 .unlink = pvfs2_unlink,
458 .symlink = pvfs2_symlink,
459 .mkdir = pvfs2_mkdir,
460 .rmdir = pvfs2_unlink,
461 .mknod = pvfs2_mknod,
462 .rename = pvfs2_rename,
463 .setattr = pvfs2_setattr,
464 .getattr = pvfs2_getattr,
465 .setxattr = generic_setxattr,
466 .getxattr = generic_getxattr,
467 .removexattr = generic_removexattr,
468 .listxattr = pvfs2_listxattr,