Blame view

fs/orangefs/namei.c 11.5 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  // SPDX-License-Identifier: GPL-2.0
274dcf55b   Mike Marshall   Orangefs: kernel ...
2
3
4
5
6
7
8
9
10
11
12
  /*
   * (C) 2001 Clemson University and The University of Chicago
   *
   * See COPYING in top-level directory.
   */
  
  /*
   *  Linux VFS namei operations.
   */
  
  #include "protocol.h"
575e94612   Mike Marshall   Orangefs: change ...
13
  #include "orangefs-kernel.h"
274dcf55b   Mike Marshall   Orangefs: kernel ...
14
15
16
17
  
  /*
   * Get a newly allocated inode to go with a negative dentry.
   */
8bb8aefd5   Yi Liu   OrangeFS: Change ...
18
  static int orangefs_create(struct inode *dir,
274dcf55b   Mike Marshall   Orangefs: kernel ...
19
20
21
22
  			struct dentry *dentry,
  			umode_t mode,
  			bool exclusive)
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
23
24
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
db0267e7a   Martin Brandenburg   orangefs: call op...
25
  	struct orangefs_object_kref ref;
274dcf55b   Mike Marshall   Orangefs: kernel ...
26
  	struct inode *inode;
a55f2d861   Martin Brandenburg   orangefs: stop se...
27
  	struct iattr iattr;
274dcf55b   Mike Marshall   Orangefs: kernel ...
28
  	int ret;
f66debf1b   Al Viro   orangefs: use %pd...
29
30
  	gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd
  ",
5253487e0   Mike Marshall   Orangefs: make so...
31
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
32
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
33

8bb8aefd5   Yi Liu   OrangeFS: Change ...
34
  	new_op = op_alloc(ORANGEFS_VFS_OP_CREATE);
274dcf55b   Mike Marshall   Orangefs: kernel ...
35
36
37
38
39
40
  	if (!new_op)
  		return -ENOMEM;
  
  	new_op->upcall.req.create.parent_refn = parent->refn;
  
  	fill_default_sys_attrs(new_op->upcall.req.create.attributes,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
41
  			       ORANGEFS_TYPE_METAFILE, mode);
274dcf55b   Mike Marshall   Orangefs: kernel ...
42
43
  
  	strncpy(new_op->upcall.req.create.d_name,
6bdfb48da   Xiongfeng Wang   orangefs: use cor...
44
  		dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
274dcf55b   Mike Marshall   Orangefs: kernel ...
45
46
47
48
  
  	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
49
50
  		     "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:
  ",
5253487e0   Mike Marshall   Orangefs: make so...
51
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
52
  		     dentry,
274dcf55b   Mike Marshall   Orangefs: kernel ...
53
  		     &new_op->downcall.resp.create.refn.khandle,
5253487e0   Mike Marshall   Orangefs: make so...
54
55
56
  		     new_op->downcall.resp.create.refn.fs_id,
  		     new_op,
  		     ret);
274dcf55b   Mike Marshall   Orangefs: kernel ...
57

5253487e0   Mike Marshall   Orangefs: make so...
58
  	if (ret < 0)
274dcf55b   Mike Marshall   Orangefs: kernel ...
59
  		goto out;
274dcf55b   Mike Marshall   Orangefs: kernel ...
60

db0267e7a   Martin Brandenburg   orangefs: call op...
61
  	ref = new_op->downcall.resp.create.refn;
db0267e7a   Martin Brandenburg   orangefs: call op...
62
63
  
  	inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0, &ref);
