blob: 1dd710e5f3761871da044aad21756a0fa7fc52cb [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 */
Yi Liu8bb8aef2015-11-24 15:12:14 -050018static int orangefs_create(struct inode *dir,
Mike Marshall274dcf52015-07-17 10:38:13 -040019 struct dentry *dentry,
20 umode_t mode,
21 bool exclusive)
22{
Yi Liu8bb8aef2015-11-24 15:12:14 -050023 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
24 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -050025 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -040026 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -050027 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -040028 int ret;
29
Al Virof66debf2016-08-07 12:20:01 -040030 gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd\n",
Mike Marshall52534872016-02-16 17:09:09 -050031 __func__,
Al Virof66debf2016-08-07 12:20:01 -040032 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040033
Yi Liu8bb8aef2015-11-24 15:12:14 -050034 new_op = op_alloc(ORANGEFS_VFS_OP_CREATE);
Mike Marshall274dcf52015-07-17 10:38:13 -040035 if (!new_op)
36 return -ENOMEM;
37
38 new_op->upcall.req.create.parent_refn = parent->refn;
39
40 fill_default_sys_attrs(new_op->upcall.req.create.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -050041 ORANGEFS_TYPE_METAFILE, mode);
Mike Marshall274dcf52015-07-17 10:38:13 -040042
43 strncpy(new_op->upcall.req.create.d_name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +080044 dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -040045
46 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
47
48 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040049 "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n",
Mike Marshall52534872016-02-16 17:09:09 -050050 __func__,
Al Virof66debf2016-08-07 12:20:01 -040051 dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -040052 &new_op->downcall.resp.create.refn.khandle,
Mike Marshall52534872016-02-16 17:09:09 -050053 new_op->downcall.resp.create.refn.fs_id,
54 new_op,
55 ret);
Mike Marshall274dcf52015-07-17 10:38:13 -040056
Mike Marshall52534872016-02-16 17:09:09 -050057 if (ret < 0)
Mike Marshall274dcf52015-07-17 10:38:13 -040058 goto out;
Mike Marshall274dcf52015-07-17 10:38:13 -040059
Martin Brandenburgdb0267e2017-11-10 12:08:01 -050060 ref = new_op->downcall.resp.create.refn;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -050061
62 inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -040063 if (IS_ERR(inode)) {
Al Virof66debf2016-08-07 12:20:01 -040064 gossip_err("%s: Failed to allocate inode for file :%pd:\n",
Mike Marshall52534872016-02-16 17:09:09 -050065 __func__,
Al Virof66debf2016-08-07 12:20:01 -040066 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040067 ret = PTR_ERR(inode);
68 goto out;
69 }
70
71 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040072 "%s: Assigned inode :%pU: for file :%pd:\n",
Mike Marshall52534872016-02-16 17:09:09 -050073 __func__,
74 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -040075 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040076
Al Viro1e2e5472018-05-04 08:23:01 -040077 d_instantiate_new(dentry, inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +020078 orangefs_set_timeout(dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040079
80 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040081 "%s: dentry instantiated for %pd\n",
Mike Marshall52534872016-02-16 17:09:09 -050082 __func__,
Al Virof66debf2016-08-07 12:20:01 -040083 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040084
Martin Brandenburga55f2d82017-11-07 15:01:40 -050085 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +000086 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
87 iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
88 __orangefs_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -040089 ret = 0;
90out:
Mike Marshall34e6148a2018-10-18 13:58:25 -040091 op_release(new_op);
Mike Marshall52534872016-02-16 17:09:09 -050092 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040093 "%s: %pd: returning %d\n",
Mike Marshall52534872016-02-16 17:09:09 -050094 __func__,
Al Virof66debf2016-08-07 12:20:01 -040095 dentry,
Mike Marshall52534872016-02-16 17:09:09 -050096 ret);
Mike Marshall274dcf52015-07-17 10:38:13 -040097 return ret;
98}
99
100/*
101 * Attempt to resolve an object name (dentry->d_name), parent handle, and
102 * fsid into a handle for the object.
103 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500104static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400105 unsigned int flags)
106{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500107 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
108 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400109 struct inode *inode;
Mike Marshall274dcf52015-07-17 10:38:13 -0400110 int ret = -EINVAL;
111
112 /*
113 * in theory we could skip a lookup here (if the intent is to
114 * create) in order to avoid a potentially failed lookup, but
115 * leaving it in can skip a valid lookup and try to create a file
116 * that already exists (e.g. the vfs already handles checking for
117 * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
118 * in the create path)
119 */
Al Virof66debf2016-08-07 12:20:01 -0400120 gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n",
121 __func__, dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400122
Martin Brandenburg47b49482016-02-20 14:22:40 -0500123 if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1))
Mike Marshall274dcf52015-07-17 10:38:13 -0400124 return ERR_PTR(-ENAMETOOLONG);
125
Yi Liu8bb8aef2015-11-24 15:12:14 -0500126 new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
Mike Marshall274dcf52015-07-17 10:38:13 -0400127 if (!new_op)
128 return ERR_PTR(-ENOMEM);
129
Mike Marshall7cec28e2015-12-11 10:46:22 -0500130 new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
Mike Marshall274dcf52015-07-17 10:38:13 -0400131
132 gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
133 __FILE__,
134 __func__,
135 __LINE__,
136 &parent->refn.khandle);
137 new_op->upcall.req.lookup.parent_refn = parent->refn;
138
139 strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800140 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400141
142 gossip_debug(GOSSIP_NAME_DEBUG,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500143 "%s: doing lookup on %s under %pU,%d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400144 __func__,
145 new_op->upcall.req.lookup.d_name,
146 &new_op->upcall.req.lookup.parent_refn.khandle,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500147 new_op->upcall.req.lookup.parent_refn.fs_id);
Mike Marshall274dcf52015-07-17 10:38:13 -0400148
149 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
150
151 gossip_debug(GOSSIP_NAME_DEBUG,
152 "Lookup Got %pU, fsid %d (ret=%d)\n",
153 &new_op->downcall.resp.lookup.refn.khandle,
154 new_op->downcall.resp.lookup.refn.fs_id,
155 ret);
156
Mike Marshall22fc9db2018-10-18 14:05:46 -0400157 if (ret == 0) {
Al Viro04bb1ba2018-04-30 23:12:03 -0400158 orangefs_set_timeout(dentry);
159 inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
160 } else if (ret == -ENOENT) {
161 inode = NULL;
162 } else {
Mike Marshall274dcf52015-07-17 10:38:13 -0400163 /* must be a non-recoverable error */
Al Viro04bb1ba2018-04-30 23:12:03 -0400164 inode = ERR_PTR(ret);
Mike Marshall274dcf52015-07-17 10:38:13 -0400165 }
166
Mike Marshall274dcf52015-07-17 10:38:13 -0400167 op_release(new_op);
Al Viro04bb1ba2018-04-30 23:12:03 -0400168 return d_splice_alias(inode, dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400169}
170
171/* return 0 on success; non-zero otherwise */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500172static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
Mike Marshall274dcf52015-07-17 10:38:13 -0400173{
174 struct inode *inode = dentry->d_inode;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500175 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
176 struct orangefs_kernel_op_s *new_op;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500177 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400178 int ret;
179
180 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400181 "%s: called on %pd\n"
Mike Marshall274dcf52015-07-17 10:38:13 -0400182 " (inode %pU): Parent is %pU | fs_id %d\n",
183 __func__,
Al Virof66debf2016-08-07 12:20:01 -0400184 dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400185 get_khandle_from_ino(inode),
186 &parent->refn.khandle,
187 parent->refn.fs_id);
188
Yi Liu8bb8aef2015-11-24 15:12:14 -0500189 new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
Mike Marshall274dcf52015-07-17 10:38:13 -0400190 if (!new_op)
191 return -ENOMEM;
192
193 new_op->upcall.req.remove.parent_refn = parent->refn;
194 strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800195 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400196
Yi Liu8bb8aef2015-11-24 15:12:14 -0500197 ret = service_operation(new_op, "orangefs_unlink",
Mike Marshall274dcf52015-07-17 10:38:13 -0400198 get_interruptible_flag(inode));
199
Mike Marshall52534872016-02-16 17:09:09 -0500200 gossip_debug(GOSSIP_NAME_DEBUG,
201 "%s: service_operation returned:%d:\n",
202 __func__,
203 ret);
204
Mike Marshall274dcf52015-07-17 10:38:13 -0400205 op_release(new_op);
206
207 if (!ret) {
208 drop_nlink(inode);
209
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500210 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +0000211 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
212 iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
213 __orangefs_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400214 }
215 return ret;
216}
217
Yi Liu8bb8aef2015-11-24 15:12:14 -0500218static int orangefs_symlink(struct inode *dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400219 struct dentry *dentry,
220 const char *symname)
221{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500222 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
223 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500224 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -0400225 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500226 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400227 int mode = 755;
228 int ret;
229
230 gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
231
232 if (!symname)
233 return -EINVAL;
234
Martin Brandenburgc62da582016-02-29 16:07:35 -0500235 if (strlen(symname)+1 > ORANGEFS_NAME_MAX)
236 return -ENAMETOOLONG;
237
Yi Liu8bb8aef2015-11-24 15:12:14 -0500238 new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
Mike Marshall274dcf52015-07-17 10:38:13 -0400239 if (!new_op)
240 return -ENOMEM;
241
242 new_op->upcall.req.sym.parent_refn = parent->refn;
243
244 fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500245 ORANGEFS_TYPE_SYMLINK,
Mike Marshall274dcf52015-07-17 10:38:13 -0400246 mode);
247
248 strncpy(new_op->upcall.req.sym.entry_name,
249 dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800250 ORANGEFS_NAME_MAX - 1);
251 strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400252
253 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
254
255 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500256 "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400257 &new_op->downcall.resp.sym.refn.khandle,
258 new_op->downcall.resp.sym.refn.fs_id, ret);
259
260 if (ret < 0) {
261 gossip_debug(GOSSIP_NAME_DEBUG,
262 "%s: failed with error code %d\n",
263 __func__, ret);
264 goto out;
265 }
266
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500267 ref = new_op->downcall.resp.sym.refn;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500268
269 inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -0400270 if (IS_ERR(inode)) {
271 gossip_err
Yi Liu8bb8aef2015-11-24 15:12:14 -0500272 ("*** Failed to allocate orangefs symlink inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400273 ret = PTR_ERR(inode);
274 goto out;
275 }
Martin Brandenburgf6a4b4c2018-05-31 16:36:58 +0000276 /*
277 * This is necessary because orangefs_inode_getattr will not
278 * re-read symlink size as it is impossible for it to change.
279 * Invalidating the cache does not help. orangefs_new_inode
280 * does not set the correct size (it does not know symname).
281 */
282 inode->i_size = strlen(symname);
Mike Marshall274dcf52015-07-17 10:38:13 -0400283
284 gossip_debug(GOSSIP_NAME_DEBUG,
285 "Assigned symlink inode new number of %pU\n",
286 get_khandle_from_ino(inode));
287
Al Viro1e2e5472018-05-04 08:23:01 -0400288 d_instantiate_new(dentry, inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200289 orangefs_set_timeout(dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400290
291 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400292 "Inode (Symlink) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400293 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400294 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400295
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500296 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +0000297 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
298 iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
299 __orangefs_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400300 ret = 0;
301out:
Mike Marshall34e6148a2018-10-18 13:58:25 -0400302 op_release(new_op);
Mike Marshall274dcf52015-07-17 10:38:13 -0400303 return ret;
304}
305
Yi Liu8bb8aef2015-11-24 15:12:14 -0500306static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
Mike Marshall274dcf52015-07-17 10:38:13 -0400307{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500308 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
309 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500310 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -0400311 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500312 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400313 int ret;
314
Yi Liu8bb8aef2015-11-24 15:12:14 -0500315 new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
Mike Marshall274dcf52015-07-17 10:38:13 -0400316 if (!new_op)
317 return -ENOMEM;
318
319 new_op->upcall.req.mkdir.parent_refn = parent->refn;
320
321 fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500322 ORANGEFS_TYPE_DIRECTORY, mode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400323
324 strncpy(new_op->upcall.req.mkdir.d_name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800325 dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400326
327 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
328
329 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500330 "Mkdir Got ORANGEFS handle %pU on fsid %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400331 &new_op->downcall.resp.mkdir.refn.khandle,
332 new_op->downcall.resp.mkdir.refn.fs_id);
333
334 if (ret < 0) {
335 gossip_debug(GOSSIP_NAME_DEBUG,
336 "%s: failed with error code %d\n",
337 __func__, ret);
338 goto out;
339 }
340
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500341 ref = new_op->downcall.resp.mkdir.refn;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500342
343 inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -0400344 if (IS_ERR(inode)) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500345 gossip_err("*** Failed to allocate orangefs dir inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400346 ret = PTR_ERR(inode);
347 goto out;
348 }
349
350 gossip_debug(GOSSIP_NAME_DEBUG,
351 "Assigned dir inode new number of %pU\n",
352 get_khandle_from_ino(inode));
353
Al Viro1e2e5472018-05-04 08:23:01 -0400354 d_instantiate_new(dentry, inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200355 orangefs_set_timeout(dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400356
357 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400358 "Inode (Directory) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400359 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400360 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400361
362 /*
363 * NOTE: we have no good way to keep nlink consistent for directories
364 * across clients; keep constant at 1.
365 */
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500366 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +0000367 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
368 iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
369 __orangefs_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400370out:
Mike Marshall34e6148a2018-10-18 13:58:25 -0400371 op_release(new_op);
Mike Marshall274dcf52015-07-17 10:38:13 -0400372 return ret;
373}
374
Yi Liu8bb8aef2015-11-24 15:12:14 -0500375static int orangefs_rename(struct inode *old_dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400376 struct dentry *old_dentry,
377 struct inode *new_dir,
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200378 struct dentry *new_dentry,
379 unsigned int flags)
Mike Marshall274dcf52015-07-17 10:38:13 -0400380{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500381 struct orangefs_kernel_op_s *new_op;
Martin Brandenburg5e7f1d42018-02-12 15:49:24 +0000382 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400383 int ret;
384
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200385 if (flags)
386 return -EINVAL;
387
Mike Marshall274dcf52015-07-17 10:38:13 -0400388 gossip_debug(GOSSIP_NAME_DEBUG,
Al Viro96b0cff2016-05-29 15:00:34 -0400389 "orangefs_rename: called (%pd2 => %pd2) ct=%d\n",
390 old_dentry, new_dentry, d_count(new_dentry));
Mike Marshall274dcf52015-07-17 10:38:13 -0400391
Martin Brandenburg5e7f1d42018-02-12 15:49:24 +0000392 memset(&iattr, 0, sizeof iattr);
Martin Brandenburgafd9fb22018-02-13 20:13:46 +0000393 iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
394 iattr.ia_mtime = iattr.ia_ctime = current_time(new_dir);
395 __orangefs_setattr(new_dir, &iattr);
Martin Brandenburg71680c12016-06-09 16:32:38 -0400396
Yi Liu8bb8aef2015-11-24 15:12:14 -0500397 new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
Mike Marshall274dcf52015-07-17 10:38:13 -0400398 if (!new_op)
399 return -EINVAL;
400
Yi Liu8bb8aef2015-11-24 15:12:14 -0500401 new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn;
402 new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn;
Mike Marshall274dcf52015-07-17 10:38:13 -0400403
404 strncpy(new_op->upcall.req.rename.d_old_name,
405 old_dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800406 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400407 strncpy(new_op->upcall.req.rename.d_new_name,
408 new_dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800409 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400410
411 ret = service_operation(new_op,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500412 "orangefs_rename",
Mike Marshall274dcf52015-07-17 10:38:13 -0400413 get_interruptible_flag(old_dentry->d_inode));
414
415 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500416 "orangefs_rename: got downcall status %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400417 ret);
418
419 if (new_dentry->d_inode)
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700420 new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400421
422 op_release(new_op);
423 return ret;
424}
425
Yi Liu8bb8aef2015-11-24 15:12:14 -0500426/* ORANGEFS implementation of VFS inode operations for directories */
Al Viro6f3fc102016-05-14 18:46:32 -0400427const struct inode_operations orangefs_dir_inode_operations = {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500428 .lookup = orangefs_lookup,
429 .get_acl = orangefs_get_acl,
430 .set_acl = orangefs_set_acl,
431 .create = orangefs_create,
432 .unlink = orangefs_unlink,
433 .symlink = orangefs_symlink,
434 .mkdir = orangefs_mkdir,
435 .rmdir = orangefs_unlink,
436 .rename = orangefs_rename,
437 .setattr = orangefs_setattr,
438 .getattr = orangefs_getattr,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500439 .listxattr = orangefs_listxattr,
Martin Brandenburg933287d2016-01-30 13:46:54 -0500440 .permission = orangefs_permission,
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500441 .update_time = orangefs_update_time,
Mike Marshall274dcf52015-07-17 10:38:13 -0400442};