blob: 6e3134e6d98a51c14a7c170ec6b98fdd7b78ff8e [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;
61 op_release(new_op);
62
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
78 d_instantiate(dentry, inode);
79 unlock_new_inode(inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +020080 orangefs_set_timeout(dentry);
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -040081 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
Martin Brandenburg68a24a62017-04-25 15:38:03 -040082 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
Mike Marshall274dcf52015-07-17 10:38:13 -040083
84 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040085 "%s: dentry instantiated for %pd\n",
Mike Marshall52534872016-02-16 17:09:09 -050086 __func__,
Al Virof66debf2016-08-07 12:20:01 -040087 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040088
Deepa Dinamanic2050a42016-09-14 07:48:06 -070089 dir->i_mtime = dir->i_ctime = current_time(dir);
Martin Brandenburga55f2d82017-11-07 15:01:40 -050090 memset(&iattr, 0, sizeof iattr);
91 iattr.ia_valid |= ATTR_MTIME;
92 orangefs_inode_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -040093 mark_inode_dirty_sync(dir);
94 ret = 0;
95out:
Mike Marshall52534872016-02-16 17:09:09 -050096 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040097 "%s: %pd: returning %d\n",
Mike Marshall52534872016-02-16 17:09:09 -050098 __func__,
Al Virof66debf2016-08-07 12:20:01 -040099 dentry,
Mike Marshall52534872016-02-16 17:09:09 -0500100 ret);
Mike Marshall274dcf52015-07-17 10:38:13 -0400101 return ret;
102}
103
104/*
105 * Attempt to resolve an object name (dentry->d_name), parent handle, and
106 * fsid into a handle for the object.
107 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500108static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400109 unsigned int flags)
110{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500111 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
112 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400113 struct inode *inode;
114 struct dentry *res;
115 int ret = -EINVAL;
116
117 /*
118 * in theory we could skip a lookup here (if the intent is to
119 * create) in order to avoid a potentially failed lookup, but
120 * leaving it in can skip a valid lookup and try to create a file
121 * that already exists (e.g. the vfs already handles checking for
122 * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
123 * in the create path)
124 */
Al Virof66debf2016-08-07 12:20:01 -0400125 gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n",
126 __func__, dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400127
Martin Brandenburg47b49482016-02-20 14:22:40 -0500128 if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1))
Mike Marshall274dcf52015-07-17 10:38:13 -0400129 return ERR_PTR(-ENAMETOOLONG);
130
Yi Liu8bb8aef2015-11-24 15:12:14 -0500131 new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
Mike Marshall274dcf52015-07-17 10:38:13 -0400132 if (!new_op)
133 return ERR_PTR(-ENOMEM);
134
Mike Marshall7cec28e2015-12-11 10:46:22 -0500135 new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
Mike Marshall274dcf52015-07-17 10:38:13 -0400136
137 gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
138 __FILE__,
139 __func__,
140 __LINE__,
141 &parent->refn.khandle);
142 new_op->upcall.req.lookup.parent_refn = parent->refn;
143
144 strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800145 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400146
147 gossip_debug(GOSSIP_NAME_DEBUG,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500148 "%s: doing lookup on %s under %pU,%d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400149 __func__,
150 new_op->upcall.req.lookup.d_name,
151 &new_op->upcall.req.lookup.parent_refn.khandle,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500152 new_op->upcall.req.lookup.parent_refn.fs_id);
Mike Marshall274dcf52015-07-17 10:38:13 -0400153
154 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
155
156 gossip_debug(GOSSIP_NAME_DEBUG,
157 "Lookup Got %pU, fsid %d (ret=%d)\n",
158 &new_op->downcall.resp.lookup.refn.khandle,
159 new_op->downcall.resp.lookup.refn.fs_id,
160 ret);
161
162 if (ret < 0) {
163 if (ret == -ENOENT) {
164 /*
165 * if no inode was found, add a negative dentry to
166 * dcache anyway; if we don't, we don't hold expected
167 * lookup semantics and we most noticeably break
168 * during directory renames.
169 *
170 * however, if the operation failed or exited, do not
171 * add the dentry (e.g. in the case that a touch is
172 * issued on a file that already exists that was
173 * interrupted during this lookup -- no need to add
174 * another negative dentry for an existing file)
175 */
176
177 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500178 "orangefs_lookup: Adding *negative* dentry "
Al Virof66debf2016-08-07 12:20:01 -0400179 "%p for %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400180 dentry,
Al Virof66debf2016-08-07 12:20:01 -0400181 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400182
183 d_add(dentry, NULL);
184 res = NULL;
185 goto out;
186 }
187
188 /* must be a non-recoverable error */
189 res = ERR_PTR(ret);
190 goto out;
191 }
192
Miklos Szeredi804b1732016-10-17 10:14:23 +0200193 orangefs_set_timeout(dentry);
Martin Brandenburg31b7c1a2016-02-08 17:01:29 -0500194
Yi Liu8bb8aef2015-11-24 15:12:14 -0500195 inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
Mike Marshall274dcf52015-07-17 10:38:13 -0400196 if (IS_ERR(inode)) {
197 gossip_debug(GOSSIP_NAME_DEBUG,
198 "error %ld from iget\n", PTR_ERR(inode));
199 res = ERR_CAST(inode);
200 goto out;
201 }
202
203 gossip_debug(GOSSIP_NAME_DEBUG,
204 "%s:%s:%d "
205 "Found good inode [%lu] with count [%d]\n",
206 __FILE__,
207 __func__,
208 __LINE__,
209 inode->i_ino,
210 (int)atomic_read(&inode->i_count));
211
212 /* update dentry/inode pair into dcache */
213 res = d_splice_alias(inode, dentry);
214
215 gossip_debug(GOSSIP_NAME_DEBUG,
216 "Lookup success (inode ct = %d)\n",
217 (int)atomic_read(&inode->i_count));
218out:
219 op_release(new_op);
220 return res;
221}
222
223/* return 0 on success; non-zero otherwise */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500224static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
Mike Marshall274dcf52015-07-17 10:38:13 -0400225{
226 struct inode *inode = dentry->d_inode;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500227 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
228 struct orangefs_kernel_op_s *new_op;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500229 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400230 int ret;
231
232 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400233 "%s: called on %pd\n"
Mike Marshall274dcf52015-07-17 10:38:13 -0400234 " (inode %pU): Parent is %pU | fs_id %d\n",
235 __func__,
Al Virof66debf2016-08-07 12:20:01 -0400236 dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400237 get_khandle_from_ino(inode),
238 &parent->refn.khandle,
239 parent->refn.fs_id);
240
Yi Liu8bb8aef2015-11-24 15:12:14 -0500241 new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
Mike Marshall274dcf52015-07-17 10:38:13 -0400242 if (!new_op)
243 return -ENOMEM;
244
245 new_op->upcall.req.remove.parent_refn = parent->refn;
246 strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800247 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400248
Yi Liu8bb8aef2015-11-24 15:12:14 -0500249 ret = service_operation(new_op, "orangefs_unlink",
Mike Marshall274dcf52015-07-17 10:38:13 -0400250 get_interruptible_flag(inode));
251
Mike Marshall52534872016-02-16 17:09:09 -0500252 gossip_debug(GOSSIP_NAME_DEBUG,
253 "%s: service_operation returned:%d:\n",
254 __func__,
255 ret);
256
Mike Marshall274dcf52015-07-17 10:38:13 -0400257 op_release(new_op);
258
259 if (!ret) {
260 drop_nlink(inode);
261
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700262 dir->i_mtime = dir->i_ctime = current_time(dir);
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500263 memset(&iattr, 0, sizeof iattr);
264 iattr.ia_valid |= ATTR_MTIME;
265 orangefs_inode_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400266 mark_inode_dirty_sync(dir);
267 }
268 return ret;
269}
270
Yi Liu8bb8aef2015-11-24 15:12:14 -0500271static int orangefs_symlink(struct inode *dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400272 struct dentry *dentry,
273 const char *symname)
274{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500275 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
276 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500277 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -0400278 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500279 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400280 int mode = 755;
281 int ret;
282
283 gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
284
285 if (!symname)
286 return -EINVAL;
287
Martin Brandenburgc62da582016-02-29 16:07:35 -0500288 if (strlen(symname)+1 > ORANGEFS_NAME_MAX)
289 return -ENAMETOOLONG;
290
Yi Liu8bb8aef2015-11-24 15:12:14 -0500291 new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
Mike Marshall274dcf52015-07-17 10:38:13 -0400292 if (!new_op)
293 return -ENOMEM;
294
295 new_op->upcall.req.sym.parent_refn = parent->refn;
296
297 fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500298 ORANGEFS_TYPE_SYMLINK,
Mike Marshall274dcf52015-07-17 10:38:13 -0400299 mode);
300
301 strncpy(new_op->upcall.req.sym.entry_name,
302 dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800303 ORANGEFS_NAME_MAX - 1);
304 strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400305
306 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
307
308 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500309 "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400310 &new_op->downcall.resp.sym.refn.khandle,
311 new_op->downcall.resp.sym.refn.fs_id, ret);
312
313 if (ret < 0) {
314 gossip_debug(GOSSIP_NAME_DEBUG,
315 "%s: failed with error code %d\n",
316 __func__, ret);
317 goto out;
318 }
319
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500320 ref = new_op->downcall.resp.sym.refn;
321 op_release(new_op);
322
323 inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -0400324 if (IS_ERR(inode)) {
325 gossip_err
Yi Liu8bb8aef2015-11-24 15:12:14 -0500326 ("*** Failed to allocate orangefs symlink inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400327 ret = PTR_ERR(inode);
328 goto out;
329 }
330
331 gossip_debug(GOSSIP_NAME_DEBUG,
332 "Assigned symlink inode new number of %pU\n",
333 get_khandle_from_ino(inode));
334
335 d_instantiate(dentry, inode);
336 unlock_new_inode(inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200337 orangefs_set_timeout(dentry);
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -0400338 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
Martin Brandenburg68a24a62017-04-25 15:38:03 -0400339 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
Mike Marshall274dcf52015-07-17 10:38:13 -0400340
341 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400342 "Inode (Symlink) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400343 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400344 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400345
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700346 dir->i_mtime = dir->i_ctime = current_time(dir);
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500347 memset(&iattr, 0, sizeof iattr);
348 iattr.ia_valid |= ATTR_MTIME;
349 orangefs_inode_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400350 mark_inode_dirty_sync(dir);
351 ret = 0;
352out:
Mike Marshall274dcf52015-07-17 10:38:13 -0400353 return ret;
354}
355
Yi Liu8bb8aef2015-11-24 15:12:14 -0500356static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
Mike Marshall274dcf52015-07-17 10:38:13 -0400357{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500358 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
359 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500360 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -0400361 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500362 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400363 int ret;
364
Yi Liu8bb8aef2015-11-24 15:12:14 -0500365 new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
Mike Marshall274dcf52015-07-17 10:38:13 -0400366 if (!new_op)
367 return -ENOMEM;
368
369 new_op->upcall.req.mkdir.parent_refn = parent->refn;
370
371 fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500372 ORANGEFS_TYPE_DIRECTORY, mode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400373
374 strncpy(new_op->upcall.req.mkdir.d_name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800375 dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400376
377 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
378
379 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500380 "Mkdir Got ORANGEFS handle %pU on fsid %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400381 &new_op->downcall.resp.mkdir.refn.khandle,
382 new_op->downcall.resp.mkdir.refn.fs_id);
383
384 if (ret < 0) {
385 gossip_debug(GOSSIP_NAME_DEBUG,
386 "%s: failed with error code %d\n",
387 __func__, ret);
388 goto out;
389 }
390
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500391 ref = new_op->downcall.resp.mkdir.refn;
392 op_release(new_op);
393
394 inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -0400395 if (IS_ERR(inode)) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500396 gossip_err("*** Failed to allocate orangefs dir inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400397 ret = PTR_ERR(inode);
398 goto out;
399 }
400
401 gossip_debug(GOSSIP_NAME_DEBUG,
402 "Assigned dir inode new number of %pU\n",
403 get_khandle_from_ino(inode));
404
405 d_instantiate(dentry, inode);
406 unlock_new_inode(inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200407 orangefs_set_timeout(dentry);
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -0400408 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
Martin Brandenburg68a24a62017-04-25 15:38:03 -0400409 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
Mike Marshall274dcf52015-07-17 10:38:13 -0400410
411 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400412 "Inode (Directory) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400413 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400414 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400415
416 /*
417 * NOTE: we have no good way to keep nlink consistent for directories
418 * across clients; keep constant at 1.
419 */
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700420 dir->i_mtime = dir->i_ctime = current_time(dir);
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500421 memset(&iattr, 0, sizeof iattr);
422 iattr.ia_valid |= ATTR_MTIME;
423 orangefs_inode_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400424 mark_inode_dirty_sync(dir);
425out:
Mike Marshall274dcf52015-07-17 10:38:13 -0400426 return ret;
427}
428
Yi Liu8bb8aef2015-11-24 15:12:14 -0500429static int orangefs_rename(struct inode *old_dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400430 struct dentry *old_dentry,
431 struct inode *new_dir,
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200432 struct dentry *new_dentry,
433 unsigned int flags)
Mike Marshall274dcf52015-07-17 10:38:13 -0400434{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500435 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400436 int ret;
437
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200438 if (flags)
439 return -EINVAL;
440
Mike Marshall274dcf52015-07-17 10:38:13 -0400441 gossip_debug(GOSSIP_NAME_DEBUG,
Al Viro96b0cff2016-05-29 15:00:34 -0400442 "orangefs_rename: called (%pd2 => %pd2) ct=%d\n",
443 old_dentry, new_dentry, d_count(new_dentry));
Mike Marshall274dcf52015-07-17 10:38:13 -0400444
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -0400445 ORANGEFS_I(new_dentry->d_parent->d_inode)->getattr_time = jiffies - 1;
Martin Brandenburg71680c12016-06-09 16:32:38 -0400446
Yi Liu8bb8aef2015-11-24 15:12:14 -0500447 new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
Mike Marshall274dcf52015-07-17 10:38:13 -0400448 if (!new_op)
449 return -EINVAL;
450
Yi Liu8bb8aef2015-11-24 15:12:14 -0500451 new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn;
452 new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn;
Mike Marshall274dcf52015-07-17 10:38:13 -0400453
454 strncpy(new_op->upcall.req.rename.d_old_name,
455 old_dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800456 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400457 strncpy(new_op->upcall.req.rename.d_new_name,
458 new_dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800459 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400460
461 ret = service_operation(new_op,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500462 "orangefs_rename",
Mike Marshall274dcf52015-07-17 10:38:13 -0400463 get_interruptible_flag(old_dentry->d_inode));
464
465 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500466 "orangefs_rename: got downcall status %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400467 ret);
468
469 if (new_dentry->d_inode)
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700470 new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400471
472 op_release(new_op);
473 return ret;
474}
475
Yi Liu8bb8aef2015-11-24 15:12:14 -0500476/* ORANGEFS implementation of VFS inode operations for directories */
Al Viro6f3fc102016-05-14 18:46:32 -0400477const struct inode_operations orangefs_dir_inode_operations = {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500478 .lookup = orangefs_lookup,
479 .get_acl = orangefs_get_acl,
480 .set_acl = orangefs_set_acl,
481 .create = orangefs_create,
482 .unlink = orangefs_unlink,
483 .symlink = orangefs_symlink,
484 .mkdir = orangefs_mkdir,
485 .rmdir = orangefs_unlink,
486 .rename = orangefs_rename,
487 .setattr = orangefs_setattr,
488 .getattr = orangefs_getattr,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500489 .listxattr = orangefs_listxattr,
Martin Brandenburg933287d2016-01-30 13:46:54 -0500490 .permission = orangefs_permission,
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500491 .update_time = orangefs_update_time,
Mike Marshall274dcf52015-07-17 10:38:13 -0400492};