274dcf55b   Mike Marshall   Orangefs: kernel ...
64
  	if (IS_ERR(inode)) {
f66debf1b   Al Viro   orangefs: use %pd...
65
66
  		gossip_err("%s: Failed to allocate inode for file :%pd:
  ",
5253487e0   Mike Marshall   Orangefs: make so...
67
  			   __func__,
f66debf1b   Al Viro   orangefs: use %pd...
68
  			   dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
69
70
71
72
73
  		ret = PTR_ERR(inode);
  		goto out;
  	}
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
74
75
  		     "%s: Assigned inode :%pU: for file :%pd:
  ",
5253487e0   Mike Marshall   Orangefs: make so...
76
77
  		     __func__,
  		     get_khandle_from_ino(inode),
f66debf1b   Al Viro   orangefs: use %pd...
78
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
79

1e2e547a9   Al Viro   do d_instantiate/...
80
  	d_instantiate_new(dentry, inode);
804b1737d   Miklos Szeredi   orangefs: don't u...
81
  	orangefs_set_timeout(dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
82
83
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
84
85
  		     "%s: dentry instantiated for %pd
  ",
5253487e0   Mike Marshall   Orangefs: make so...
86
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
87
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
88

a55f2d861   Martin Brandenburg   orangefs: stop se...
89
  	memset(&iattr, 0, sizeof iattr);
afd9fb2a3   Martin Brandenburg   orangefs: reorgan...
90
91
92
  	iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
  	iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
  	__orangefs_setattr(dir, &iattr);
274dcf55b   Mike Marshall   Orangefs: kernel ...
93
94
  	ret = 0;
  out:
34e6148a2   Mike Marshall   orangefs: some er...
95
  	op_release(new_op);
5253487e0   Mike Marshall   Orangefs: make so...
96
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
97
98
  		     "%s: %pd: returning %d
  ",
5253487e0   Mike Marshall   Orangefs: make so...
99
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
100
  		     dentry,
5253487e0   Mike Marshall   Orangefs: make so...
101
  		     ret);
274dcf55b   Mike Marshall   Orangefs: kernel ...
102
103
104
105
106
107
108
  	return ret;
  }
  
  /*
   * Attempt to resolve an object name (dentry->d_name), parent handle, and
   * fsid into a handle for the object.
   */
8bb8aefd5   Yi Liu   OrangeFS: Change ...
109
  static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
274dcf55b   Mike Marshall   Orangefs: kernel ...
110
111
  				   unsigned int flags)
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
112
113
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
274dcf55b   Mike Marshall   Orangefs: kernel ...
114
  	struct inode *inode;
274dcf55b   Mike Marshall   Orangefs: kernel ...
115
116
117
118
119
120
121
122
123
124
  	int ret = -EINVAL;
  
  	/*
  	 * in theory we could skip a lookup here (if the intent is to
  	 * create) in order to avoid a potentially failed lookup, but
  	 * leaving it in can skip a valid lookup and try to create a file
  	 * that already exists (e.g. the vfs already handles checking for
  	 * -EEXIST on O_EXCL opens, which is broken if we skip this lookup
  	 * in the create path)
  	 */
f66debf1b   Al Viro   orangefs: use %pd...
125
126
127
  	gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd
  ",
  		     __func__, dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
128

47b4948fd   Martin Brandenburg   orangefs: use ORA...
129
  	if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1))
274dcf55b   Mike Marshall   Orangefs: kernel ...
130
  		return ERR_PTR(-ENAMETOOLONG);
8bb8aefd5   Yi Liu   OrangeFS: Change ...
131
  	new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
274dcf55b   Mike Marshall   Orangefs: kernel ...
132
133
  	if (!new_op)
  		return ERR_PTR(-ENOMEM);
7cec28e91   Mike Marshall   Orangefs: don't k...
134
  	new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
274dcf55b   Mike Marshall   Orangefs: kernel ...
135
136
137
138
139
140
141
142
143
144
  
  	gossip_debug(GOSSIP_NAME_DEBUG, "%s:%s:%d using parent %pU
  ",
  		     __FILE__,
  		     __func__,
  		     __LINE__,
  		     &parent->refn.khandle);
  	new_op->upcall.req.lookup.parent_refn = parent->refn;
  
  	strncpy(new_op->upcall.req.lookup.d_name, dentry->d_name.name,
6bdfb48da   Xiongfeng Wang   orangefs: use cor...
145
  		ORANGEFS_NAME_MAX - 1);
274dcf55b   Mike Marshall   Orangefs: kernel ...
146
147
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
6ceaf7818   Martin Brandenburg   orangefs: we neve...
148
149
  		     "%s: doing lookup on %s under %pU,%d
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
150
151
152
  		     __func__,
  		     new_op->upcall.req.lookup.d_name,
  		     &new_op->upcall.req.lookup.parent_refn.khandle,
6ceaf7818   Martin Brandenburg   orangefs: we neve...
153
  		     new_op->upcall.req.lookup.parent_refn.fs_id);
274dcf55b   Mike Marshall   Orangefs: kernel ...
154
155
156
157
158
159
160
161
162
  
  	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
  		     "Lookup Got %pU, fsid %d (ret=%d)
  ",
  		     &new_op->downcall.resp.lookup.refn.khandle,
  		     new_op->downcall.resp.lookup.refn.fs_id,
  		     ret);
