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: %pd\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: %pd: 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 :%pd:\n",
67 gossip_debug(GOSSIP_NAME_DEBUG
,
68 "%s: Assigned inode :%pU: for file :%pd:\n",
70 get_khandle_from_ino(inode
),
73 d_instantiate(dentry
, inode
);
74 unlock_new_inode(inode
);
75 orangefs_set_timeout(dentry
);
76 ORANGEFS_I(inode
)->getattr_time
= jiffies
- 1;
77 ORANGEFS_I(inode
)->getattr_mask
= STATX_BASIC_STATS
;
79 gossip_debug(GOSSIP_NAME_DEBUG
,
80 "%s: dentry instantiated for %pd\n",
85 dir
->i_mtime
= dir
->i_ctime
= current_time(dir
);
86 mark_inode_dirty_sync(dir
);
90 gossip_debug(GOSSIP_NAME_DEBUG
,
91 "%s: %pd: returning %d\n",
99 * Attempt to resolve an object name (dentry->d_name), parent handle, and
100 * fsid into a handle for the object.
102 static struct dentry
*orangefs_lookup(struct inode
*dir
, struct dentry
*dentry
,
105 struct orangefs_inode_s
*parent
= ORANGEFS_I(dir
);
106 struct orangefs_kernel_op_s
*new_op
;
112 * in theory we could skip a lookup here (if the intent is to
113 * create) in order to avoid a potentially failed lookup, but
114 * leaving it in can skip a valid lookup and try to create a file
115 * that already exists (e.g. the vfs already handles checking for
116 * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
117 * in the create path)
119 gossip_debug(GOSSIP_NAME_DEBUG
, "%s called on %pd\n",
122 if (dentry
->d_name
.len
> (ORANGEFS_NAME_MAX
- 1))
123 return ERR_PTR(-ENAMETOOLONG
);
125 new_op
= op_alloc(ORANGEFS_VFS_OP_LOOKUP
);
127 return ERR_PTR(-ENOMEM
);
129 new_op
->upcall
.req
.lookup
.sym_follow
= ORANGEFS_LOOKUP_LINK_NO_FOLLOW
;
131 gossip_debug(GOSSIP_NAME_DEBUG
, "%s:%s:%d using parent %pU\n",
135 &parent
->refn
.khandle
);
136 new_op
->upcall
.req
.lookup
.parent_refn
= parent
->refn
;
138 strncpy(new_op
->upcall
.req
.lookup
.d_name
, dentry
->d_name
.name
,
141 gossip_debug(GOSSIP_NAME_DEBUG
,
142 "%s: doing lookup on %s under %pU,%d\n",
144 new_op
->upcall
.req
.lookup
.d_name
,
145 &new_op
->upcall
.req
.lookup
.parent_refn
.khandle
,
146 new_op
->upcall
.req
.lookup
.parent_refn
.fs_id
);
148 ret
= service_operation(new_op
, __func__
, get_interruptible_flag(dir
));
150 gossip_debug(GOSSIP_NAME_DEBUG
,
151 "Lookup Got %pU, fsid %d (ret=%d)\n",
152 &new_op
->downcall
.resp
.lookup
.refn
.khandle
,
153 new_op
->downcall
.resp
.lookup
.refn
.fs_id
,
157 if (ret
== -ENOENT
) {
159 * if no inode was found, add a negative dentry to
160 * dcache anyway; if we don't, we don't hold expected
161 * lookup semantics and we most noticeably break
162 * during directory renames.
164 * however, if the operation failed or exited, do not
165 * add the dentry (e.g. in the case that a touch is
166 * issued on a file that already exists that was
167 * interrupted during this lookup -- no need to add
168 * another negative dentry for an existing file)
171 gossip_debug(GOSSIP_NAME_DEBUG
,
172 "orangefs_lookup: Adding *negative* dentry "
182 /* must be a non-recoverable error */
187 orangefs_set_timeout(dentry
);
189 inode
= orangefs_iget(dir
->i_sb
, &new_op
->downcall
.resp
.lookup
.refn
);
191 gossip_debug(GOSSIP_NAME_DEBUG
,
192 "error %ld from iget\n", PTR_ERR(inode
));
193 res
= ERR_CAST(inode
);
197 gossip_debug(GOSSIP_NAME_DEBUG
,
199 "Found good inode [%lu] with count [%d]\n",
204 (int)atomic_read(&inode
->i_count
));
206 /* update dentry/inode pair into dcache */
207 res
= d_splice_alias(inode
, dentry
);
209 gossip_debug(GOSSIP_NAME_DEBUG
,
210 "Lookup success (inode ct = %d)\n",
211 (int)atomic_read(&inode
->i_count
));
217 /* return 0 on success; non-zero otherwise */
218 static int orangefs_unlink(struct inode
*dir
, struct dentry
*dentry
)
220 struct inode
*inode
= dentry
->d_inode
;
221 struct orangefs_inode_s
*parent
= ORANGEFS_I(dir
);
222 struct orangefs_kernel_op_s
*new_op
;
225 gossip_debug(GOSSIP_NAME_DEBUG
,
226 "%s: called on %pd\n"
227 " (inode %pU): Parent is %pU | fs_id %d\n",
230 get_khandle_from_ino(inode
),
231 &parent
->refn
.khandle
,
234 new_op
= op_alloc(ORANGEFS_VFS_OP_REMOVE
);
238 new_op
->upcall
.req
.remove
.parent_refn
= parent
->refn
;
239 strncpy(new_op
->upcall
.req
.remove
.d_name
, dentry
->d_name
.name
,
242 ret
= service_operation(new_op
, "orangefs_unlink",
243 get_interruptible_flag(inode
));
245 gossip_debug(GOSSIP_NAME_DEBUG
,
246 "%s: service_operation returned:%d:\n",
255 SetMtimeFlag(parent
);
256 dir
->i_mtime
= dir
->i_ctime
= current_time(dir
);
257 mark_inode_dirty_sync(dir
);
262 static int orangefs_symlink(struct inode
*dir
,
263 struct dentry
*dentry
,
266 struct orangefs_inode_s
*parent
= ORANGEFS_I(dir
);
267 struct orangefs_kernel_op_s
*new_op
;
272 gossip_debug(GOSSIP_NAME_DEBUG
, "%s: called\n", __func__
);
277 if (strlen(symname
)+1 > ORANGEFS_NAME_MAX
)
278 return -ENAMETOOLONG
;
280 new_op
= op_alloc(ORANGEFS_VFS_OP_SYMLINK
);
284 new_op
->upcall
.req
.sym
.parent_refn
= parent
->refn
;
286 fill_default_sys_attrs(new_op
->upcall
.req
.sym
.attributes
,
287 ORANGEFS_TYPE_SYMLINK
,
290 strncpy(new_op
->upcall
.req
.sym
.entry_name
,
293 strncpy(new_op
->upcall
.req
.sym
.target
, symname
, ORANGEFS_NAME_MAX
);
295 ret
= service_operation(new_op
, __func__
, get_interruptible_flag(dir
));
297 gossip_debug(GOSSIP_NAME_DEBUG
,
298 "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
299 &new_op
->downcall
.resp
.sym
.refn
.khandle
,
300 new_op
->downcall
.resp
.sym
.refn
.fs_id
, ret
);
303 gossip_debug(GOSSIP_NAME_DEBUG
,
304 "%s: failed with error code %d\n",
309 inode
= orangefs_new_inode(dir
->i_sb
, dir
, S_IFLNK
| mode
, 0,
310 &new_op
->downcall
.resp
.sym
.refn
);
313 ("*** Failed to allocate orangefs symlink inode\n");
314 ret
= PTR_ERR(inode
);
318 gossip_debug(GOSSIP_NAME_DEBUG
,
319 "Assigned symlink inode new number of %pU\n",
320 get_khandle_from_ino(inode
));
322 d_instantiate(dentry
, inode
);
323 unlock_new_inode(inode
);
324 orangefs_set_timeout(dentry
);
325 ORANGEFS_I(inode
)->getattr_time
= jiffies
- 1;
326 ORANGEFS_I(inode
)->getattr_mask
= STATX_BASIC_STATS
;
328 gossip_debug(GOSSIP_NAME_DEBUG
,
329 "Inode (Symlink) %pU -> %pd\n",
330 get_khandle_from_ino(inode
),
333 SetMtimeFlag(parent
);
334 dir
->i_mtime
= dir
->i_ctime
= current_time(dir
);
335 mark_inode_dirty_sync(dir
);
342 static int orangefs_mkdir(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
344 struct orangefs_inode_s
*parent
= ORANGEFS_I(dir
);
345 struct orangefs_kernel_op_s
*new_op
;
349 new_op
= op_alloc(ORANGEFS_VFS_OP_MKDIR
);
353 new_op
->upcall
.req
.mkdir
.parent_refn
= parent
->refn
;
355 fill_default_sys_attrs(new_op
->upcall
.req
.mkdir
.attributes
,
356 ORANGEFS_TYPE_DIRECTORY
, mode
);
358 strncpy(new_op
->upcall
.req
.mkdir
.d_name
,
359 dentry
->d_name
.name
, ORANGEFS_NAME_MAX
);
361 ret
= service_operation(new_op
, __func__
, get_interruptible_flag(dir
));
363 gossip_debug(GOSSIP_NAME_DEBUG
,
364 "Mkdir Got ORANGEFS handle %pU on fsid %d\n",
365 &new_op
->downcall
.resp
.mkdir
.refn
.khandle
,
366 new_op
->downcall
.resp
.mkdir
.refn
.fs_id
);
369 gossip_debug(GOSSIP_NAME_DEBUG
,
370 "%s: failed with error code %d\n",
375 inode
= orangefs_new_inode(dir
->i_sb
, dir
, S_IFDIR
| mode
, 0,
376 &new_op
->downcall
.resp
.mkdir
.refn
);
378 gossip_err("*** Failed to allocate orangefs dir inode\n");
379 ret
= PTR_ERR(inode
);
383 gossip_debug(GOSSIP_NAME_DEBUG
,
384 "Assigned dir inode new number of %pU\n",
385 get_khandle_from_ino(inode
));
387 d_instantiate(dentry
, inode
);
388 unlock_new_inode(inode
);
389 orangefs_set_timeout(dentry
);
390 ORANGEFS_I(inode
)->getattr_time
= jiffies
- 1;
391 ORANGEFS_I(inode
)->getattr_mask
= STATX_BASIC_STATS
;
393 gossip_debug(GOSSIP_NAME_DEBUG
,
394 "Inode (Directory) %pU -> %pd\n",
395 get_khandle_from_ino(inode
),
399 * NOTE: we have no good way to keep nlink consistent for directories
400 * across clients; keep constant at 1.
402 SetMtimeFlag(parent
);
403 dir
->i_mtime
= dir
->i_ctime
= current_time(dir
);
404 mark_inode_dirty_sync(dir
);
410 static int orangefs_rename(struct inode
*old_dir
,
411 struct dentry
*old_dentry
,
412 struct inode
*new_dir
,
413 struct dentry
*new_dentry
,
416 struct orangefs_kernel_op_s
*new_op
;
422 gossip_debug(GOSSIP_NAME_DEBUG
,
423 "orangefs_rename: called (%pd2 => %pd2) ct=%d\n",
424 old_dentry
, new_dentry
, d_count(new_dentry
));
426 ORANGEFS_I(new_dentry
->d_parent
->d_inode
)->getattr_time
= jiffies
- 1;
428 new_op
= op_alloc(ORANGEFS_VFS_OP_RENAME
);
432 new_op
->upcall
.req
.rename
.old_parent_refn
= ORANGEFS_I(old_dir
)->refn
;
433 new_op
->upcall
.req
.rename
.new_parent_refn
= ORANGEFS_I(new_dir
)->refn
;
435 strncpy(new_op
->upcall
.req
.rename
.d_old_name
,
436 old_dentry
->d_name
.name
,
438 strncpy(new_op
->upcall
.req
.rename
.d_new_name
,
439 new_dentry
->d_name
.name
,
442 ret
= service_operation(new_op
,
444 get_interruptible_flag(old_dentry
->d_inode
));
446 gossip_debug(GOSSIP_NAME_DEBUG
,
447 "orangefs_rename: got downcall status %d\n",
450 if (new_dentry
->d_inode
)
451 new_dentry
->d_inode
->i_ctime
= current_time(new_dentry
->d_inode
);
457 /* ORANGEFS implementation of VFS inode operations for directories */
458 const struct inode_operations orangefs_dir_inode_operations
= {
459 .lookup
= orangefs_lookup
,
460 .get_acl
= orangefs_get_acl
,
461 .set_acl
= orangefs_set_acl
,
462 .create
= orangefs_create
,
463 .unlink
= orangefs_unlink
,
464 .symlink
= orangefs_symlink
,
465 .mkdir
= orangefs_mkdir
,
466 .rmdir
= orangefs_unlink
,
467 .rename
= orangefs_rename
,
468 .setattr
= orangefs_setattr
,
469 .getattr
= orangefs_getattr
,
470 .listxattr
= orangefs_listxattr
,
471 .permission
= orangefs_permission
,