blob: 600e8eee541fba422f33f24161f6bf72a8982650 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Mike Marshall274dcf52015-07-17 10:38:13 -04002/*
3 * (C) 2001 Clemson University and The University of Chicago
4 *
5 * See COPYING in top-level directory.
6 */
7
8/*
9 * Linux VFS namei operations.
10 */
11
12#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -050013#include "orangefs-kernel.h"
Mike Marshall274dcf52015-07-17 10:38:13 -040014
15/*
16 * Get a newly allocated inode to go with a negative dentry.
17 */
Christian Brauner549c7292021-01-21 14:19:43 +010018static int orangefs_create(struct user_namespace *mnt_userns,
19 struct inode *dir,
Mike Marshall274dcf52015-07-17 10:38:13 -040020 struct dentry *dentry,
21 umode_t mode,
22 bool exclusive)
23{
Yi Liu8bb8aef2015-11-24 15:12:14 -050024 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
25 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -050026 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -040027 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -050028 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -040029 int ret;
30
Al Virof66debf2016-08-07 12:20:01 -040031 gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd\n",
Mike Marshall52534872016-02-16 17:09:09 -050032 __func__,
Al Virof66debf2016-08-07 12:20:01 -040033 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040034
Yi Liu8bb8aef2015-11-24 15:12:14 -050035 new_op = op_alloc(ORANGEFS_VFS_OP_CREATE);
Mike Marshall274dcf52015-07-17 10:38:13 -040036 if (!new_op)
37 return -ENOMEM;
38
39 new_op->upcall.req.create.parent_refn = parent->refn;
40
41 fill_default_sys_attrs(new_op->upcall.req.create.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -050042 ORANGEFS_TYPE_METAFILE, mode);
Mike Marshall274dcf52015-07-17 10:38:13 -040043
44 strncpy(new_op->upcall.req.create.d_name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +080045 dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -040046
47 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
48
49 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040050 "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n",
Mike Marshall52534872016-02-16 17:09:09 -050051 __func__,
Al Virof66debf2016-08-07 12:20:01 -040052 dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -040053 &new_op->downcall.resp.create.refn.khandle,
Mike Marshall52534872016-02-16 17:09:09 -050054 new_op->downcall.resp.create.refn.fs_id,
55 new_op,
56 ret);
Mike Marshall274dcf52015-07-17 10:38:13 -040057
Mike Marshall52534872016-02-16 17:09:09 -050058 if (ret < 0)
Mike Marshall274dcf52015-07-17 10:38:13 -040059 goto out;
Mike Marshall274dcf52015-07-17 10:38:13 -040060
Martin Brandenburgdb0267e2017-11-10 12:08:01 -050061 ref = new_op->downcall.resp.create.refn;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -050062
63 inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -040064 if (IS_ERR(inode)) {
Al Virof66debf2016-08-07 12:20:01 -040065 gossip_err("%s: Failed to allocate inode for file :%pd:\n",
Mike Marshall52534872016-02-16 17:09:09 -050066 __func__,
Al Virof66debf2016-08-07 12:20:01 -040067 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040068 ret = PTR_ERR(inode);
69 goto out;
70 }
71
72 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040073 "%s: Assigned inode :%pU: for file :%pd:\n",
Mike Marshall52534872016-02-16 17:09:09 -050074 __func__,
75 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -040076 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040077
Al Viro1e2e5472018-05-04 08:23:01 -040078 d_instantiate_new(dentry, inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +020079 orangefs_set_timeout(dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040080
81 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040082 "%s: dentry instantiated for %pd\n",
Mike Marshall52534872016-02-16 17:09:09 -050083 __func__,
Al Virof66debf2016-08-07 12:20:01 -040084 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040085
Martin Brandenburga55f2d82017-11-07 15:01:40 -050086 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +000087 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
88 iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
89 __orangefs_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -040090 ret = 0;
91out:
Mike Marshall34e6148a2018-10-18 13:58:25 -040092 op_release(new_op);
Mike Marshall52534872016-02-16 17:09:09 -050093 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040094 "%s: %pd: returning %d\n",
Mike Marshall52534872016-02-16 17:09:09 -050095 __func__,
Al Virof66debf2016-08-07 12:20:01 -040096 dentry,
Mike Marshall52534872016-02-16 17:09:09 -050097 ret);
Mike Marshall274dcf52015-07-17 10:38:13 -040098 return ret;
99}
100
101/*
102 * Attempt to resolve an object name (dentry->d_name), parent handle, and
103 * fsid into a handle for the object.
104 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500105static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400106 unsigned int flags)
107{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500108 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
109 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400110 struct inode *inode;
Mike Marshall274dcf52015-07-17 10:38:13 -0400111 int ret = -EINVAL;
112
113 /*
114 * in theory we could skip a lookup here (if the intent is to
115 * create) in order to avoid a potentially failed lookup, but
116 * leaving it in can skip a valid lookup and try to create a file
117 * that already exists (e.g. the vfs already handles checking for
118 * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
119 * in the create path)
120 */
Al Virof66debf2016-08-07 12:20:01 -0400121 gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n",
122 __func__, dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400123
Martin Brandenburg47b49482016-02-20 14:22:40 -0500124 if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1))
Mike Marshall274dcf52015-07-17 10:38:13 -0400125 return ERR_PTR(-ENAMETOOLONG);
126
Yi Liu8bb8aef2015-11-24 15:12:14 -0500127 new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
Mike Marshall274dcf52015-07-17 10:38:13 -0400128 if (!new_op)
129 return ERR_PTR(-ENOMEM);
130
Mike Marshall7cec28e2015-12-11 10:46:22 -0500131 new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
Mike Marshall274dcf52015-07-17 10:38:13 -0400132
133 gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
134 __FILE__,
135 __func__,
136 __LINE__,
137 &parent->refn.khandle);
138 new_op->upcall.req.lookup.parent_refn = parent->refn;
139
140 strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800141 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400142
143 gossip_debug(GOSSIP_NAME_DEBUG,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500144 "%s: doing lookup on %s under %pU,%d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400145 __func__,
146 new_op->upcall.req.lookup.d_name,
147 &new_op->upcall.req.lookup.parent_refn.khandle,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500148 new_op->upcall.req.lookup.parent_refn.fs_id);
Mike Marshall274dcf52015-07-17 10:38:13 -0400149
150 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
151
152 gossip_debug(GOSSIP_NAME_DEBUG,
153 "Lookup Got %pU, fsid %d (ret=%d)\n",
154 &new_op->downcall.resp.lookup.refn.khandle,
155 new_op->downcall.resp.lookup.refn.fs_id,
156 ret);
157
Mike Marshall22fc9db2018-10-18 14:05:46 -0400158 if (ret == 0) {
Al Viro04bb1ba2018-04-30 23:12:03 -0400159 orangefs_set_timeout(dentry);
160 inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
161 } else if (ret == -ENOENT) {
162 inode = NULL;
163 } else {
Mike Marshall274dcf52015-07-17 10:38:13 -0400164 /* must be a non-recoverable error */
Al Viro04bb1ba2018-04-30 23:12:03 -0400165 inode = ERR_PTR(ret);
Mike Marshall274dcf52015-07-17 10:38:13 -0400166 }
167
Mike Marshall274dcf52015-07-17 10:38:13 -0400168 op_release(new_op);
Al Viro04bb1ba2018-04-30 23:12:03 -0400169 return d_splice_alias(inode, dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400170}
171
172/* return 0 on success; non-zero otherwise */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500173static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
Mike Marshall274dcf52015-07-17 10:38:13 -0400174{
175 struct inode *inode = dentry->d_inode;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500176 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
177 struct orangefs_kernel_op_s *new_op;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500178 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400179 int ret;
180
181 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400182 "%s: called on %pd\n"
Mike Marshall274dcf52015-07-17 10:38:13 -0400183 " (inode %pU): Parent is %pU | fs_id %d\n",
184 __func__,
Al Virof66debf2016-08-07 12:20:01 -0400185 dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400186 get_khandle_from_ino(inode),
187 &parent->refn.khandle,
188 parent->refn.fs_id);
189
Yi Liu8bb8aef2015-11-24 15:12:14 -0500190 new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
Mike Marshall274dcf52015-07-17 10:38:13 -0400191 if (!new_op)
192 return -ENOMEM;
193
194 new_op->upcall.req.remove.parent_refn = parent->refn;
195 strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800196 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400197
Yi Liu8bb8aef2015-11-24 15:12:14 -0500198 ret = service_operation(new_op, "orangefs_unlink",
Mike Marshall274dcf52015-07-17 10:38:13 -0400199 get_interruptible_flag(inode));
200
Mike Marshall52534872016-02-16 17:09:09 -0500201 gossip_debug(GOSSIP_NAME_DEBUG,
202 "%s: service_operation returned:%d:\n",
203 __func__,
204 ret);
205
Mike Marshall274dcf52015-07-17 10:38:13 -0400206 op_release(new_op);
207
208 if (!ret) {
209 drop_nlink(inode);
210
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500211 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +0000212 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
213 iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
214 __orangefs_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400215 }
216 return ret;
217}
218
Christian Brauner549c7292021-01-21 14:19:43 +0100219static int orangefs_symlink(struct user_namespace *mnt_userns,
220 struct inode *dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400221 struct dentry *dentry,
222 const char *symname)
223{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500224 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
225 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500226 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -0400227 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500228 struct iattr iattr;
Artur Świgońc42293a2019-08-13 12:53:37 +0200229 int mode = 0755;
Mike Marshall274dcf52015-07-17 10:38:13 -0400230 int ret;
231
232 gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
233
234 if (!symname)
235 return -EINVAL;
236
Martin Brandenburgc62da582016-02-29 16:07:35 -0500237 if (strlen(symname)+1 > ORANGEFS_NAME_MAX)
238 return -ENAMETOOLONG;
239
Yi Liu8bb8aef2015-11-24 15:12:14 -0500240 new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
Mike Marshall274dcf52015-07-17 10:38:13 -0400241 if (!new_op)
242 return -ENOMEM;
243
244 new_op->upcall.req.sym.parent_refn = parent->refn;
245
246 fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500247 ORANGEFS_TYPE_SYMLINK,
Mike Marshall274dcf52015-07-17 10:38:13 -0400248 mode);
249
250 strncpy(new_op->upcall.req.sym.entry_name,
251 dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800252 ORANGEFS_NAME_MAX - 1);
253 strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400254
255 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
256
257 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500258 "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400259 &new_op->downcall.resp.sym.refn.khandle,
260 new_op->downcall.resp.sym.refn.fs_id, ret);
261
262 if (ret < 0) {
263 gossip_debug(GOSSIP_NAME_DEBUG,
264 "%s: failed with error code %d\n",
265 __func__, ret);
266 goto out;
267 }
268
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500269 ref = new_op->downcall.resp.sym.refn;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500270
271 inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -0400272 if (IS_ERR(inode)) {
273 gossip_err
Yi Liu8bb8aef2015-11-24 15:12:14 -0500274 ("*** Failed to allocate orangefs symlink inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400275 ret = PTR_ERR(inode);
276 goto out;
277 }
Martin Brandenburgf6a4b4c2018-05-31 16:36:58 +0000278 /*
279 * This is necessary because orangefs_inode_getattr will not
280 * re-read symlink size as it is impossible for it to change.
281 * Invalidating the cache does not help. orangefs_new_inode
282 * does not set the correct size (it does not know symname).
283 */
284 inode->i_size = strlen(symname);
Mike Marshall274dcf52015-07-17 10:38:13 -0400285
286 gossip_debug(GOSSIP_NAME_DEBUG,
287 "Assigned symlink inode new number of %pU\n",
288 get_khandle_from_ino(inode));
289
Al Viro1e2e5472018-05-04 08:23:01 -0400290 d_instantiate_new(dentry, inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200291 orangefs_set_timeout(dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400292
293 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400294 "Inode (Symlink) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400295 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400296 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400297
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500298 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +0000299 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
300 iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
301 __orangefs_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400302 ret = 0;
303out:
Mike Marshall34e6148a2018-10-18 13:58:25 -0400304 op_release(new_op);
Mike Marshall274dcf52015-07-17 10:38:13 -0400305 return ret;
306}
307
Christian Brauner549c7292021-01-21 14:19:43 +0100308static int orangefs_mkdir(struct user_namespace *mnt_userns, struct inode *dir,
309 struct dentry *dentry, umode_t mode)
Mike Marshall274dcf52015-07-17 10:38:13 -0400310{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500311 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
312 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500313 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -0400314 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500315 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400316 int ret;
317
Yi Liu8bb8aef2015-11-24 15:12:14 -0500318 new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
Mike Marshall274dcf52015-07-17 10:38:13 -0400319 if (!new_op)
320 return -ENOMEM;
321
322 new_op->upcall.req.mkdir.parent_refn = parent->refn;
323
324 fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500325 ORANGEFS_TYPE_DIRECTORY, mode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400326
327 strncpy(new_op->upcall.req.mkdir.d_name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800328 dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400329
330 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
331
332 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500333 "Mkdir Got ORANGEFS handle %pU on fsid %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400334 &new_op->downcall.resp.mkdir.refn.khandle,
335 new_op->downcall.resp.mkdir.refn.fs_id);
336
337 if (ret < 0) {
338 gossip_debug(GOSSIP_NAME_DEBUG,
339 "%s: failed with error code %d\n",
340 __func__, ret);
341 goto out;
342 }
343
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500344 ref = new_op->downcall.resp.mkdir.refn;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500345
346 inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -0400347 if (IS_ERR(inode)) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500348 gossip_err("*** Failed to allocate orangefs dir inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400349 ret = PTR_ERR(inode);
350 goto out;
351 }
352
353 gossip_debug(GOSSIP_NAME_DEBUG,
354 "Assigned dir inode new number of %pU\n",
355 get_khandle_from_ino(inode));
356
Al Viro1e2e5472018-05-04 08:23:01 -0400357 d_instantiate_new(dentry, inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200358 orangefs_set_timeout(dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400359
360 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400361 "Inode (Directory) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400362 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400363 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400364
365 /*
366 * NOTE: we have no good way to keep nlink consistent for directories
367 * across clients; keep constant at 1.
368 */
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500369 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +0000370 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
371 iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
372 __orangefs_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400373out:
Mike Marshall34e6148a2018-10-18 13:58:25 -0400374 op_release(new_op);
Mike Marshall274dcf52015-07-17 10:38:13 -0400375 return ret;
376}
377
Christian Brauner549c7292021-01-21 14:19:43 +0100378static int orangefs_rename(struct user_namespace *mnt_userns,
379 struct inode *old_dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400380 struct dentry *old_dentry,
381 struct inode *new_dir,
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200382 struct dentry *new_dentry,
383 unsigned int flags)
Mike Marshall274dcf52015-07-17 10:38:13 -0400384{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500385 struct orangefs_kernel_op_s *new_op;
Martin Brandenburg5e7f1d42018-02-12 15:49:24 +0000386 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400387 int ret;
388
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200389 if (flags)
390 return -EINVAL;
391
Mike Marshall274dcf52015-07-17 10:38:13 -0400392 gossip_debug(GOSSIP_NAME_DEBUG,
Al Viro96b0cff2016-05-29 15:00:34 -0400393 "orangefs_rename: called (%pd2 => %pd2) ct=%d\n",
394 old_dentry, new_dentry, d_count(new_dentry));
Mike Marshall274dcf52015-07-17 10:38:13 -0400395
Martin Brandenburg5e7f1d42018-02-12 15:49:24 +0000396 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +0000397 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
398 iattr.ia_mtime = iattr.ia_ctime = current_time(new_dir);
399 __orangefs_setattr(new_dir, &iattr);
Martin Brandenburg71680c12016-06-09 16:32:38 -0400400
Yi Liu8bb8aef2015-11-24 15:12:14 -0500401 new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
Mike Marshall274dcf52015-07-17 10:38:13 -0400402 if (!new_op)
403 return -EINVAL;
404
Yi Liu8bb8aef2015-11-24 15:12:14 -0500405 new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn;
406 new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn;
Mike Marshall274dcf52015-07-17 10:38:13 -0400407
408 strncpy(new_op->upcall.req.rename.d_old_name,
409 old_dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800410 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400411 strncpy(new_op->upcall.req.rename.d_new_name,
412 new_dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800413 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400414
415 ret = service_operation(new_op,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500416 "orangefs_rename",
Mike Marshall274dcf52015-07-17 10:38:13 -0400417 get_interruptible_flag(old_dentry->d_inode));
418
419 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500420 "orangefs_rename: got downcall status %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400421 ret);
422
423 if (new_dentry->d_inode)
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700424 new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400425
426 op_release(new_op);
427 return ret;
428}
429
Yi Liu8bb8aef2015-11-24 15:12:14 -0500430/* ORANGEFS implementation of VFS inode operations for directories */
Al Viro6f3fc102016-05-14 18:46:32 -0400431const struct inode_operations orangefs_dir_inode_operations = {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500432 .lookup = orangefs_lookup,
433 .get_acl = orangefs_get_acl,
434 .set_acl = orangefs_set_acl,
435 .create = orangefs_create,
436 .unlink = orangefs_unlink,
437 .symlink = orangefs_symlink,
438 .mkdir = orangefs_mkdir,
439 .rmdir = orangefs_unlink,
440 .rename = orangefs_rename,
441 .setattr = orangefs_setattr,
442 .getattr = orangefs_getattr,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500443 .listxattr = orangefs_listxattr,
Martin Brandenburg933287d2016-01-30 13:46:54 -0500444 .permission = orangefs_permission,
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500445 .update_time = orangefs_update_time,
Mike Marshall274dcf52015-07-17 10:38:13 -0400446};