22fc9db29   Mike Marshall   orangefs: no need...
163
  	if (ret == 0) {
04bb1ba14   Al Viro   orangefs_lookup: ...
164
165
166
167
168
  		orangefs_set_timeout(dentry);
  		inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
  	} else if (ret == -ENOENT) {
  		inode = NULL;
  	} else {
274dcf55b   Mike Marshall   Orangefs: kernel ...
169
  		/* must be a non-recoverable error */
04bb1ba14   Al Viro   orangefs_lookup: ...
170
  		inode = ERR_PTR(ret);
274dcf55b   Mike Marshall   Orangefs: kernel ...
171
  	}
274dcf55b   Mike Marshall   Orangefs: kernel ...
172
  	op_release(new_op);
04bb1ba14   Al Viro   orangefs_lookup: ...
173
  	return d_splice_alias(inode, dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
174
175
176
  }
  
  /* return 0 on success; non-zero otherwise */
8bb8aefd5   Yi Liu   OrangeFS: Change ...
177
  static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
274dcf55b   Mike Marshall   Orangefs: kernel ...
178
179
  {
  	struct inode *inode = dentry->d_inode;
8bb8aefd5   Yi Liu   OrangeFS: Change ...
180
181
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
a55f2d861   Martin Brandenburg   orangefs: stop se...
182
  	struct iattr iattr;
274dcf55b   Mike Marshall   Orangefs: kernel ...
183
184
185
  	int ret;
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
186
187
  		     "%s: called on %pd
  "
274dcf55b   Mike Marshall   Orangefs: kernel ...
188
189
190
  		     "  (inode %pU): Parent is %pU | fs_id %d
  ",
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
191
  		     dentry,
274dcf55b   Mike Marshall   Orangefs: kernel ...
192
193
194
  		     get_khandle_from_ino(inode),
  		     &parent->refn.khandle,
  		     parent->refn.fs_id);
8bb8aefd5   Yi Liu   OrangeFS: Change ...
195
  	new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
274dcf55b   Mike Marshall   Orangefs: kernel ...
196
197
198
199
200
  	if (!new_op)
  		return -ENOMEM;
  
  	new_op->upcall.req.remove.parent_refn = parent->refn;
  	strncpy(new_op->upcall.req.remove.d_name, dentry->d_name.name,
6bdfb48da   Xiongfeng Wang   orangefs: use cor...
201
  		ORANGEFS_NAME_MAX - 1);
274dcf55b   Mike Marshall   Orangefs: kernel ...
202

8bb8aefd5   Yi Liu   OrangeFS: Change ...
203
  	ret = service_operation(new_op, "orangefs_unlink",
274dcf55b   Mike Marshall   Orangefs: kernel ...
204
  				get_interruptible_flag(inode));
5253487e0   Mike Marshall   Orangefs: make so...
205
206
207
208
209
  	gossip_debug(GOSSIP_NAME_DEBUG,
  		     "%s: service_operation returned:%d:
  ",
  		     __func__,
  		     ret);
274dcf55b   Mike Marshall   Orangefs: kernel ...
210
211
212
213
  	op_release(new_op);
  
  	if (!ret) {
  		drop_nlink(inode);
a55f2d861   Martin Brandenburg   orangefs: stop se...
214
  		memset(&iattr, 0, sizeof iattr);
afd9fb2a3   Martin Brandenburg   orangefs: reorgan...
215
216
217
  		iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
  		iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
  		__orangefs_setattr(dir, &iattr);
274dcf55b   Mike Marshall   Orangefs: kernel ...
218
219
220
  	}
  	return ret;
  }
8bb8aefd5   Yi Liu   OrangeFS: Change ...
221
  static int orangefs_symlink(struct inode *dir,
274dcf55b   Mike Marshall   Orangefs: kernel ...
222
223
224
  			 struct dentry *dentry,
  			 const char *symname)
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
225
226
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
db0267e7a   Martin Brandenburg   orangefs: call op...
227
  	struct orangefs_object_kref ref;
274dcf55b   Mike Marshall   Orangefs: kernel ...
228
  	struct inode *inode;
a55f2d861   Martin Brandenburg   orangefs: stop se...
229
  	struct iattr iattr;
