blob: 478e88bd7f9d3d3d79e4f8edf76d4df5a5acc395 [file] [log] [blame]
Mike Marshall274dcf52015-07-17 10:38:13 -04001/*
2 * (C) 2001 Clemson University and The University of Chicago
3 *
4 * See COPYING in top-level directory.
5 */
6
7/*
8 * Linux VFS namei operations.
9 */
10
11#include "protocol.h"
Mike Marshall575e9462015-12-04 12:56:14 -050012#include "orangefs-kernel.h"
Mike Marshall274dcf52015-07-17 10:38:13 -040013
14/*
15 * Get a newly allocated inode to go with a negative dentry.
16 */
Yi Liu8bb8aef2015-11-24 15:12:14 -050017static int orangefs_create(struct inode *dir,
Mike Marshall274dcf52015-07-17 10:38:13 -040018 struct dentry *dentry,
19 umode_t mode,
20 bool exclusive)
21{
Yi Liu8bb8aef2015-11-24 15:12:14 -050022 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
23 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -040024 struct inode *inode;
25 int ret;
26
Al Virof66debf2016-08-07 12:20:01 -040027 gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd\n",
Mike Marshall52534872016-02-16 17:09:09 -050028 __func__,
Al Virof66debf2016-08-07 12:20:01 -040029 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040030
Yi Liu8bb8aef2015-11-24 15:12:14 -050031 new_op = op_alloc(ORANGEFS_VFS_OP_CREATE);
Mike Marshall274dcf52015-07-17 10:38:13 -040032 if (!new_op)
33 return -ENOMEM;
34
35 new_op->upcall.req.create.parent_refn = parent->refn;
36
37 fill_default_sys_attrs(new_op->upcall.req.create.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -050038 ORANGEFS_TYPE_METAFILE, mode);
Mike Marshall274dcf52015-07-17 10:38:13 -040039
40 strncpy(new_op->upcall.req.create.d_name,
Martin Brandenburg47b49482016-02-20 14:22:40 -050041 dentry->d_name.name, ORANGEFS_NAME_MAX);
Mike Marshall274dcf52015-07-17 10:38:13 -040042
43 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
44
45 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040046 "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:\n",
Mike Marshall52534872016-02-16 17:09:09 -050047 __func__,
Al Virof66debf2016-08-07 12:20:01 -040048 dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -040049 &new_op->downcall.resp.create.refn.khandle,
Mike Marshall52534872016-02-16 17:09:09 -050050 new_op->downcall.resp.create.refn.fs_id,
51 new_op,
52 ret);
Mike Marshall274dcf52015-07-17 10:38:13 -040053
Mike Marshall52534872016-02-16 17:09:09 -050054 if (ret < 0)
Mike Marshall274dcf52015-07-17 10:38:13 -040055 goto out;
Mike Marshall274dcf52015-07-17 10:38:13 -040056
Yi Liu8bb8aef2015-11-24 15:12:14 -050057 inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0,
Mike Marshall274dcf52015-07-17 10:38:13 -040058 &new_op->downcall.resp.create.refn);
59 if (IS_ERR(inode)) {
Al Virof66debf2016-08-07 12:20:01 -040060 gossip_err("%s: Failed to allocate inode for file :%pd:\n",
Mike Marshall52534872016-02-16 17:09:09 -050061 __func__,
Al Virof66debf2016-08-07 12:20:01 -040062 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040063 ret = PTR_ERR(inode);
64 goto out;
65 }
66
67 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040068 "%s: Assigned inode :%pU: for file :%pd:\n",
Mike Marshall52534872016-02-16 17:09:09 -050069 __func__,
70 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -040071 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040072
73 d_instantiate(dentry, inode);
74 unlock_new_inode(inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +020075 orangefs_set_timeout(dentry);
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -040076 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
Martin Brandenburg68a24a62017-04-25 15:38:03 -040077 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
Mike Marshall274dcf52015-07-17 10:38:13 -040078
79 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040080 "%s: dentry instantiated for %pd\n",
Mike Marshall52534872016-02-16 17:09:09 -050081 __func__,
Al Virof66debf2016-08-07 12:20:01 -040082 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -040083
84 SetMtimeFlag(parent);
Deepa Dinamanic2050a42016-09-14 07:48:06 -070085 dir->i_mtime = dir->i_ctime = current_time(dir);
Mike Marshall274dcf52015-07-17 10:38:13 -040086 mark_inode_dirty_sync(dir);
87 ret = 0;
88out:
89 op_release(new_op);
Mike Marshall52534872016-02-16 17:09:09 -050090 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -040091 "%s: %pd: returning %d\n",
Mike Marshall52534872016-02-16 17:09:09 -050092 __func__,
Al Virof66debf2016-08-07 12:20:01 -040093 dentry,
Mike Marshall52534872016-02-16 17:09:09 -050094 ret);
Mike Marshall274dcf52015-07-17 10:38:13 -040095 return ret;
96}
97
98/*
99 * Attempt to resolve an object name (dentry->d_name), parent handle, and
100 * fsid into a handle for the object.
101 */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500102static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400103 unsigned int flags)
104{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500105 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
106 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400107 struct inode *inode;
108 struct dentry *res;
109 int ret = -EINVAL;
110
111 /*
112 * in theory we could skip a lookup here (if the intent is to
113 * create) in order to avoid a potentially failed lookup, but
114 * leaving it in can skip a valid lookup and try to create a file
115 * that already exists (e.g. the vfs already handles checking for
116 * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
117 * in the create path)
118 */
Al Virof66debf2016-08-07 12:20:01 -0400119 gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd\n",
120 __func__, dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400121
Martin Brandenburg47b49482016-02-20 14:22:40 -0500122 if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1))
Mike Marshall274dcf52015-07-17 10:38:13 -0400123 return ERR_PTR(-ENAMETOOLONG);
124
Yi Liu8bb8aef2015-11-24 15:12:14 -0500125 new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
Mike Marshall274dcf52015-07-17 10:38:13 -0400126 if (!new_op)
127 return ERR_PTR(-ENOMEM);
128
Mike Marshall7cec28e2015-12-11 10:46:22 -0500129 new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
Mike Marshall274dcf52015-07-17 10:38:13 -0400130
131 gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU\n",
132 __FILE__,
133 __func__,
134 __LINE__,
135 &parent->refn.khandle);
136 new_op->upcall.req.lookup.parent_refn = parent->refn;
137
138 strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
Martin Brandenburg47b49482016-02-20 14:22:40 -0500139 ORANGEFS_NAME_MAX);
Mike Marshall274dcf52015-07-17 10:38:13 -0400140
141 gossip_debug(GOSSIP_NAME_DEBUG,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500142 "%s: doing lookup on %s under %pU,%d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400143 __func__,
144 new_op->upcall.req.lookup.d_name,
145 &new_op->upcall.req.lookup.parent_refn.khandle,
Martin Brandenburg6ceaf782016-02-20 14:47:13 -0500146 new_op->upcall.req.lookup.parent_refn.fs_id);
Mike Marshall274dcf52015-07-17 10:38:13 -0400147
148 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
149
150 gossip_debug(GOSSIP_NAME_DEBUG,
151 "Lookup Got %pU, fsid %d (ret=%d)\n",
152 &new_op->downcall.resp.lookup.refn.khandle,
153 new_op->downcall.resp.lookup.refn.fs_id,
154 ret);
155
156 if (ret < 0) {
157 if (ret == -ENOENT) {
158 /*
159 * if no inode was found, add a negative dentry to
160 * dcache anyway; if we don't, we don't hold expected
161 * lookup semantics and we most noticeably break
162 * during directory renames.
163 *
164 * however, if the operation failed or exited, do not
165 * add the dentry (e.g. in the case that a touch is
166 * issued on a file that already exists that was
167 * interrupted during this lookup -- no need to add
168 * another negative dentry for an existing file)
169 */
170
171 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500172 "orangefs_lookup: Adding *negative* dentry "
Al Virof66debf2016-08-07 12:20:01 -0400173 "%p for %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400174 dentry,
Al Virof66debf2016-08-07 12:20:01 -0400175 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400176
177 d_add(dentry, NULL);
178 res = NULL;
179 goto out;
180 }
181
182 /* must be a non-recoverable error */
183 res = ERR_PTR(ret);
184 goto out;
185 }
186
Miklos Szeredi804b1732016-10-17 10:14:23 +0200187 orangefs_set_timeout(dentry);
Martin Brandenburg31b7c1a2016-02-08 17:01:29 -0500188
Yi Liu8bb8aef2015-11-24 15:12:14 -0500189 inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
Mike Marshall274dcf52015-07-17 10:38:13 -0400190 if (IS_ERR(inode)) {
191 gossip_debug(GOSSIP_NAME_DEBUG,
192 "error %ld from iget\n", PTR_ERR(inode));
193 res = ERR_CAST(inode);
194 goto out;
195 }
196
197 gossip_debug(GOSSIP_NAME_DEBUG,
198 "%s:%s:%d "
199 "Found good inode [%lu] with count [%d]\n",
200 __FILE__,
201 __func__,
202 __LINE__,
203 inode->i_ino,
204 (int)atomic_read(&inode->i_count));
205
206 /* update dentry/inode pair into dcache */
207 res = d_splice_alias(inode, dentry);
208
209 gossip_debug(GOSSIP_NAME_DEBUG,
210 "Lookup success (inode ct = %d)\n",
211 (int)atomic_read(&inode->i_count));
212out:
213 op_release(new_op);
214 return res;
215}
216
217/* return 0 on success; non-zero otherwise */
Yi Liu8bb8aef2015-11-24 15:12:14 -0500218static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
Mike Marshall274dcf52015-07-17 10:38:13 -0400219{
220 struct inode *inode = dentry->d_inode;
Yi Liu8bb8aef2015-11-24 15:12:14 -0500221 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
222 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400223 int ret;
224
225 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400226 "%s: called on %pd\n"
Mike Marshall274dcf52015-07-17 10:38:13 -0400227 " (inode %pU): Parent is %pU | fs_id %d\n",
228 __func__,
Al Virof66debf2016-08-07 12:20:01 -0400229 dentry,
Mike Marshall274dcf52015-07-17 10:38:13 -0400230 get_khandle_from_ino(inode),
231 &parent->refn.khandle,
232 parent->refn.fs_id);
233
Yi Liu8bb8aef2015-11-24 15:12:14 -0500234 new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
Mike Marshall274dcf52015-07-17 10:38:13 -0400235 if (!new_op)
236 return -ENOMEM;
237
238 new_op->upcall.req.remove.parent_refn = parent->refn;
239 strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
Martin Brandenburg47b49482016-02-20 14:22:40 -0500240 ORANGEFS_NAME_MAX);
Mike Marshall274dcf52015-07-17 10:38:13 -0400241
Yi Liu8bb8aef2015-11-24 15:12:14 -0500242 ret = service_operation(new_op, "orangefs_unlink",
Mike Marshall274dcf52015-07-17 10:38:13 -0400243 get_interruptible_flag(inode));
244
Mike Marshall52534872016-02-16 17:09:09 -0500245 gossip_debug(GOSSIP_NAME_DEBUG,
246 "%s: service_operation returned:%d:\n",
247 __func__,
248 ret);
249
Mike Marshall274dcf52015-07-17 10:38:13 -0400250 op_release(new_op);
251
252 if (!ret) {
253 drop_nlink(inode);
254
255 SetMtimeFlag(parent);
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700256 dir->i_mtime = dir->i_ctime = current_time(dir);
Mike Marshall274dcf52015-07-17 10:38:13 -0400257 mark_inode_dirty_sync(dir);
258 }
259 return ret;
260}
261
Yi Liu8bb8aef2015-11-24 15:12:14 -0500262static int orangefs_symlink(struct inode *dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400263 struct dentry *dentry,
264 const char *symname)
265{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500266 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
267 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400268 struct inode *inode;
269 int mode = 755;
270 int ret;
271
272 gossip_debug(GOSSIP_NAME_DEBUG, "%s: called\n", __func__);
273
274 if (!symname)
275 return -EINVAL;
276
Martin Brandenburgc62da582016-02-29 16:07:35 -0500277 if (strlen(symname)+1 > ORANGEFS_NAME_MAX)
278 return -ENAMETOOLONG;
279
Yi Liu8bb8aef2015-11-24 15:12:14 -0500280 new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
Mike Marshall274dcf52015-07-17 10:38:13 -0400281 if (!new_op)
282 return -ENOMEM;
283
284 new_op->upcall.req.sym.parent_refn = parent->refn;
285
286 fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500287 ORANGEFS_TYPE_SYMLINK,
Mike Marshall274dcf52015-07-17 10:38:13 -0400288 mode);
289
290 strncpy(new_op->upcall.req.sym.entry_name,
291 dentry->d_name.name,
Martin Brandenburg47b49482016-02-20 14:22:40 -0500292 ORANGEFS_NAME_MAX);
293 strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX);
Mike Marshall274dcf52015-07-17 10:38:13 -0400294
295 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
296
297 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500298 "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400299 &new_op->downcall.resp.sym.refn.khandle,
300 new_op->downcall.resp.sym.refn.fs_id, ret);
301
302 if (ret < 0) {
303 gossip_debug(GOSSIP_NAME_DEBUG,
304 "%s: failed with error code %d\n",
305 __func__, ret);
306 goto out;
307 }
308
Yi Liu8bb8aef2015-11-24 15:12:14 -0500309 inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0,
Mike Marshall274dcf52015-07-17 10:38:13 -0400310 &new_op->downcall.resp.sym.refn);
311 if (IS_ERR(inode)) {
312 gossip_err
Yi Liu8bb8aef2015-11-24 15:12:14 -0500313 ("*** Failed to allocate orangefs symlink inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400314 ret = PTR_ERR(inode);
315 goto out;
316 }
317
318 gossip_debug(GOSSIP_NAME_DEBUG,
319 "Assigned symlink inode new number of %pU\n",
320 get_khandle_from_ino(inode));
321
322 d_instantiate(dentry, inode);
323 unlock_new_inode(inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200324 orangefs_set_timeout(dentry);
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -0400325 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
Martin Brandenburg68a24a62017-04-25 15:38:03 -0400326 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
Mike Marshall274dcf52015-07-17 10:38:13 -0400327
328 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400329 "Inode (Symlink) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400330 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400331 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400332
333 SetMtimeFlag(parent);
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700334 dir->i_mtime = dir->i_ctime = current_time(dir);
Mike Marshall274dcf52015-07-17 10:38:13 -0400335 mark_inode_dirty_sync(dir);
336 ret = 0;
337out:
338 op_release(new_op);
339 return ret;
340}
341
Yi Liu8bb8aef2015-11-24 15:12:14 -0500342static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
Mike Marshall274dcf52015-07-17 10:38:13 -0400343{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500344 struct orangefs_inode_s *parent = ORANGEFS_I(dir);
345 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400346 struct inode *inode;
347 int ret;
348
Yi Liu8bb8aef2015-11-24 15:12:14 -0500349 new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
Mike Marshall274dcf52015-07-17 10:38:13 -0400350 if (!new_op)
351 return -ENOMEM;
352
353 new_op->upcall.req.mkdir.parent_refn = parent->refn;
354
355 fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500356 ORANGEFS_TYPE_DIRECTORY, mode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400357
358 strncpy(new_op->upcall.req.mkdir.d_name,
Martin Brandenburg47b49482016-02-20 14:22:40 -0500359 dentry->d_name.name, ORANGEFS_NAME_MAX);
Mike Marshall274dcf52015-07-17 10:38:13 -0400360
361 ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
362
363 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500364 "Mkdir Got ORANGEFS handle %pU on fsid %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400365 &new_op->downcall.resp.mkdir.refn.khandle,
366 new_op->downcall.resp.mkdir.refn.fs_id);
367
368 if (ret < 0) {
369 gossip_debug(GOSSIP_NAME_DEBUG,
370 "%s: failed with error code %d\n",
371 __func__, ret);
372 goto out;
373 }
374
Yi Liu8bb8aef2015-11-24 15:12:14 -0500375 inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0,
Mike Marshall274dcf52015-07-17 10:38:13 -0400376 &new_op->downcall.resp.mkdir.refn);
377 if (IS_ERR(inode)) {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500378 gossip_err("*** Failed to allocate orangefs dir inode\n");
Mike Marshall274dcf52015-07-17 10:38:13 -0400379 ret = PTR_ERR(inode);
380 goto out;
381 }
382
383 gossip_debug(GOSSIP_NAME_DEBUG,
384 "Assigned dir inode new number of %pU\n",
385 get_khandle_from_ino(inode));
386
387 d_instantiate(dentry, inode);
388 unlock_new_inode(inode);
Miklos Szeredi804b1732016-10-17 10:14:23 +0200389 orangefs_set_timeout(dentry);
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -0400390 ORANGEFS_I(inode)->getattr_time = jiffies - 1;
Martin Brandenburg68a24a62017-04-25 15:38:03 -0400391 ORANGEFS_I(inode)->getattr_mask = STATX_BASIC_STATS;
Mike Marshall274dcf52015-07-17 10:38:13 -0400392
393 gossip_debug(GOSSIP_NAME_DEBUG,
Al Virof66debf2016-08-07 12:20:01 -0400394 "Inode (Directory) %pU -> %pd\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400395 get_khandle_from_ino(inode),
Al Virof66debf2016-08-07 12:20:01 -0400396 dentry);
Mike Marshall274dcf52015-07-17 10:38:13 -0400397
398 /*
399 * NOTE: we have no good way to keep nlink consistent for directories
400 * across clients; keep constant at 1.
401 */
402 SetMtimeFlag(parent);
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700403 dir->i_mtime = dir->i_ctime = current_time(dir);
Mike Marshall274dcf52015-07-17 10:38:13 -0400404 mark_inode_dirty_sync(dir);
405out:
406 op_release(new_op);
407 return ret;
408}
409
Yi Liu8bb8aef2015-11-24 15:12:14 -0500410static int orangefs_rename(struct inode *old_dir,
Mike Marshall274dcf52015-07-17 10:38:13 -0400411 struct dentry *old_dentry,
412 struct inode *new_dir,
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200413 struct dentry *new_dentry,
414 unsigned int flags)
Mike Marshall274dcf52015-07-17 10:38:13 -0400415{
Yi Liu8bb8aef2015-11-24 15:12:14 -0500416 struct orangefs_kernel_op_s *new_op;
Mike Marshall274dcf52015-07-17 10:38:13 -0400417 int ret;
418
Miklos Szeredi1cd66c92016-09-27 11:03:58 +0200419 if (flags)
420 return -EINVAL;
421
Mike Marshall274dcf52015-07-17 10:38:13 -0400422 gossip_debug(GOSSIP_NAME_DEBUG,
Al Viro96b0cff2016-05-29 15:00:34 -0400423 "orangefs_rename: called (%pd2 => %pd2) ct=%d\n",
424 old_dentry, new_dentry, d_count(new_dentry));
Mike Marshall274dcf52015-07-17 10:38:13 -0400425
Martin Brandenburg8bbb20a2016-07-28 14:46:36 -0400426 ORANGEFS_I(new_dentry->d_parent->d_inode)->getattr_time = jiffies - 1;
Martin Brandenburg71680c12016-06-09 16:32:38 -0400427
Yi Liu8bb8aef2015-11-24 15:12:14 -0500428 new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
Mike Marshall274dcf52015-07-17 10:38:13 -0400429 if (!new_op)
430 return -EINVAL;
431
Yi Liu8bb8aef2015-11-24 15:12:14 -0500432 new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn;
433 new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn;
Mike Marshall274dcf52015-07-17 10:38:13 -0400434
435 strncpy(new_op->upcall.req.rename.d_old_name,
436 old_dentry->d_name.name,
Martin Brandenburg47b49482016-02-20 14:22:40 -0500437 ORANGEFS_NAME_MAX);
Mike Marshall274dcf52015-07-17 10:38:13 -0400438 strncpy(new_op->upcall.req.rename.d_new_name,
439 new_dentry->d_name.name,
Martin Brandenburg47b49482016-02-20 14:22:40 -0500440 ORANGEFS_NAME_MAX);
Mike Marshall274dcf52015-07-17 10:38:13 -0400441
442 ret = service_operation(new_op,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500443 "orangefs_rename",
Mike Marshall274dcf52015-07-17 10:38:13 -0400444 get_interruptible_flag(old_dentry->d_inode));
445
446 gossip_debug(GOSSIP_NAME_DEBUG,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500447 "orangefs_rename: got downcall status %d\n",
Mike Marshall274dcf52015-07-17 10:38:13 -0400448 ret);
449
450 if (new_dentry->d_inode)
Deepa Dinamanic2050a42016-09-14 07:48:06 -0700451 new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode);
Mike Marshall274dcf52015-07-17 10:38:13 -0400452
453 op_release(new_op);
454 return ret;
455}
456
Yi Liu8bb8aef2015-11-24 15:12:14 -0500457/* ORANGEFS implementation of VFS inode operations for directories */
Al Viro6f3fc102016-05-14 18:46:32 -0400458const struct inode_operations orangefs_dir_inode_operations = {
Yi Liu8bb8aef2015-11-24 15:12:14 -0500459 .lookup = orangefs_lookup,
460 .get_acl = orangefs_get_acl,
461 .set_acl = orangefs_set_acl,
462 .create = orangefs_create,
463 .unlink = orangefs_unlink,
464 .symlink = orangefs_symlink,
465 .mkdir = orangefs_mkdir,
466 .rmdir = orangefs_unlink,
467 .rename = orangefs_rename,
468 .setattr = orangefs_setattr,
469 .getattr = orangefs_getattr,
Yi Liu8bb8aef2015-11-24 15:12:14 -0500470 .listxattr = orangefs_listxattr,
Martin Brandenburg933287d2016-01-30 13:46:54 -0500471 .permission = orangefs_permission,
Mike Marshall274dcf52015-07-17 10:38:13 -0400472};