1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2274dcf55SMike Marshall /*
3274dcf55SMike Marshall * (C) 2001 Clemson University and The University of Chicago
4274dcf55SMike Marshall *
5274dcf55SMike Marshall * See COPYING in top-level directory.
6274dcf55SMike Marshall */
7274dcf55SMike Marshall
8274dcf55SMike Marshall /*
9274dcf55SMike Marshall * Linux VFS namei operations.
10274dcf55SMike Marshall */
11274dcf55SMike Marshall
12274dcf55SMike Marshall #include "protocol.h"
13575e9461SMike Marshall #include "orangefs-kernel.h"
14274dcf55SMike Marshall
15274dcf55SMike Marshall /*
16274dcf55SMike Marshall * Get a newly allocated inode to go with a negative dentry.
17274dcf55SMike Marshall */
orangefs_create(struct mnt_idmap * idmap,struct inode * dir,struct dentry * dentry,umode_t mode,bool exclusive)186c960e68SChristian Brauner static int orangefs_create(struct mnt_idmap *idmap,
19549c7297SChristian Brauner struct inode *dir,
20274dcf55SMike Marshall struct dentry *dentry,
21274dcf55SMike Marshall umode_t mode,
22274dcf55SMike Marshall bool exclusive)
23274dcf55SMike Marshall {
248bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir);
258bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op;
26db0267e7SMartin Brandenburg struct orangefs_object_kref ref;
27274dcf55SMike Marshall struct inode *inode;
28a55f2d86SMartin Brandenburg struct iattr iattr;
29274dcf55SMike Marshall int ret;
30274dcf55SMike Marshall
31f66debf1SAl Viro gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd\n",
325253487eSMike Marshall __func__,
33f66debf1SAl Viro dentry);
34274dcf55SMike Marshall
358bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_CREATE);
36274dcf55SMike Marshall if (!new_op)
37274dcf55SMike Marshall return -ENOMEM;
38274dcf55SMike Marshall
39274dcf55SMike Marshall new_op->upcall.req.create.parent_refn = parent->refn;
40274dcf55SMike Marshall
41274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.create.attributes,
428bb8aefdSYi Liu ORANGEFS_TYPE_METAFILE, mode);
43274dcf55SMike Marshall
44274dcf55SMike Marshall strncpy(new_op->upcall.req.create.d_name,
456bdfb48dSXiongfeng Wang dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
46274dcf55SMike Marshall
47274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
48274dcf55SMike Marshall
49274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
50f66debf1SAl Viro "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n",
515253487eSMike Marshall __func__,
52f66debf1SAl Viro dentry,
53274dcf55SMike Marshall &new_op->downcall.resp.create.refn.khandle,
545253487eSMike Marshall new_op->downcall.resp.create.refn.fs_id,
555253487eSMike Marshall new_op,
565253487eSMike Marshall ret);
57274dcf55SMike Marshall
585253487eSMike Marshall if (ret < 0)
59274dcf55SMike Marshall goto out;
60274dcf55SMike Marshall
61db0267e7SMartin Brandenburg ref = new_op->downcall.resp.create.refn;
62db0267e7SMartin Brandenburg
63db0267e7SMartin Brandenburg inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, &ref);
64274dcf55SMike Marshall if (IS_ERR(inode)) {
65f66debf1SAl Viro gossip_err("%s: Failed to allocate inode for file :%pd:\n",
665253487eSMike Marshall __func__,
67f66debf1SAl Viro dentry);
68274dcf55SMike Marshall ret = PTR_ERR(inode);
69274dcf55SMike Marshall goto out;
70274dcf55SMike Marshall }
71274dcf55SMike Marshall
72274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
73f66debf1SAl Viro "%s: Assigned inode :%pU: for file :%pd:\n",
745253487eSMike Marshall __func__,
755253487eSMike Marshall get_khandle_from_ino(inode),
76f66debf1SAl Viro dentry);
77274dcf55SMike Marshall
781e2e547aSAl Viro d_instantiate_new(dentry, inode);
79804b1737SMiklos Szeredi orangefs_set_timeout(dentry);
80274dcf55SMike Marshall
81274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
82f66debf1SAl Viro "%s: dentry instantiated for %pd\n",
835253487eSMike Marshall __func__,
84f66debf1SAl Viro dentry);
85274dcf55SMike Marshall
86a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr);
87afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
88afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
89afd9fb2aSMartin Brandenburg __orangefs_setattr(dir, &iattr);
90274dcf55SMike Marshall ret = 0;
91274dcf55SMike Marshall out:
9234e6148aSMike Marshall op_release(new_op);
935253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
94f66debf1SAl Viro "%s: %pd: returning %d\n",
955253487eSMike Marshall __func__,
96f66debf1SAl Viro dentry,
975253487eSMike Marshall ret);
98274dcf55SMike Marshall return ret;
99274dcf55SMike Marshall }
100274dcf55SMike Marshall
101274dcf55SMike Marshall /*
102274dcf55SMike Marshall * Attempt to resolve an object name (dentry->d_name), parent handle, and
103274dcf55SMike Marshall * fsid into a handle for the object.
104274dcf55SMike Marshall */
orangefs_lookup(struct inode * dir,struct dentry * dentry,unsigned int flags)1058bb8aefdSYi Liu static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
106274dcf55SMike Marshall unsigned int flags)
107274dcf55SMike Marshall {
1088bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir);
1098bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op;
110274dcf55SMike Marshall struct inode *inode;
111274dcf55SMike Marshall int ret = -EINVAL;
112274dcf55SMike Marshall
113274dcf55SMike Marshall /*
114274dcf55SMike Marshall * in theory we could skip a lookup here (if the intent is to
115274dcf55SMike Marshall * create) in order to avoid a potentially failed lookup, but
116274dcf55SMike Marshall * leaving it in can skip a valid lookup and try to create a file
117274dcf55SMike Marshall * that already exists (e.g. the vfs already handles checking for
118274dcf55SMike Marshall * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
119274dcf55SMike Marshall * in the create path)
120274dcf55SMike Marshall */
121f66debf1SAl Viro gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n",
122f66debf1SAl Viro __func__, dentry);
123274dcf55SMike Marshall
12447b4948fSMartin Brandenburg if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1))
125274dcf55SMike Marshall return ERR_PTR(-ENAMETOOLONG);
126274dcf55SMike Marshall
1278bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
128274dcf55SMike Marshall if (!new_op)
129274dcf55SMike Marshall return ERR_PTR(-ENOMEM);
130274dcf55SMike Marshall
1317cec28e9SMike Marshall new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
132274dcf55SMike Marshall
133274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
134274dcf55SMike Marshall __FILE__,
135274dcf55SMike Marshall __func__,
136274dcf55SMike Marshall __LINE__,
137274dcf55SMike Marshall &parent->refn.khandle);
138274dcf55SMike Marshall new_op->upcall.req.lookup.parent_refn = parent->refn;
139274dcf55SMike Marshall
140274dcf55SMike Marshall strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
1416bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1);
142274dcf55SMike Marshall
143274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
1446ceaf781SMartin Brandenburg "%s: doing lookup on %s under %pU,%d\n",
145274dcf55SMike Marshall __func__,
146274dcf55SMike Marshall new_op->upcall.req.lookup.d_name,
147274dcf55SMike Marshall &new_op->upcall.req.lookup.parent_refn.khandle,
1486ceaf781SMartin Brandenburg new_op->upcall.req.lookup.parent_refn.fs_id);
149274dcf55SMike Marshall
150274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
151274dcf55SMike Marshall
152274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
153274dcf55SMike Marshall "Lookup Got %pU, fsid %d (ret=%d)\n",
154274dcf55SMike Marshall &new_op->downcall.resp.lookup.refn.khandle,
155274dcf55SMike Marshall new_op->downcall.resp.lookup.refn.fs_id,
156274dcf55SMike Marshall ret);
157274dcf55SMike Marshall
15822fc9db2SMike Marshall if (ret == 0) {
159804b1737SMiklos Szeredi orangefs_set_timeout(dentry);
1608bb8aefdSYi Liu inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
16104bb1ba1SAl Viro } else if (ret == -ENOENT) {
16204bb1ba1SAl Viro inode = NULL;
16304bb1ba1SAl Viro } else {
16404bb1ba1SAl Viro /* must be a non-recoverable error */
16504bb1ba1SAl Viro inode = ERR_PTR(ret);
166274dcf55SMike Marshall }
167274dcf55SMike Marshall
168274dcf55SMike Marshall op_release(new_op);
16904bb1ba1SAl Viro return d_splice_alias(inode, dentry);
170274dcf55SMike Marshall }
171274dcf55SMike Marshall
172274dcf55SMike Marshall /* return 0 on success; non-zero otherwise */
orangefs_unlink(struct inode * dir,struct dentry * dentry)1738bb8aefdSYi Liu static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
174274dcf55SMike Marshall {
175274dcf55SMike Marshall struct inode *inode = dentry->d_inode;
1768bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir);
1778bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op;
178a55f2d86SMartin Brandenburg struct iattr iattr;
179274dcf55SMike Marshall int ret;
180274dcf55SMike Marshall
181274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
182f66debf1SAl Viro "%s: called on %pd\n"
183274dcf55SMike Marshall " (inode %pU): Parent is %pU | fs_id %d\n",
184274dcf55SMike Marshall __func__,
185f66debf1SAl Viro dentry,
186274dcf55SMike Marshall get_khandle_from_ino(inode),
187274dcf55SMike Marshall &parent->refn.khandle,
188274dcf55SMike Marshall parent->refn.fs_id);
189274dcf55SMike Marshall
1908bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
191274dcf55SMike Marshall if (!new_op)
192274dcf55SMike Marshall return -ENOMEM;
193274dcf55SMike Marshall
194274dcf55SMike Marshall new_op->upcall.req.remove.parent_refn = parent->refn;
195274dcf55SMike Marshall strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
1966bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1);
197274dcf55SMike Marshall
1988bb8aefdSYi Liu ret = service_operation(new_op, "orangefs_unlink",
199274dcf55SMike Marshall get_interruptible_flag(inode));
200274dcf55SMike Marshall
2015253487eSMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
2025253487eSMike Marshall "%s: service_operation returned:%d:\n",
2035253487eSMike Marshall __func__,
2045253487eSMike Marshall ret);
2055253487eSMike Marshall
206274dcf55SMike Marshall op_release(new_op);
207274dcf55SMike Marshall
208274dcf55SMike Marshall if (!ret) {
209274dcf55SMike Marshall drop_nlink(inode);
210274dcf55SMike Marshall
211a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr);
212afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
213afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
214afd9fb2aSMartin Brandenburg __orangefs_setattr(dir, &iattr);
215274dcf55SMike Marshall }
216274dcf55SMike Marshall return ret;
217274dcf55SMike Marshall }
218274dcf55SMike Marshall
orangefs_symlink(struct mnt_idmap * idmap,struct inode * dir,struct dentry * dentry,const char * symname)2197a77db95SChristian Brauner static int orangefs_symlink(struct mnt_idmap *idmap,
220549c7297SChristian Brauner struct inode *dir,
221274dcf55SMike Marshall struct dentry *dentry,
222274dcf55SMike Marshall const char *symname)
223274dcf55SMike Marshall {
2248bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir);
2258bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op;
226db0267e7SMartin Brandenburg struct orangefs_object_kref ref;
227274dcf55SMike Marshall struct inode *inode;
228a55f2d86SMartin Brandenburg struct iattr iattr;
229c42293a9SArtur Świgoń int mode = 0755;
230274dcf55SMike Marshall int ret;
231274dcf55SMike Marshall
232274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
233274dcf55SMike Marshall
234274dcf55SMike Marshall if (!symname)
235274dcf55SMike Marshall return -EINVAL;
236274dcf55SMike Marshall
237c62da585SMartin Brandenburg if (strlen(symname)+1 > ORANGEFS_NAME_MAX)
238c62da585SMartin Brandenburg return -ENAMETOOLONG;
239c62da585SMartin Brandenburg
2408bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
241274dcf55SMike Marshall if (!new_op)
242274dcf55SMike Marshall return -ENOMEM;
243274dcf55SMike Marshall
244274dcf55SMike Marshall new_op->upcall.req.sym.parent_refn = parent->refn;
245274dcf55SMike Marshall
246274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
2478bb8aefdSYi Liu ORANGEFS_TYPE_SYMLINK,
248274dcf55SMike Marshall mode);
249274dcf55SMike Marshall
250274dcf55SMike Marshall strncpy(new_op->upcall.req.sym.entry_name,
251274dcf55SMike Marshall dentry->d_name.name,
2526bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1);
2536bdfb48dSXiongfeng Wang strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX - 1);
254274dcf55SMike Marshall
255274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
256274dcf55SMike Marshall
257274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
2588bb8aefdSYi Liu "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
259274dcf55SMike Marshall &new_op->downcall.resp.sym.refn.khandle,
260274dcf55SMike Marshall new_op->downcall.resp.sym.refn.fs_id, ret);
261274dcf55SMike Marshall
262274dcf55SMike Marshall if (ret < 0) {
263274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
264274dcf55SMike Marshall "%s: failed with error code %d\n",
265274dcf55SMike Marshall __func__, ret);
266274dcf55SMike Marshall goto out;
267274dcf55SMike Marshall }
268274dcf55SMike Marshall
269db0267e7SMartin Brandenburg ref = new_op->downcall.resp.sym.refn;
270db0267e7SMartin Brandenburg
271db0267e7SMartin Brandenburg inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref);
272274dcf55SMike Marshall if (IS_ERR(inode)) {
273274dcf55SMike Marshall gossip_err
2748bb8aefdSYi Liu ("*** Failed to allocate orangefs symlink inode\n");
275274dcf55SMike Marshall ret = PTR_ERR(inode);
276274dcf55SMike Marshall goto out;
277274dcf55SMike Marshall }
278f6a4b4c9SMartin Brandenburg /*
279f6a4b4c9SMartin Brandenburg * This is necessary because orangefs_inode_getattr will not
280f6a4b4c9SMartin Brandenburg * re-read symlink size as it is impossible for it to change.
281f6a4b4c9SMartin Brandenburg * Invalidating the cache does not help. orangefs_new_inode
282f6a4b4c9SMartin Brandenburg * does not set the correct size (it does not know symname).
283f6a4b4c9SMartin Brandenburg */
284f6a4b4c9SMartin Brandenburg inode->i_size = strlen(symname);
285274dcf55SMike Marshall
286274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
287274dcf55SMike Marshall "Assigned symlink inode new number of %pU\n",
288274dcf55SMike Marshall get_khandle_from_ino(inode));
289274dcf55SMike Marshall
2901e2e547aSAl Viro d_instantiate_new(dentry, inode);
291804b1737SMiklos Szeredi orangefs_set_timeout(dentry);
292274dcf55SMike Marshall
293274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
294f66debf1SAl Viro "Inode (Symlink) %pU -> %pd\n",
295274dcf55SMike Marshall get_khandle_from_ino(inode),
296f66debf1SAl Viro dentry);
297274dcf55SMike Marshall
298a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr);
299afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
300afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
301afd9fb2aSMartin Brandenburg __orangefs_setattr(dir, &iattr);
302274dcf55SMike Marshall ret = 0;
303274dcf55SMike Marshall out:
30434e6148aSMike Marshall op_release(new_op);
305274dcf55SMike Marshall return ret;
306274dcf55SMike Marshall }
307274dcf55SMike Marshall
orangefs_mkdir(struct mnt_idmap * idmap,struct inode * dir,struct dentry * dentry,umode_t mode)308c54bd91eSChristian Brauner static int orangefs_mkdir(struct mnt_idmap *idmap, struct inode *dir,
309549c7297SChristian Brauner struct dentry *dentry, umode_t mode)
310274dcf55SMike Marshall {
3118bb8aefdSYi Liu struct orangefs_inode_s *parent = ORANGEFS_I(dir);
3128bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op;
313db0267e7SMartin Brandenburg struct orangefs_object_kref ref;
314274dcf55SMike Marshall struct inode *inode;
315a55f2d86SMartin Brandenburg struct iattr iattr;
316274dcf55SMike Marshall int ret;
317274dcf55SMike Marshall
3188bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
319274dcf55SMike Marshall if (!new_op)
320274dcf55SMike Marshall return -ENOMEM;
321274dcf55SMike Marshall
322274dcf55SMike Marshall new_op->upcall.req.mkdir.parent_refn = parent->refn;
323274dcf55SMike Marshall
324274dcf55SMike Marshall fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
3258bb8aefdSYi Liu ORANGEFS_TYPE_DIRECTORY, mode);
326274dcf55SMike Marshall
327274dcf55SMike Marshall strncpy(new_op->upcall.req.mkdir.d_name,
3286bdfb48dSXiongfeng Wang dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
329274dcf55SMike Marshall
330274dcf55SMike Marshall ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
331274dcf55SMike Marshall
332274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
3338bb8aefdSYi Liu "Mkdir Got ORANGEFS handle %pU on fsid %d\n",
334274dcf55SMike Marshall &new_op->downcall.resp.mkdir.refn.khandle,
335274dcf55SMike Marshall new_op->downcall.resp.mkdir.refn.fs_id);
336274dcf55SMike Marshall
337274dcf55SMike Marshall if (ret < 0) {
338274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
339274dcf55SMike Marshall "%s: failed with error code %d\n",
340274dcf55SMike Marshall __func__, ret);
341274dcf55SMike Marshall goto out;
342274dcf55SMike Marshall }
343274dcf55SMike Marshall
344db0267e7SMartin Brandenburg ref = new_op->downcall.resp.mkdir.refn;
345db0267e7SMartin Brandenburg
346db0267e7SMartin Brandenburg inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref);
347274dcf55SMike Marshall if (IS_ERR(inode)) {
3488bb8aefdSYi Liu gossip_err("*** Failed to allocate orangefs dir inode\n");
349274dcf55SMike Marshall ret = PTR_ERR(inode);
350274dcf55SMike Marshall goto out;
351274dcf55SMike Marshall }
352274dcf55SMike Marshall
353274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
354274dcf55SMike Marshall "Assigned dir inode new number of %pU\n",
355274dcf55SMike Marshall get_khandle_from_ino(inode));
356274dcf55SMike Marshall
3571e2e547aSAl Viro d_instantiate_new(dentry, inode);
358804b1737SMiklos Szeredi orangefs_set_timeout(dentry);
359274dcf55SMike Marshall
360274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
361f66debf1SAl Viro "Inode (Directory) %pU -> %pd\n",
362274dcf55SMike Marshall get_khandle_from_ino(inode),
363f66debf1SAl Viro dentry);
364274dcf55SMike Marshall
365274dcf55SMike Marshall /*
366274dcf55SMike Marshall * NOTE: we have no good way to keep nlink consistent for directories
367274dcf55SMike Marshall * across clients; keep constant at 1.
368274dcf55SMike Marshall */
369a55f2d86SMartin Brandenburg memset(&iattr, 0, sizeof iattr);
370afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
371afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
372afd9fb2aSMartin Brandenburg __orangefs_setattr(dir, &iattr);
373274dcf55SMike Marshall out:
37434e6148aSMike Marshall op_release(new_op);
375274dcf55SMike Marshall return ret;
376274dcf55SMike Marshall }
377274dcf55SMike Marshall
orangefs_rename(struct mnt_idmap * idmap,struct inode * old_dir,struct dentry * old_dentry,struct inode * new_dir,struct dentry * new_dentry,unsigned int flags)378e18275aeSChristian Brauner static int orangefs_rename(struct mnt_idmap *idmap,
379549c7297SChristian Brauner struct inode *old_dir,
380274dcf55SMike Marshall struct dentry *old_dentry,
381274dcf55SMike Marshall struct inode *new_dir,
3821cd66c93SMiklos Szeredi struct dentry *new_dentry,
3831cd66c93SMiklos Szeredi unsigned int flags)
384274dcf55SMike Marshall {
3858bb8aefdSYi Liu struct orangefs_kernel_op_s *new_op;
3865e7f1d43SMartin Brandenburg struct iattr iattr;
387274dcf55SMike Marshall int ret;
388274dcf55SMike Marshall
3891cd66c93SMiklos Szeredi if (flags)
3901cd66c93SMiklos Szeredi return -EINVAL;
3911cd66c93SMiklos Szeredi
392274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
39396b0cffbSAl Viro "orangefs_rename: called (%pd2 => %pd2) ct=%d\n",
39496b0cffbSAl Viro old_dentry, new_dentry, d_count(new_dentry));
395274dcf55SMike Marshall
3965e7f1d43SMartin Brandenburg memset(&iattr, 0, sizeof iattr);
397afd9fb2aSMartin Brandenburg iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
398afd9fb2aSMartin Brandenburg iattr.ia_mtime = iattr.ia_ctime = current_time(new_dir);
399afd9fb2aSMartin Brandenburg __orangefs_setattr(new_dir, &iattr);
40071680c18SMartin Brandenburg
4018bb8aefdSYi Liu new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
402274dcf55SMike Marshall if (!new_op)
403274dcf55SMike Marshall return -EINVAL;
404274dcf55SMike Marshall
4058bb8aefdSYi Liu new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn;
4068bb8aefdSYi Liu new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn;
407274dcf55SMike Marshall
408274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_old_name,
409274dcf55SMike Marshall old_dentry->d_name.name,
4106bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1);
411274dcf55SMike Marshall strncpy(new_op->upcall.req.rename.d_new_name,
412274dcf55SMike Marshall new_dentry->d_name.name,
4136bdfb48dSXiongfeng Wang ORANGEFS_NAME_MAX - 1);
414274dcf55SMike Marshall
415274dcf55SMike Marshall ret = service_operation(new_op,
4168bb8aefdSYi Liu "orangefs_rename",
417274dcf55SMike Marshall get_interruptible_flag(old_dentry->d_inode));
418274dcf55SMike Marshall
419274dcf55SMike Marshall gossip_debug(GOSSIP_NAME_DEBUG,
4208bb8aefdSYi Liu "orangefs_rename: got downcall status %d\n",
421274dcf55SMike Marshall ret);
422274dcf55SMike Marshall
423274dcf55SMike Marshall if (new_dentry->d_inode)
424*0971a799SJeff Layton inode_set_ctime_current(d_inode(new_dentry));
425274dcf55SMike Marshall
426274dcf55SMike Marshall op_release(new_op);
427274dcf55SMike Marshall return ret;
428274dcf55SMike Marshall }
429274dcf55SMike Marshall
4308bb8aefdSYi Liu /* ORANGEFS implementation of VFS inode operations for directories */
4316f3fc107SAl Viro const struct inode_operations orangefs_dir_inode_operations = {
4328bb8aefdSYi Liu .lookup = orangefs_lookup,
433cac2f8b8SChristian Brauner .get_inode_acl = orangefs_get_acl,
4348bb8aefdSYi Liu .set_acl = orangefs_set_acl,
4358bb8aefdSYi Liu .create = orangefs_create,
4368bb8aefdSYi Liu .unlink = orangefs_unlink,
4378bb8aefdSYi Liu .symlink = orangefs_symlink,
4388bb8aefdSYi Liu .mkdir = orangefs_mkdir,
4398bb8aefdSYi Liu .rmdir = orangefs_unlink,
4408bb8aefdSYi Liu .rename = orangefs_rename,
4418bb8aefdSYi Liu .setattr = orangefs_setattr,
4428bb8aefdSYi Liu .getattr = orangefs_getattr,
4438bb8aefdSYi Liu .listxattr = orangefs_listxattr,
444933287daSMartin Brandenburg .permission = orangefs_permission,
445a55f2d86SMartin Brandenburg .update_time = orangefs_update_time,
446274dcf55SMike Marshall };
447