c42293a95   Artur ÅšwigoÅ„   orangefs: Add oct...
230
  	int mode = 0755;
274dcf55b   Mike Marshall   Orangefs: kernel ...
231
232
233
234
235
236
237
  	int ret;
  
  	gossip_debug(GOSSIP_NAME_DEBUG, "%s: called
  ", __func__);
  
  	if (!symname)
  		return -EINVAL;
c62da5853   Martin Brandenburg   orangefs: Avoid s...
238
239
  	if (strlen(symname)+1 > ORANGEFS_NAME_MAX)
  		return -ENAMETOOLONG;
8bb8aefd5   Yi Liu   OrangeFS: Change ...
240
  	new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
274dcf55b   Mike Marshall   Orangefs: kernel ...
241
242
243
244
245
246
  	if (!new_op)
  		return -ENOMEM;
  
  	new_op->upcall.req.sym.parent_refn = parent->refn;
  
  	fill_default_sys_attrs(new_op->upcall.req.sym.attributes,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
247
  			       ORANGEFS_TYPE_SYMLINK,
274dcf55b   Mike Marshall   Orangefs: kernel ...
248
249
250
251
  			       mode);
  
  	strncpy(new_op->upcall.req.sym.entry_name,
  		dentry->d_name.name,
6bdfb48da   Xiongfeng Wang   orangefs: use cor...
252
253
  		ORANGEFS_NAME_MAX - 1);
  	strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX - 1);
274dcf55b   Mike Marshall   Orangefs: kernel ...
254
255
256
257
  
  	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
258
259
  		     "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
260
261
262
263
264
265
266
267
268
269
  		     &new_op->downcall.resp.sym.refn.khandle,
  		     new_op->downcall.resp.sym.refn.fs_id, ret);
  
  	if (ret < 0) {
  		gossip_debug(GOSSIP_NAME_DEBUG,
  			    "%s: failed with error code %d
  ",
  			    __func__, ret);
  		goto out;
  	}
db0267e7a   Martin Brandenburg   orangefs: call op...
270
  	ref = new_op->downcall.resp.sym.refn;
db0267e7a   Martin Brandenburg   orangefs: call op...
271
272
  
  	inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0, &ref);
274dcf55b   Mike Marshall   Orangefs: kernel ...
273
274
  	if (IS_ERR(inode)) {
  		gossip_err
8bb8aefd5   Yi Liu   OrangeFS: Change ...
275
276
  		    ("*** Failed to allocate orangefs symlink inode
  ");
274dcf55b   Mike Marshall   Orangefs: kernel ...
277
278
279
  		ret = PTR_ERR(inode);
  		goto out;
  	}
f6a4b4c9d   Martin Brandenburg   orangefs: set i_s...
280
281
282
283
284
285
286
  	/*
  	 * This is necessary because orangefs_inode_getattr will not
  	 * re-read symlink size as it is impossible for it to change.
  	 * Invalidating the cache does not help.  orangefs_new_inode
  	 * does not set the correct size (it does not know symname).
  	 */
  	inode->i_size = strlen(symname);
274dcf55b   Mike Marshall   Orangefs: kernel ...
287
288
289
290
291
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
  		     "Assigned symlink inode new number of %pU
  ",
  		     get_khandle_from_ino(inode));
1e2e547a9   Al Viro   do d_instantiate/...
292
  	d_instantiate_new(dentry, inode);
804b1737d   Miklos Szeredi   orangefs: don't u...
293
  	orangefs_set_timeout(dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
294
295
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
296
297
  		     "Inode (Symlink) %pU -> %pd
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
298
  		     get_khandle_from_ino(inode),
f66debf1b   Al Viro   orangefs: use %pd...
299
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
300

a55f2d861   Martin Brandenburg   orangefs: stop se...
301
  	memset(&iattr, 0, sizeof iattr);
afd9fb2a3   Martin Brandenburg   orangefs: reorgan...
302
303
304
  	iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
  	iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
  	__orangefs_setattr(dir, &iattr);
274dcf55b   Mike Marshall   Orangefs: kernel ...
305
306
  	ret = 0;
  out:
34e6148a2   Mike Marshall   orangefs: some er...
307
  	op_release(new_op);
274dcf55b   Mike Marshall   Orangefs: kernel ...
308
309
  	return ret;
  }
8bb8aefd5   Yi Liu   OrangeFS: Change ...
310
  static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
