xref: /openbmc/linux/fs/orangefs/namei.c (revision 8bb8aefd5afb54a25a002feb4ec70011812d06a0)
1274dcf55SMike Marshall /*
2274dcf55SMike Marshall  * (C) 2001 Clemson University and The University of Chicago
3274dcf55SMike Marshall  *
4274dcf55SMike Marshall  * See COPYING in top-level directory.
5274dcf55SMike Marshall  */
6274dcf55SMike Marshall 
7274dcf55SMike Marshall /*
8274dcf55SMike Marshall  *  Linux VFS namei operations.
9274dcf55SMike Marshall  */
10274dcf55SMike Marshall 
11274dcf55SMike Marshall #include "protocol.h"
12274dcf55SMike Marshall #include "pvfs2-kernel.h"
13274dcf55SMike Marshall 
14274dcf55SMike Marshall /*
15274dcf55SMike Marshall  * Get a newly allocated inode to go with a negative dentry.
16274dcf55SMike Marshall  */
17*8bb8aefdSYi Liu static int orangefs_create(struct inode *dir,
18274dcf55SMike Marshall 			struct dentry *dentry,
19274dcf55SMike Marshall 			umode_t mode,
20274dcf55SMike Marshall 			bool exclusive)
21274dcf55SMike Marshall {
22*8bb8aefdSYi Liu 	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
23*8bb8aefdSYi Liu 	struct orangefs_kernel_op_s *new_op;
24274dcf55SMike Marshall 	struct inode *inode;
25274dcf55SMike Marshall 	int ret;
26274dcf55SMike Marshall 
27274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
28274dcf55SMike Marshall 
29*8bb8aefdSYi Liu 	new_op = op_alloc(ORANGEFS_VFS_OP_CREATE);
30274dcf55SMike Marshall 	if (!new_op)
31274dcf55SMike Marshall 		return -ENOMEM;
32274dcf55SMike Marshall 
33274dcf55SMike Marshall 	new_op->upcall.req.create.parent_refn = parent->refn;
34274dcf55SMike Marshall 
35274dcf55SMike Marshall 	fill_default_sys_attrs(new_op->upcall.req.create.attributes,
36*8bb8aefdSYi Liu 			       ORANGEFS_TYPE_METAFILE, mode);
37274dcf55SMike Marshall 
38274dcf55SMike Marshall 	strncpy(new_op->upcall.req.create.d_name,
39*8bb8aefdSYi Liu 		dentry->d_name.name, ORANGEFS_NAME_LEN);
40274dcf55SMike Marshall 
41274dcf55SMike Marshall 	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
42274dcf55SMike Marshall 
43274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
44*8bb8aefdSYi Liu 		     "Create Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
45274dcf55SMike Marshall 		     &new_op->downcall.resp.create.refn.khandle,
46274dcf55SMike Marshall 		     new_op->downcall.resp.create.refn.fs_id, ret);
47274dcf55SMike Marshall 
48274dcf55SMike Marshall 	if (ret < 0) {
49274dcf55SMike Marshall 		gossip_debug(GOSSIP_NAME_DEBUG,
50274dcf55SMike Marshall 			     "%s: failed with error code %d\n",
51274dcf55SMike Marshall 			     __func__, ret);
52274dcf55SMike Marshall 		goto out;
53274dcf55SMike Marshall 	}
54274dcf55SMike Marshall 
55*8bb8aefdSYi Liu 	inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0,
56274dcf55SMike Marshall 				&new_op->downcall.resp.create.refn);
57274dcf55SMike Marshall 	if (IS_ERR(inode)) {
58*8bb8aefdSYi Liu 		gossip_err("*** Failed to allocate orangefs file inode\n");
59274dcf55SMike Marshall 		ret = PTR_ERR(inode);
60274dcf55SMike Marshall 		goto out;
61274dcf55SMike Marshall 	}
62274dcf55SMike Marshall 
63274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
64274dcf55SMike Marshall 		     "Assigned file inode new number of %pU\n",
65274dcf55SMike Marshall 		     get_khandle_from_ino(inode));
66274dcf55SMike Marshall 
67274dcf55SMike Marshall 	d_instantiate(dentry, inode);
68274dcf55SMike Marshall 	unlock_new_inode(inode);
69274dcf55SMike Marshall 
70274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
71274dcf55SMike Marshall 		     "Inode (Regular File) %pU -> %s\n",
72274dcf55SMike Marshall 		     get_khandle_from_ino(inode),
73274dcf55SMike Marshall 		     dentry->d_name.name);
74274dcf55SMike Marshall 
75274dcf55SMike Marshall 	SetMtimeFlag(parent);
76274dcf55SMike Marshall 	dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
77274dcf55SMike Marshall 	mark_inode_dirty_sync(dir);
78274dcf55SMike Marshall 	ret = 0;
79274dcf55SMike Marshall out:
80274dcf55SMike Marshall 	op_release(new_op);
81274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG, "%s: returning %d\n", __func__, ret);
82274dcf55SMike Marshall 	return ret;
83274dcf55SMike Marshall }
84274dcf55SMike Marshall 
85274dcf55SMike Marshall /*
86274dcf55SMike Marshall  * Attempt to resolve an object name (dentry->d_name), parent handle, and
87274dcf55SMike Marshall  * fsid into a handle for the object.
88274dcf55SMike Marshall  */
89*8bb8aefdSYi Liu static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
90274dcf55SMike Marshall 				   unsigned int flags)
91274dcf55SMike Marshall {
92*8bb8aefdSYi Liu 	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
93*8bb8aefdSYi Liu 	struct orangefs_kernel_op_s *new_op;
94274dcf55SMike Marshall 	struct inode *inode;
95274dcf55SMike Marshall 	struct dentry *res;
96274dcf55SMike Marshall 	int ret = -EINVAL;
97274dcf55SMike Marshall 
98274dcf55SMike Marshall 	/*
99274dcf55SMike Marshall 	 * in theory we could skip a lookup here (if the intent is to
100274dcf55SMike Marshall 	 * create) in order to avoid a potentially failed lookup, but
101274dcf55SMike Marshall 	 * leaving it in can skip a valid lookup and try to create a file
102274dcf55SMike Marshall 	 * that already exists (e.g. the vfs already handles checking for
103274dcf55SMike Marshall 	 * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
104274dcf55SMike Marshall 	 * in the create path)
105274dcf55SMike Marshall 	 */
106274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %s\n",
107274dcf55SMike Marshall 		     __func__, dentry->d_name.name);
108274dcf55SMike Marshall 
109*8bb8aefdSYi Liu 	if (dentry->d_name.len > (ORANGEFS_NAME_LEN - 1))
110274dcf55SMike Marshall 		return ERR_PTR(-ENAMETOOLONG);
111274dcf55SMike Marshall 
112*8bb8aefdSYi Liu 	new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
113274dcf55SMike Marshall 	if (!new_op)
114274dcf55SMike Marshall 		return ERR_PTR(-ENOMEM);
115274dcf55SMike Marshall 
116274dcf55SMike Marshall 	new_op->upcall.req.lookup.sym_follow = flags & LOOKUP_FOLLOW;
117274dcf55SMike Marshall 
118274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
119274dcf55SMike Marshall 		     __FILE__,
120274dcf55SMike Marshall 		     __func__,
121274dcf55SMike Marshall 		     __LINE__,
122274dcf55SMike Marshall 		     &parent->refn.khandle);
123274dcf55SMike Marshall 	new_op->upcall.req.lookup.parent_refn = parent->refn;
124274dcf55SMike Marshall 
125274dcf55SMike Marshall 	strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
126*8bb8aefdSYi Liu 		ORANGEFS_NAME_LEN);
127274dcf55SMike Marshall 
128274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
129274dcf55SMike Marshall 		     "%s: doing lookup on %s under %pU,%d (follow=%s)\n",
130274dcf55SMike Marshall 		     __func__,
131274dcf55SMike Marshall 		     new_op->upcall.req.lookup.d_name,
132274dcf55SMike Marshall 		     &new_op->upcall.req.lookup.parent_refn.khandle,
133274dcf55SMike Marshall 		     new_op->upcall.req.lookup.parent_refn.fs_id,
134274dcf55SMike Marshall 		     ((new_op->upcall.req.lookup.sym_follow ==
135*8bb8aefdSYi Liu 		       ORANGEFS_LOOKUP_LINK_FOLLOW) ? "yes" : "no"));
136274dcf55SMike Marshall 
137274dcf55SMike Marshall 	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
138274dcf55SMike Marshall 
139274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
140274dcf55SMike Marshall 		     "Lookup Got %pU, fsid %d (ret=%d)\n",
141274dcf55SMike Marshall 		     &new_op->downcall.resp.lookup.refn.khandle,
142274dcf55SMike Marshall 		     new_op->downcall.resp.lookup.refn.fs_id,
143274dcf55SMike Marshall 		     ret);
144274dcf55SMike Marshall 
145274dcf55SMike Marshall 	if (ret < 0) {
146274dcf55SMike Marshall 		if (ret == -ENOENT) {
147274dcf55SMike Marshall 			/*
148274dcf55SMike Marshall 			 * if no inode was found, add a negative dentry to
149274dcf55SMike Marshall 			 * dcache anyway; if we don't, we don't hold expected
150274dcf55SMike Marshall 			 * lookup semantics and we most noticeably break
151274dcf55SMike Marshall 			 * during directory renames.
152274dcf55SMike Marshall 			 *
153274dcf55SMike Marshall 			 * however, if the operation failed or exited, do not
154274dcf55SMike Marshall 			 * add the dentry (e.g. in the case that a touch is
155274dcf55SMike Marshall 			 * issued on a file that already exists that was
156274dcf55SMike Marshall 			 * interrupted during this lookup -- no need to add
157274dcf55SMike Marshall 			 * another negative dentry for an existing file)
158274dcf55SMike Marshall 			 */
159274dcf55SMike Marshall 
160274dcf55SMike Marshall 			gossip_debug(GOSSIP_NAME_DEBUG,
161*8bb8aefdSYi Liu 				     "orangefs_lookup: Adding *negative* dentry "
162274dcf55SMike Marshall 				     "%p for %s\n",
163274dcf55SMike Marshall 				     dentry,
164274dcf55SMike Marshall 				     dentry->d_name.name);
165274dcf55SMike Marshall 
166274dcf55SMike Marshall 			d_add(dentry, NULL);
167274dcf55SMike Marshall 			res = NULL;
168274dcf55SMike Marshall 			goto out;
169274dcf55SMike Marshall 		}
170274dcf55SMike Marshall 
171274dcf55SMike Marshall 		/* must be a non-recoverable error */
172274dcf55SMike Marshall 		res = ERR_PTR(ret);
173274dcf55SMike Marshall 		goto out;
174274dcf55SMike Marshall 	}
175274dcf55SMike Marshall 
176*8bb8aefdSYi Liu 	inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
177274dcf55SMike Marshall 	if (IS_ERR(inode)) {
178274dcf55SMike Marshall 		gossip_debug(GOSSIP_NAME_DEBUG,
179274dcf55SMike Marshall 			"error %ld from iget\n", PTR_ERR(inode));
180274dcf55SMike Marshall 		res = ERR_CAST(inode);
181274dcf55SMike Marshall 		goto out;
182274dcf55SMike Marshall 	}
183274dcf55SMike Marshall 
184274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
185274dcf55SMike Marshall 		     "%s:%s:%d "
186274dcf55SMike Marshall 		     "Found good inode [%lu] with count [%d]\n",
187274dcf55SMike Marshall 		     __FILE__,
188274dcf55SMike Marshall 		     __func__,
189274dcf55SMike Marshall 		     __LINE__,
190274dcf55SMike Marshall 		     inode->i_ino,
191274dcf55SMike Marshall 		     (int)atomic_read(&inode->i_count));
192274dcf55SMike Marshall 
193274dcf55SMike Marshall 	/* update dentry/inode pair into dcache */
194274dcf55SMike Marshall 	res = d_splice_alias(inode, dentry);
195274dcf55SMike Marshall 
196274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
197274dcf55SMike Marshall 		     "Lookup success (inode ct = %d)\n",
198274dcf55SMike Marshall 		     (int)atomic_read(&inode->i_count));
199274dcf55SMike Marshall out:
200274dcf55SMike Marshall 	op_release(new_op);
201274dcf55SMike Marshall 	return res;
202274dcf55SMike Marshall }
203274dcf55SMike Marshall 
204274dcf55SMike Marshall /* return 0 on success; non-zero otherwise */
205*8bb8aefdSYi Liu static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
206274dcf55SMike Marshall {
207274dcf55SMike Marshall 	struct inode *inode = dentry->d_inode;
208*8bb8aefdSYi Liu 	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
209*8bb8aefdSYi Liu 	struct orangefs_kernel_op_s *new_op;
210274dcf55SMike Marshall 	int ret;
211274dcf55SMike Marshall 
212274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
213274dcf55SMike Marshall 		     "%s: called on %s\n"
214274dcf55SMike Marshall 		     "  (inode %pU): Parent is %pU | fs_id %d\n",
215274dcf55SMike Marshall 		     __func__,
216274dcf55SMike Marshall 		     dentry->d_name.name,
217274dcf55SMike Marshall 		     get_khandle_from_ino(inode),
218274dcf55SMike Marshall 		     &parent->refn.khandle,
219274dcf55SMike Marshall 		     parent->refn.fs_id);
220274dcf55SMike Marshall 
221*8bb8aefdSYi Liu 	new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
222274dcf55SMike Marshall 	if (!new_op)
223274dcf55SMike Marshall 		return -ENOMEM;
224274dcf55SMike Marshall 
225274dcf55SMike Marshall 	new_op->upcall.req.remove.parent_refn = parent->refn;
226274dcf55SMike Marshall 	strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
227*8bb8aefdSYi Liu 		ORANGEFS_NAME_LEN);
228274dcf55SMike Marshall 
229*8bb8aefdSYi Liu 	ret = service_operation(new_op, "orangefs_unlink",
230274dcf55SMike Marshall 				get_interruptible_flag(inode));
231274dcf55SMike Marshall 
232274dcf55SMike Marshall 	/* when request is serviced properly, free req op struct */
233274dcf55SMike Marshall 	op_release(new_op);
234274dcf55SMike Marshall 
235274dcf55SMike Marshall 	if (!ret) {
236274dcf55SMike Marshall 		drop_nlink(inode);
237274dcf55SMike Marshall 
238274dcf55SMike Marshall 		SetMtimeFlag(parent);
239274dcf55SMike Marshall 		dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
240274dcf55SMike Marshall 		mark_inode_dirty_sync(dir);
241274dcf55SMike Marshall 	}
242274dcf55SMike Marshall 	return ret;
243274dcf55SMike Marshall }
244274dcf55SMike Marshall 
245*8bb8aefdSYi Liu static int orangefs_symlink(struct inode *dir,
246274dcf55SMike Marshall 			 struct dentry *dentry,
247274dcf55SMike Marshall 			 const char *symname)
248274dcf55SMike Marshall {
249*8bb8aefdSYi Liu 	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
250*8bb8aefdSYi Liu 	struct orangefs_kernel_op_s *new_op;
251274dcf55SMike Marshall 	struct inode *inode;
252274dcf55SMike Marshall 	int mode = 755;
253274dcf55SMike Marshall 	int ret;
254274dcf55SMike Marshall 
255274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
256274dcf55SMike Marshall 
257274dcf55SMike Marshall 	if (!symname)
258274dcf55SMike Marshall 		return -EINVAL;
259274dcf55SMike Marshall 
260*8bb8aefdSYi Liu 	new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
261274dcf55SMike Marshall 	if (!new_op)
262274dcf55SMike Marshall 		return -ENOMEM;
263274dcf55SMike Marshall 
264274dcf55SMike Marshall 	new_op->upcall.req.sym.parent_refn = parent->refn;
265274dcf55SMike Marshall 
266274dcf55SMike Marshall 	fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
267*8bb8aefdSYi Liu 			       ORANGEFS_TYPE_SYMLINK,
268274dcf55SMike Marshall 			       mode);
269274dcf55SMike Marshall 
270274dcf55SMike Marshall 	strncpy(new_op->upcall.req.sym.entry_name,
271274dcf55SMike Marshall 		dentry->d_name.name,
272*8bb8aefdSYi Liu 		ORANGEFS_NAME_LEN);
273*8bb8aefdSYi Liu 	strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_LEN);
274274dcf55SMike Marshall 
275274dcf55SMike Marshall 	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
276274dcf55SMike Marshall 
277274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
278*8bb8aefdSYi Liu 		     "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
279274dcf55SMike Marshall 		     &new_op->downcall.resp.sym.refn.khandle,
280274dcf55SMike Marshall 		     new_op->downcall.resp.sym.refn.fs_id, ret);
281274dcf55SMike Marshall 
282274dcf55SMike Marshall 	if (ret < 0) {
283274dcf55SMike Marshall 		gossip_debug(GOSSIP_NAME_DEBUG,
284274dcf55SMike Marshall 			    "%s: failed with error code %d\n",
285274dcf55SMike Marshall 			    __func__, ret);
286274dcf55SMike Marshall 		goto out;
287274dcf55SMike Marshall 	}
288274dcf55SMike Marshall 
289*8bb8aefdSYi Liu 	inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0,
290274dcf55SMike Marshall 				&new_op->downcall.resp.sym.refn);
291274dcf55SMike Marshall 	if (IS_ERR(inode)) {
292274dcf55SMike Marshall 		gossip_err
293*8bb8aefdSYi Liu 		    ("*** Failed to allocate orangefs symlink inode\n");
294274dcf55SMike Marshall 		ret = PTR_ERR(inode);
295274dcf55SMike Marshall 		goto out;
296274dcf55SMike Marshall 	}
297274dcf55SMike Marshall 
298274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
299274dcf55SMike Marshall 		     "Assigned symlink inode new number of %pU\n",
300274dcf55SMike Marshall 		     get_khandle_from_ino(inode));
301274dcf55SMike Marshall 
302274dcf55SMike Marshall 	d_instantiate(dentry, inode);
303274dcf55SMike Marshall 	unlock_new_inode(inode);
304274dcf55SMike Marshall 
305274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
306274dcf55SMike Marshall 		     "Inode (Symlink) %pU -> %s\n",
307274dcf55SMike Marshall 		     get_khandle_from_ino(inode),
308274dcf55SMike Marshall 		     dentry->d_name.name);
309274dcf55SMike Marshall 
310274dcf55SMike Marshall 	SetMtimeFlag(parent);
311274dcf55SMike Marshall 	dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
312274dcf55SMike Marshall 	mark_inode_dirty_sync(dir);
313274dcf55SMike Marshall 	ret = 0;
314274dcf55SMike Marshall out:
315274dcf55SMike Marshall 	op_release(new_op);
316274dcf55SMike Marshall 	return ret;
317274dcf55SMike Marshall }
318274dcf55SMike Marshall 
319*8bb8aefdSYi Liu static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
320274dcf55SMike Marshall {
321*8bb8aefdSYi Liu 	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
322*8bb8aefdSYi Liu 	struct orangefs_kernel_op_s *new_op;
323274dcf55SMike Marshall 	struct inode *inode;
324274dcf55SMike Marshall 	int ret;
325274dcf55SMike Marshall 
326*8bb8aefdSYi Liu 	new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
327274dcf55SMike Marshall 	if (!new_op)
328274dcf55SMike Marshall 		return -ENOMEM;
329274dcf55SMike Marshall 
330274dcf55SMike Marshall 	new_op->upcall.req.mkdir.parent_refn = parent->refn;
331274dcf55SMike Marshall 
332274dcf55SMike Marshall 	fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
333*8bb8aefdSYi Liu 			      ORANGEFS_TYPE_DIRECTORY, mode);
334274dcf55SMike Marshall 
335274dcf55SMike Marshall 	strncpy(new_op->upcall.req.mkdir.d_name,
336*8bb8aefdSYi Liu 		dentry->d_name.name, ORANGEFS_NAME_LEN);
337274dcf55SMike Marshall 
338274dcf55SMike Marshall 	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
339274dcf55SMike Marshall 
340274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
341*8bb8aefdSYi Liu 		     "Mkdir Got ORANGEFS handle %pU on fsid %d\n",
342274dcf55SMike Marshall 		     &new_op->downcall.resp.mkdir.refn.khandle,
343274dcf55SMike Marshall 		     new_op->downcall.resp.mkdir.refn.fs_id);
344274dcf55SMike Marshall 
345274dcf55SMike Marshall 	if (ret < 0) {
346274dcf55SMike Marshall 		gossip_debug(GOSSIP_NAME_DEBUG,
347274dcf55SMike Marshall 			     "%s: failed with error code %d\n",
348274dcf55SMike Marshall 			     __func__, ret);
349274dcf55SMike Marshall 		goto out;
350274dcf55SMike Marshall 	}
351274dcf55SMike Marshall 
352*8bb8aefdSYi Liu 	inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0,
353274dcf55SMike Marshall 				&new_op->downcall.resp.mkdir.refn);
354274dcf55SMike Marshall 	if (IS_ERR(inode)) {
355*8bb8aefdSYi Liu 		gossip_err("*** Failed to allocate orangefs dir inode\n");
356274dcf55SMike Marshall 		ret = PTR_ERR(inode);
357274dcf55SMike Marshall 		goto out;
358274dcf55SMike Marshall 	}
359274dcf55SMike Marshall 
360274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
361274dcf55SMike Marshall 		     "Assigned dir inode new number of %pU\n",
362274dcf55SMike Marshall 		     get_khandle_from_ino(inode));
363274dcf55SMike Marshall 
364274dcf55SMike Marshall 	d_instantiate(dentry, inode);
365274dcf55SMike Marshall 	unlock_new_inode(inode);
366274dcf55SMike Marshall 
367274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
368274dcf55SMike Marshall 		     "Inode (Directory) %pU -> %s\n",
369274dcf55SMike Marshall 		     get_khandle_from_ino(inode),
370274dcf55SMike Marshall 		     dentry->d_name.name);
371274dcf55SMike Marshall 
372274dcf55SMike Marshall 	/*
373274dcf55SMike Marshall 	 * NOTE: we have no good way to keep nlink consistent for directories
374274dcf55SMike Marshall 	 * across clients; keep constant at 1.
375274dcf55SMike Marshall 	 */
376274dcf55SMike Marshall 	SetMtimeFlag(parent);
377274dcf55SMike Marshall 	dir->i_mtime = dir->i_ctime = current_fs_time(dir->i_sb);
378274dcf55SMike Marshall 	mark_inode_dirty_sync(dir);
379274dcf55SMike Marshall out:
380274dcf55SMike Marshall 	op_release(new_op);
381274dcf55SMike Marshall 	return ret;
382274dcf55SMike Marshall }
383274dcf55SMike Marshall 
384*8bb8aefdSYi Liu static int orangefs_rename(struct inode *old_dir,
385274dcf55SMike Marshall 			struct dentry *old_dentry,
386274dcf55SMike Marshall 			struct inode *new_dir,
387274dcf55SMike Marshall 			struct dentry *new_dentry)
388274dcf55SMike Marshall {
389*8bb8aefdSYi Liu 	struct orangefs_kernel_op_s *new_op;
390274dcf55SMike Marshall 	int ret;
391274dcf55SMike Marshall 
392274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
393*8bb8aefdSYi Liu 		     "orangefs_rename: called (%s/%s => %s/%s) ct=%d\n",
394274dcf55SMike Marshall 		     old_dentry->d_parent->d_name.name,
395274dcf55SMike Marshall 		     old_dentry->d_name.name,
396274dcf55SMike Marshall 		     new_dentry->d_parent->d_name.name,
397274dcf55SMike Marshall 		     new_dentry->d_name.name,
398274dcf55SMike Marshall 		     d_count(new_dentry));
399274dcf55SMike Marshall 
400*8bb8aefdSYi Liu 	new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
401274dcf55SMike Marshall 	if (!new_op)
402274dcf55SMike Marshall 		return -EINVAL;
403274dcf55SMike Marshall 
404*8bb8aefdSYi Liu 	new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn;
405*8bb8aefdSYi Liu 	new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn;
406274dcf55SMike Marshall 
407274dcf55SMike Marshall 	strncpy(new_op->upcall.req.rename.d_old_name,
408274dcf55SMike Marshall 		old_dentry->d_name.name,
409*8bb8aefdSYi Liu 		ORANGEFS_NAME_LEN);
410274dcf55SMike Marshall 	strncpy(new_op->upcall.req.rename.d_new_name,
411274dcf55SMike Marshall 		new_dentry->d_name.name,
412*8bb8aefdSYi Liu 		ORANGEFS_NAME_LEN);
413274dcf55SMike Marshall 
414274dcf55SMike Marshall 	ret = service_operation(new_op,
415*8bb8aefdSYi Liu 				"orangefs_rename",
416274dcf55SMike Marshall 				get_interruptible_flag(old_dentry->d_inode));
417274dcf55SMike Marshall 
418274dcf55SMike Marshall 	gossip_debug(GOSSIP_NAME_DEBUG,
419*8bb8aefdSYi Liu 		     "orangefs_rename: got downcall status %d\n",
420274dcf55SMike Marshall 		     ret);
421274dcf55SMike Marshall 
422274dcf55SMike Marshall 	if (new_dentry->d_inode)
423274dcf55SMike Marshall 		new_dentry->d_inode->i_ctime = CURRENT_TIME;
424274dcf55SMike Marshall 
425274dcf55SMike Marshall 	op_release(new_op);
426274dcf55SMike Marshall 	return ret;
427274dcf55SMike Marshall }
428274dcf55SMike Marshall 
429*8bb8aefdSYi Liu /* ORANGEFS implementation of VFS inode operations for directories */
430*8bb8aefdSYi Liu struct inode_operations orangefs_dir_inode_operations = {
431*8bb8aefdSYi Liu 	.lookup = orangefs_lookup,
432*8bb8aefdSYi Liu 	.get_acl = orangefs_get_acl,
433*8bb8aefdSYi Liu 	.set_acl = orangefs_set_acl,
434*8bb8aefdSYi Liu 	.create = orangefs_create,
435*8bb8aefdSYi Liu 	.unlink = orangefs_unlink,
436*8bb8aefdSYi Liu 	.symlink = orangefs_symlink,
437*8bb8aefdSYi Liu 	.mkdir = orangefs_mkdir,
438*8bb8aefdSYi Liu 	.rmdir = orangefs_unlink,
439*8bb8aefdSYi Liu 	.rename = orangefs_rename,
440*8bb8aefdSYi Liu 	.setattr = orangefs_setattr,
441*8bb8aefdSYi Liu 	.getattr = orangefs_getattr,
442274dcf55SMike Marshall 	.setxattr = generic_setxattr,
443274dcf55SMike Marshall 	.getxattr = generic_getxattr,
444274dcf55SMike Marshall 	.removexattr = generic_removexattr,
445*8bb8aefdSYi Liu 	.listxattr = orangefs_listxattr,
446274dcf55SMike Marshall };
447