blob: 625b0580f9beb9794755d8c93eb1972116fcbfdf [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
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);
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -040080 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
Martin Brandenburg68a24a62017-04-25 15:38:03 -040081 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
Mike Marshall274dcf52015-07-17 10:38:13 -040082
83 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040084 "%s: dentry instantiated for %pd\n",
Mike Marshall52534872016-02-16 17:09:09 -050085 __func__,
Al Virof66debf2016-08-07 12:20:01 -040086 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040087
Deepa Dinamanic2050a42016-09-14 07:48:06 -070088 dir->i_mtime = dir->i_ctime = current_time(dir);
Martin Brandenburga55f2d82017-11-07 15:01:40 -050089 memset(&iattr, 0, sizeof iattr);
90 iattr.ia_valid |= ATTR_MTIME;
91 orangefs_inode_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -040092 mark_inode_dirty_sync(dir);
93 ret = 0;
94out:
Mike Marshall52534872016-02-16 17:09:09 -050095 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040096 "%s: %pd: returning %d\n",
Mike Marshall52534872016-02-16 17:09:09 -050097 __func__,
Al Virof66debf2016-08-07 12:20:01 -040098 dentry,
Mike Marshall52534872016-02-16 17:09:09 -050099 ret);
Mike Marshall274dcf52015-07-17 10:38:13 -0400100 return ret;
101}
102
103/*
104 * Attempt to resolve an object name (dentry->d_name), parent handle, and
105 * fsid into a handle for the object.
106 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500107static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400108 unsigned int flags)
109{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500110 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
111 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400112 struct inode *inode;
Mike Marshall274dcf52015-07-17 10:38:13 -0400113 int ret = -EINVAL;
114
115 /*
116 * in theory we could skip a lookup here (if the intent is to
117 * create) in order to avoid a potentially failed lookup, but
118 * leaving it in can skip a valid lookup and try to create a file
119 * that already exists (e.g. the vfs already handles checking for
120 * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
121 * in the create path)
122 */
Al Virof66debf2016-08-07 12:20:01 -0400123 gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n",
124 __func__, dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400125
Martin Brandenburg47b49482016-02-20 14:22:40 -0500126 if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1))
Mike Marshall274dcf52015-07-17 10:38:13 -0400127 return ERR_PTR(-ENAMETOOLONG);
128
Yi Liu8bb8aef2015-11-24 15:12:14 -0500129 new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
Mike Marshall274dcf52015-07-17 10:38:13 -0400130 if (!new_op)
131 return ERR_PTR(-ENOMEM);
132
Mike Marshall7cec28e2015-12-11 10:46:22 -0500133 new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
Mike Marshall274dcf52015-07-17 10:38:13 -0400134
135 gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
136 __FILE__,
137 __func__,
138 __LINE__,
139 &parent->refn.khandle);
140 new_op->upcall.req.lookup.parent_refn = parent->refn;
141
142 strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800143 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400144
145 gossip_debug(GOSSIP_NAME_DEBUG,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500146 "%s: doing lookup on %s under %pU,%d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400147 __func__,
148 new_op->upcall.req.lookup.d_name,
149 &new_op->upcall.req.lookup.parent_refn.khandle,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500150 new_op->upcall.req.lookup.parent_refn.fs_id);
Mike Marshall274dcf52015-07-17 10:38:13 -0400151
152 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
153
154 gossip_debug(GOSSIP_NAME_DEBUG,
155 "Lookup Got %pU, fsid %d (ret=%d)\n",
156 &new_op->downcall.resp.lookup.refn.khandle,
157 new_op->downcall.resp.lookup.refn.fs_id,
158 ret);
159
Al Viro04bb1ba2018-04-30 23:12:03 -0400160 if (ret >= 0) {
161 orangefs_set_timeout(dentry);
162 inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
163 } else if (ret == -ENOENT) {
164 inode = NULL;
165 } else {
Mike Marshall274dcf52015-07-17 10:38:13 -0400166 /* must be a non-recoverable error */
Al Viro04bb1ba2018-04-30 23:12:03 -0400167 inode = ERR_PTR(ret);
Mike Marshall274dcf52015-07-17 10:38:13 -0400168 }
169
Mike Marshall274dcf52015-07-17 10:38:13 -0400170 op_release(new_op);
Al Viro04bb1ba2018-04-30 23:12:03 -0400171 return d_splice_alias(inode, dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400172}
173
174/* return 0 on success; non-zero otherwise */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500175static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
Mike Marshall274dcf52015-07-17 10:38:13 -0400176{
177 struct inode *inode = dentry->d_inode;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500178 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
179 struct orangefs_kernel_op_s *new_op;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500180 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400181 int ret;
182
183 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400184 "%s: called on %pd\n"
Mike Marshall274dcf52015-07-17 10:38:13 -0400185 " (inode %pU): Parent is %pU | fs_id %d\n",
186 __func__,
Al Virof66debf2016-08-07 12:20:01 -0400187 dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400188 get_khandle_from_ino(inode),
189 &parent->refn.khandle,
190 parent->refn.fs_id);
191
Yi Liu8bb8aef2015-11-24 15:12:14 -0500192 new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
Mike Marshall274dcf52015-07-17 10:38:13 -0400193 if (!new_op)
194 return -ENOMEM;
195
196 new_op->upcall.req.remove.parent_refn = parent->refn;
197 strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800198 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400199
Yi Liu8bb8aef2015-11-24 15:12:14 -0500200 ret = service_operation(new_op, "orangefs_unlink",
Mike Marshall274dcf52015-07-17 10:38:13 -0400201 get_interruptible_flag(inode));
202
Mike Marshall52534872016-02-16 17:09:09 -0500203 gossip_debug(GOSSIP_NAME_DEBUG,
204 "%s: service_operation returned:%d:\n",
205 __func__,
206 ret);
207
Mike Marshall274dcf52015-07-17 10:38:13 -0400208 op_release(new_op);
209
210 if (!ret) {
211 drop_nlink(inode);
212
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700213 dir->i_mtime = dir->i_ctime = current_time(dir);
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500214 memset(&iattr, 0, sizeof iattr);
215 iattr.ia_valid |= ATTR_MTIME;
216 orangefs_inode_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400217 mark_inode_dirty_sync(dir);
218 }
219 return ret;
220}
221
Yi Liu8bb8aef2015-11-24 15:12:14 -0500222static int orangefs_symlink(struct inode *dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400223 struct dentry *dentry,
224 const char *symname)
225{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500226 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
227 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500228 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -0400229 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500230 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400231 int mode = 755;
232 int ret;
233
234 gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
235
236 if (!symname)
237 return -EINVAL;
238
Martin Brandenburgc62da582016-02-29 16:07:35 -0500239 if (strlen(symname)+1 > ORANGEFS_NAME_MAX)
240 return -ENAMETOOLONG;
241
Yi Liu8bb8aef2015-11-24 15:12:14 -0500242 new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
Mike Marshall274dcf52015-07-17 10:38:13 -0400243 if (!new_op)
244 return -ENOMEM;
245
246 new_op->upcall.req.sym.parent_refn = parent->refn;
247
248 fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500249 ORANGEFS_TYPE_SYMLINK,
Mike Marshall274dcf52015-07-17 10:38:13 -0400250 mode);
251
252 strncpy(new_op->upcall.req.sym.entry_name,
253 dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800254 ORANGEFS_NAME_MAX - 1);
255 strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400256
257 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
258
259 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500260 "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400261 &new_op->downcall.resp.sym.refn.khandle,
262 new_op->downcall.resp.sym.refn.fs_id, ret);
263
264 if (ret < 0) {
265 gossip_debug(GOSSIP_NAME_DEBUG,
266 "%s: failed with error code %d\n",
267 __func__, ret);
268 goto out;
269 }
270
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500271 ref = new_op->downcall.resp.sym.refn;
272 op_release(new_op);
273
274 inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -0400275 if (IS_ERR(inode)) {
276 gossip_err
Yi Liu8bb8aef2015-11-24 15:12:14 -0500277 ("*** Failed to allocate orangefs symlink inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400278 ret = PTR_ERR(inode);
279 goto out;
280 }
Martin Brandenburgf6a4b4c2018-05-31 16:36:58 +0000281 /*
282 * This is necessary because orangefs_inode_getattr will not
283 * re-read symlink size as it is impossible for it to change.
284 * Invalidating the cache does not help. orangefs_new_inode
285 * does not set the correct size (it does not know symname).
286 */
287 inode->i_size = strlen(symname);
Mike Marshall274dcf52015-07-17 10:38:13 -0400288
289 gossip_debug(GOSSIP_NAME_DEBUG,
290 "Assigned symlink inode new number of %pU\n",
291 get_khandle_from_ino(inode));
292
Al Viro1e2e5472018-05-04 08:23:01 -0400293 d_instantiate_new(dentry, inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200294 orangefs_set_timeout(dentry);
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -0400295 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
Martin Brandenburg68a24a62017-04-25 15:38:03 -0400296 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
Mike Marshall274dcf52015-07-17 10:38:13 -0400297
298 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400299 "Inode (Symlink) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400300 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400301 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400302
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700303 dir->i_mtime = dir->i_ctime = current_time(dir);
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500304 memset(&iattr, 0, sizeof iattr);
305 iattr.ia_valid |= ATTR_MTIME;
306 orangefs_inode_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400307 mark_inode_dirty_sync(dir);
308 ret = 0;
309out:
Mike Marshall274dcf52015-07-17 10:38:13 -0400310 return ret;
311}
312
Yi Liu8bb8aef2015-11-24 15:12:14 -0500313static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
Mike Marshall274dcf52015-07-17 10:38:13 -0400314{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500315 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
316 struct orangefs_kernel_op_s *new_op;
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500317 struct orangefs_object_kref ref;
Mike Marshall274dcf52015-07-17 10:38:13 -0400318 struct inode *inode;
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500319 struct iattr iattr;
Mike Marshall274dcf52015-07-17 10:38:13 -0400320 int ret;
321
Yi Liu8bb8aef2015-11-24 15:12:14 -0500322 new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
Mike Marshall274dcf52015-07-17 10:38:13 -0400323 if (!new_op)
324 return -ENOMEM;
325
326 new_op->upcall.req.mkdir.parent_refn = parent->refn;
327
328 fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500329 ORANGEFS_TYPE_DIRECTORY, mode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400330
331 strncpy(new_op->upcall.req.mkdir.d_name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800332 dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400333
334 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
335
336 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500337 "Mkdir Got ORANGEFS handle %pU on fsid %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400338 &new_op->downcall.resp.mkdir.refn.khandle,
339 new_op->downcall.resp.mkdir.refn.fs_id);
340
341 if (ret < 0) {
342 gossip_debug(GOSSIP_NAME_DEBUG,
343 "%s: failed with error code %d\n",
344 __func__, ret);
345 goto out;
346 }
347
Martin Brandenburgdb0267e2017-11-10 12:08:01 -0500348 ref = new_op->downcall.resp.mkdir.refn;
349 op_release(new_op);
350
351 inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref);
Mike Marshall274dcf52015-07-17 10:38:13 -0400352 if (IS_ERR(inode)) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500353 gossip_err("*** Failed to allocate orangefs dir inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400354 ret = PTR_ERR(inode);
355 goto out;
356 }
357
358 gossip_debug(GOSSIP_NAME_DEBUG,
359 "Assigned dir inode new number of %pU\n",
360 get_khandle_from_ino(inode));
361
Al Viro1e2e5472018-05-04 08:23:01 -0400362 d_instantiate_new(dentry, inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200363 orangefs_set_timeout(dentry);
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -0400364 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
Martin Brandenburg68a24a62017-04-25 15:38:03 -0400365 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
Mike Marshall274dcf52015-07-17 10:38:13 -0400366
367 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400368 "Inode (Directory) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400369 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400370 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400371
372 /*
373 * NOTE: we have no good way to keep nlink consistent for directories
374 * across clients; keep constant at 1.
375 */
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700376 dir->i_mtime = dir->i_ctime = current_time(dir);
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500377 memset(&iattr, 0, sizeof iattr);
378 iattr.ia_valid |= ATTR_MTIME;
379 orangefs_inode_setattr(dir, &iattr);
Mike Marshall274dcf52015-07-17 10:38:13 -0400380 mark_inode_dirty_sync(dir);
381out:
Mike Marshall274dcf52015-07-17 10:38:13 -0400382 return ret;
383}
384
Yi Liu8bb8aef2015-11-24 15:12:14 -0500385static int orangefs_rename(struct inode *old_dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400386 struct dentry *old_dentry,
387 struct inode *new_dir,
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200388 struct dentry *new_dentry,
389 unsigned int flags)
Mike Marshall274dcf52015-07-17 10:38:13 -0400390{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500391 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400392 int ret;
393
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200394 if (flags)
395 return -EINVAL;
396
Mike Marshall274dcf52015-07-17 10:38:13 -0400397 gossip_debug(GOSSIP_NAME_DEBUG,
Al Viro96b0cff2016-05-29 15:00:34 -0400398 "orangefs_rename: called (%pd2 => %pd2) ct=%d\n",
399 old_dentry, new_dentry, d_count(new_dentry));
Mike Marshall274dcf52015-07-17 10:38:13 -0400400
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -0400401 ORANGEFS_I(new_dentry->d_parent->d_inode)->getattr_time = jiffies - 1;
Martin Brandenburg71680c12016-06-09 16:32:38 -0400402
Yi Liu8bb8aef2015-11-24 15:12:14 -0500403 new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
Mike Marshall274dcf52015-07-17 10:38:13 -0400404 if (!new_op)
405 return -EINVAL;
406
Yi Liu8bb8aef2015-11-24 15:12:14 -0500407 new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn;
408 new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn;
Mike Marshall274dcf52015-07-17 10:38:13 -0400409
410 strncpy(new_op->upcall.req.rename.d_old_name,
411 old_dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800412 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400413 strncpy(new_op->upcall.req.rename.d_new_name,
414 new_dentry->d_name.name,
Xiongfeng Wang6bdfb482018-01-08 20:22:33 +0800415 ORANGEFS_NAME_MAX - 1);
Mike Marshall274dcf52015-07-17 10:38:13 -0400416
417 ret = service_operation(new_op,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500418 "orangefs_rename",
Mike Marshall274dcf52015-07-17 10:38:13 -0400419 get_interruptible_flag(old_dentry->d_inode));
420
421 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500422 "orangefs_rename: got downcall status %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400423 ret);
424
425 if (new_dentry->d_inode)
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700426 new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400427
428 op_release(new_op);
429 return ret;
430}
431
Yi Liu8bb8aef2015-11-24 15:12:14 -0500432/* ORANGEFS implementation of VFS inode operations for directories */
Al Viro6f3fc102016-05-14 18:46:32 -0400433const struct inode_operations orangefs_dir_inode_operations = {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500434 .lookup = orangefs_lookup,
435 .get_acl = orangefs_get_acl,
436 .set_acl = orangefs_set_acl,
437 .create = orangefs_create,
438 .unlink = orangefs_unlink,
439 .symlink = orangefs_symlink,
440 .mkdir = orangefs_mkdir,
441 .rmdir = orangefs_unlink,
442 .rename = orangefs_rename,
443 .setattr = orangefs_setattr,
444 .getattr = orangefs_getattr,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500445 .listxattr = orangefs_listxattr,
Martin Brandenburg933287d2016-01-30 13:46:54 -0500446 .permission = orangefs_permission,
Martin Brandenburga55f2d82017-11-07 15:01:40 -0500447 .update_time = orangefs_update_time,
Mike Marshall274dcf52015-07-17 10:38:13 -0400448};