274dcf55b   Mike Marshall   Orangefs: kernel ...
311
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
312
313
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
db0267e7a   Martin Brandenburg   orangefs: call op...
314
  	struct orangefs_object_kref ref;
274dcf55b   Mike Marshall   Orangefs: kernel ...
315
  	struct inode *inode;
a55f2d861   Martin Brandenburg   orangefs: stop se...
316
  	struct iattr iattr;
274dcf55b   Mike Marshall   Orangefs: kernel ...
317
  	int ret;
8bb8aefd5   Yi Liu   OrangeFS: Change ...
318
  	new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
274dcf55b   Mike Marshall   Orangefs: kernel ...
319
320
321
322
323
324
  	if (!new_op)
  		return -ENOMEM;
  
  	new_op->upcall.req.mkdir.parent_refn = parent->refn;
  
  	fill_default_sys_attrs(new_op->upcall.req.mkdir.attributes,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
325
  			      ORANGEFS_TYPE_DIRECTORY, mode);
274dcf55b   Mike Marshall   Orangefs: kernel ...
326
327
  
  	strncpy(new_op->upcall.req.mkdir.d_name,
6bdfb48da   Xiongfeng Wang   orangefs: use cor...
328
  		dentry->d_name.name, ORANGEFS_NAME_MAX - 1);
274dcf55b   Mike Marshall   Orangefs: kernel ...
329
330
331
332
  
  	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
333
334
  		     "Mkdir Got ORANGEFS handle %pU on fsid %d
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
335
336
337
338
339
340
341
342
343
344
  		     &new_op->downcall.resp.mkdir.refn.khandle,
  		     new_op->downcall.resp.mkdir.refn.fs_id);
  
  	if (ret < 0) {
  		gossip_debug(GOSSIP_NAME_DEBUG,
  			     "%s: failed with error code %d
  ",
  			     __func__, ret);
  		goto out;
  	}
db0267e7a   Martin Brandenburg   orangefs: call op...
345
  	ref = new_op->downcall.resp.mkdir.refn;
db0267e7a   Martin Brandenburg   orangefs: call op...
346
347
  
  	inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0, &ref);
274dcf55b   Mike Marshall   Orangefs: kernel ...
348
  	if (IS_ERR(inode)) {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
349
350
  		gossip_err("*** Failed to allocate orangefs dir inode
  ");
274dcf55b   Mike Marshall   Orangefs: kernel ...
351
352
353
354
355
356
357
358
  		ret = PTR_ERR(inode);
  		goto out;
  	}
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
  		     "Assigned dir inode new number of %pU
  ",
  		     get_khandle_from_ino(inode));
1e2e547a9   Al Viro   do d_instantiate/...
359
  	d_instantiate_new(dentry, inode);
804b1737d   Miklos Szeredi   orangefs: don't u...
360
  	orangefs_set_timeout(dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
361
362
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
363
364
  		     "Inode (Directory) %pU -> %pd
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
365
  		     get_khandle_from_ino(inode),
f66debf1b   Al Viro   orangefs: use %pd...
366
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
367
368
369
370
371
  
  	/*
  	 * NOTE: we have no good way to keep nlink consistent for directories
  	 * across clients; keep constant at 1.
  	 */
a55f2d861   Martin Brandenburg   orangefs: stop se...
372
  	memset(&iattr, 0, sizeof iattr);
afd9fb2a3   Martin Brandenburg   orangefs: reorgan...
373
374
375
  	iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
  	iattr.ia_mtime = iattr.ia_ctime = current_time(dir);
  	__orangefs_setattr(dir, &iattr);
274dcf55b   Mike Marshall   Orangefs: kernel ...
376
  out:
34e6148a2   Mike Marshall   orangefs: some er...
377
  	op_release(new_op);
274dcf55b   Mike Marshall   Orangefs: kernel ...
378
379
  	return ret;
  }
8bb8aefd5   Yi Liu   OrangeFS: Change ...
380
  static int orangefs_rename(struct inode *old_dir,
274dcf55b   Mike Marshall   Orangefs: kernel ...
381
382
  			struct dentry *old_dentry,
  			struct inode *new_dir,
1cd66c93b   Miklos Szeredi   fs: make remainin...
383
384
  			struct dentry *new_dentry,
  			unsigned int flags)
274dcf55b   Mike Marshall   Orangefs: kernel ...
385
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
386
  	struct orangefs_kernel_op_s *new_op;
5e7f1d433   Martin Brandenburg   orangefs: update ...
387
  	struct iattr iattr;
274dcf55b   Mike Marshall   Orangefs: kernel ...
388
  	int ret;
1cd66c93b   Miklos Szeredi   fs: make remainin...
389
390
  	if (flags)
  		return -EINVAL;
274dcf55b   Mike Marshall   Orangefs: kernel ...
391
  	gossip_debug(GOSSIP_NAME_DEBUG,
96b0cffba   Al Viro   orangefs: don't o...
392
393
394
  		     "orangefs_rename: called (%pd2 => %pd2) ct=%d
  ",
  		     old_dentry, new_dentry, d_count(new_dentry));
274dcf55b   Mike Marshall   Orangefs: kernel ...
395

5e7f1d433   Martin Brandenburg   orangefs: update ...
396
  	memset(&iattr, 0, sizeof iattr);
afd9fb2a3   Martin Brandenburg   orangefs: reorgan...
397
398
399
  	iattr.ia_valid |= ATTR_MTIME | ATTR_CTIME;
  	iattr.ia_mtime = iattr.ia_ctime = current_time(new_dir);
  	__orangefs_setattr(new_dir, &iattr);
71680c18c   Martin Brandenburg   orangefs: Cache g...
400

8bb8aefd5   Yi Liu   OrangeFS: Change ...
401
  	new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
274dcf55b   Mike Marshall   Orangefs: kernel ...
402
403
  	if (!new_op)
  		return -EINVAL;
8bb8aefd5   Yi Liu   OrangeFS: Change ...
404
405
  	new_op->upcall.req.rename.old_parent_refn = ORANGEFS_I(old_dir)->refn;
  	new_op->upcall.req.rename.new_parent_refn = ORANGEFS_I(new_dir)->refn;
274dcf55b   Mike Marshall   Orangefs: kernel ...
406
407
408
  
  	strncpy(new_op->upcall.req.rename.d_old_name,
  		old_dentry->d_name.name,
6bdfb48da   Xiongfeng Wang   orangefs: use cor...
409
  		ORANGEFS_NAME_MAX - 1);
274dcf55b   Mike Marshall   Orangefs: kernel ...
410
411
  	strncpy(new_op->upcall.req.rename.d_new_name,
  		new_dentry->d_name.name,
6bdfb48da   Xiongfeng Wang   orangefs: use cor...
412
  		ORANGEFS_NAME_MAX - 1);
274dcf55b   Mike Marshall   Orangefs: kernel ...
413
414
  
  	ret = service_operation(new_op,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
415
  				"orangefs_rename",
274dcf55b   Mike Marshall   Orangefs: kernel ...
416
417
418
  				get_interruptible_flag(old_dentry->d_inode));
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
419
420
  		     "orangefs_rename: got downcall status %d
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
421
422
423
  		     ret);
  
  	if (new_dentry->d_inode)
c2050a454   Deepa Dinamani   fs: Replace curre...
424
  		new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode);
274dcf55b   Mike Marshall   Orangefs: kernel ...
425
426
427
428
  
  	op_release(new_op);
  	return ret;
  }
8bb8aefd5   Yi Liu   OrangeFS: Change ...
429
  /* ORANGEFS implementation of VFS inode operations for directories */
6f3fc1070   Al Viro   orangefs: constif...
430
  const struct inode_operations orangefs_dir_inode_operations = {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
431
432
433
434
435
436
437
438
439
440
441
  	.lookup = orangefs_lookup,
  	.get_acl = orangefs_get_acl,
  	.set_acl = orangefs_set_acl,
  	.create = orangefs_create,
  	.unlink = orangefs_unlink,
  	.symlink = orangefs_symlink,
  	.mkdir = orangefs_mkdir,
  	.rmdir = orangefs_unlink,
  	.rename = orangefs_rename,
  	.setattr = orangefs_setattr,
  	.getattr = orangefs_getattr,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
442
  	.listxattr = orangefs_listxattr,
933287da7   Martin Brandenburg   orangefs: Impleme...
443
  	.permission = orangefs_permission,
a55f2d861   Martin Brandenburg   orangefs: stop se...
444
  	.update_time = orangefs_update_time,
274dcf55b   Mike Marshall   Orangefs: kernel ...
445
  };