Blame view

fs/orangefs/namei.c 12 KB
274dcf55b   Mike Marshall   Orangefs: kernel ...
1
2
3
4
5
6
7
8
9
10
11
  /*
   * (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 ...
12
  #include "orangefs-kernel.h"
274dcf55b   Mike Marshall   Orangefs: kernel ...
13
14
15
16
  
  /*
   * Get a newly allocated inode to go with a negative dentry.
   */
8bb8aefd5   Yi Liu   OrangeFS: Change ...
17
  static int orangefs_create(struct inode *dir,
274dcf55b   Mike Marshall   Orangefs: kernel ...
18
19
20
21
  			struct dentry *dentry,
  			umode_t mode,
  			bool exclusive)
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
22
23
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
274dcf55b   Mike Marshall   Orangefs: kernel ...
24
25
  	struct inode *inode;
  	int ret;
f66debf1b   Al Viro   orangefs: use %pd...
26
27
  	gossip_debug(GOSSIP_NAME_DEBUG, "%s: %pd
  ",
5253487e0   Mike Marshall   Orangefs: make so...
28
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
29
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
30

8bb8aefd5   Yi Liu   OrangeFS: Change ...
31
  	new_op = op_alloc(ORANGEFS_VFS_OP_CREATE);
274dcf55b   Mike Marshall   Orangefs: kernel ...
32
33
34
35
36
37
  	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 ...
38
  			       ORANGEFS_TYPE_METAFILE, mode);
274dcf55b   Mike Marshall   Orangefs: kernel ...
39
40
  
  	strncpy(new_op->upcall.req.create.d_name,
47b4948fd   Martin Brandenburg   orangefs: use ORA...
41
  		dentry->d_name.name, ORANGEFS_NAME_MAX);
274dcf55b   Mike Marshall   Orangefs: kernel ...
42
43
44
45
  
  	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
46
47
  		     "%s: %pd: handle:%pU: fsid:%d: new_op:%p: ret:%d:
  ",
5253487e0   Mike Marshall   Orangefs: make so...
48
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
49
  		     dentry,
274dcf55b   Mike Marshall   Orangefs: kernel ...
50
  		     &new_op->downcall.resp.create.refn.khandle,
5253487e0   Mike Marshall   Orangefs: make so...
51
52
53
  		     new_op->downcall.resp.create.refn.fs_id,
  		     new_op,
  		     ret);
274dcf55b   Mike Marshall   Orangefs: kernel ...
54

5253487e0   Mike Marshall   Orangefs: make so...
55
  	if (ret < 0)
274dcf55b   Mike Marshall   Orangefs: kernel ...
56
  		goto out;
274dcf55b   Mike Marshall   Orangefs: kernel ...
57

8bb8aefd5   Yi Liu   OrangeFS: Change ...
58
  	inode = orangefs_new_inode(dir->i_sb, dir, S_IFREG | mode, 0,
274dcf55b   Mike Marshall   Orangefs: kernel ...
59
60
  				&new_op->downcall.resp.create.refn);
  	if (IS_ERR(inode)) {
f66debf1b   Al Viro   orangefs: use %pd...
61
62
  		gossip_err("%s: Failed to allocate inode for file :%pd:
  ",
5253487e0   Mike Marshall   Orangefs: make so...
63
  			   __func__,
f66debf1b   Al Viro   orangefs: use %pd...
64
  			   dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
65
66
67
68
69
  		ret = PTR_ERR(inode);
  		goto out;
  	}
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
70
71
  		     "%s: Assigned inode :%pU: for file :%pd:
  ",
5253487e0   Mike Marshall   Orangefs: make so...
72
73
  		     __func__,
  		     get_khandle_from_ino(inode),
f66debf1b   Al Viro   orangefs: use %pd...
74
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
75
76
77
  
  	d_instantiate(dentry, inode);
  	unlock_new_inode(inode);
804b1737d   Miklos Szeredi   orangefs: don't u...
78
  	orangefs_set_timeout(dentry);
8bbb20a86   Martin Brandenburg   orangefs: Account...
79
  	ORANGEFS_I(inode)->getattr_time = jiffies - 1;
274dcf55b   Mike Marshall   Orangefs: kernel ...
80
81
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
82
83
  		     "%s: dentry instantiated for %pd
  ",
5253487e0   Mike Marshall   Orangefs: make so...
84
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
85
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
86
87
  
  	SetMtimeFlag(parent);
c2050a454   Deepa Dinamani   fs: Replace curre...
88
  	dir->i_mtime = dir->i_ctime = current_time(dir);
274dcf55b   Mike Marshall   Orangefs: kernel ...
89
90
91
92
  	mark_inode_dirty_sync(dir);
  	ret = 0;
  out:
  	op_release(new_op);
5253487e0   Mike Marshall   Orangefs: make so...
93
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
94
95
  		     "%s: %pd: returning %d
  ",
5253487e0   Mike Marshall   Orangefs: make so...
96
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
97
  		     dentry,
5253487e0   Mike Marshall   Orangefs: make so...
98
  		     ret);
274dcf55b   Mike Marshall   Orangefs: kernel ...
99
100
101
102
103
104
105
  	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 ...
106
  static struct dentry *orangefs_lookup(struct inode *dir, struct dentry *dentry,
274dcf55b   Mike Marshall   Orangefs: kernel ...
107
108
  				   unsigned int flags)
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
109
110
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
274dcf55b   Mike Marshall   Orangefs: kernel ...
111
112
113
114
115
116
117
118
119
120
121
122
  	struct inode *inode;
  	struct dentry *res;
  	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...
123
124
125
  	gossip_debug(GOSSIP_NAME_DEBUG, "%s called on %pd
  ",
  		     __func__, dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
126

47b4948fd   Martin Brandenburg   orangefs: use ORA...
127
  	if (dentry->d_name.len > (ORANGEFS_NAME_MAX - 1))
274dcf55b   Mike Marshall   Orangefs: kernel ...
128
  		return ERR_PTR(-ENAMETOOLONG);
8bb8aefd5   Yi Liu   OrangeFS: Change ...
129
  	new_op = op_alloc(ORANGEFS_VFS_OP_LOOKUP);
274dcf55b   Mike Marshall   Orangefs: kernel ...
130
131
  	if (!new_op)
  		return ERR_PTR(-ENOMEM);
7cec28e91   Mike Marshall   Orangefs: don't k...
132
  	new_op->upcall.req.lookup.sym_follow = ORANGEFS_LOOKUP_LINK_NO_FOLLOW;
274dcf55b   Mike Marshall   Orangefs: kernel ...
133
134
135
136
137
138
139
140
141
142
  
  	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,
47b4948fd   Martin Brandenburg   orangefs: use ORA...
143
  		ORANGEFS_NAME_MAX);
274dcf55b   Mike Marshall   Orangefs: kernel ...
144
145
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
6ceaf7818   Martin Brandenburg   orangefs: we neve...
146
147
  		     "%s: doing lookup on %s under %pU,%d
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
148
149
150
  		     __func__,
  		     new_op->upcall.req.lookup.d_name,
  		     &new_op->upcall.req.lookup.parent_refn.khandle,
6ceaf7818   Martin Brandenburg   orangefs: we neve...
151
  		     new_op->upcall.req.lookup.parent_refn.fs_id);
274dcf55b   Mike Marshall   Orangefs: kernel ...
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
  
  	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);
  
  	if (ret < 0) {
  		if (ret == -ENOENT) {
  			/*
  			 * if no inode was found, add a negative dentry to
  			 * dcache anyway; if we don't, we don't hold expected
  			 * lookup semantics and we most noticeably break
  			 * during directory renames.
  			 *
  			 * however, if the operation failed or exited, do not
  			 * add the dentry (e.g. in the case that a touch is
  			 * issued on a file that already exists that was
  			 * interrupted during this lookup -- no need to add
  			 * another negative dentry for an existing file)
  			 */
  
  			gossip_debug(GOSSIP_NAME_DEBUG,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
178
  				     "orangefs_lookup: Adding *negative* dentry "
f66debf1b   Al Viro   orangefs: use %pd...
179
180
  				     "%p for %pd
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
181
  				     dentry,
f66debf1b   Al Viro   orangefs: use %pd...
182
  				     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
183
184
185
186
187
188
189
190
191
192
  
  			d_add(dentry, NULL);
  			res = NULL;
  			goto out;
  		}
  
  		/* must be a non-recoverable error */
  		res = ERR_PTR(ret);
  		goto out;
  	}
804b1737d   Miklos Szeredi   orangefs: don't u...
193
  	orangefs_set_timeout(dentry);
31b7c1ab4   Martin Brandenburg   orangefs: Use d_t...
194

8bb8aefd5   Yi Liu   OrangeFS: Change ...
195
  	inode = orangefs_iget(dir->i_sb, &new_op->downcall.resp.lookup.refn);
274dcf55b   Mike Marshall   Orangefs: kernel ...
196
197
198
199
200
201
202
  	if (IS_ERR(inode)) {
  		gossip_debug(GOSSIP_NAME_DEBUG,
  			"error %ld from iget
  ", PTR_ERR(inode));
  		res = ERR_CAST(inode);
  		goto out;
  	}
8bbb20a86   Martin Brandenburg   orangefs: Account...
203
  	ORANGEFS_I(inode)->getattr_time = jiffies - 1;
71680c18c   Martin Brandenburg   orangefs: Cache g...
204

274dcf55b   Mike Marshall   Orangefs: kernel ...
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
  	gossip_debug(GOSSIP_NAME_DEBUG,
  		     "%s:%s:%d "
  		     "Found good inode [%lu] with count [%d]
  ",
  		     __FILE__,
  		     __func__,
  		     __LINE__,
  		     inode->i_ino,
  		     (int)atomic_read(&inode->i_count));
  
  	/* update dentry/inode pair into dcache */
  	res = d_splice_alias(inode, dentry);
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
  		     "Lookup success (inode ct = %d)
  ",
  		     (int)atomic_read(&inode->i_count));
  out:
  	op_release(new_op);
  	return res;
  }
  
  /* return 0 on success; non-zero otherwise */
8bb8aefd5   Yi Liu   OrangeFS: Change ...
228
  static int orangefs_unlink(struct inode *dir, struct dentry *dentry)
274dcf55b   Mike Marshall   Orangefs: kernel ...
229
230
  {
  	struct inode *inode = dentry->d_inode;
8bb8aefd5   Yi Liu   OrangeFS: Change ...
231
232
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
274dcf55b   Mike Marshall   Orangefs: kernel ...
233
234
235
  	int ret;
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
236
237
  		     "%s: called on %pd
  "
274dcf55b   Mike Marshall   Orangefs: kernel ...
238
239
240
  		     "  (inode %pU): Parent is %pU | fs_id %d
  ",
  		     __func__,
f66debf1b   Al Viro   orangefs: use %pd...
241
  		     dentry,
274dcf55b   Mike Marshall   Orangefs: kernel ...
242
243
244
  		     get_khandle_from_ino(inode),
  		     &parent->refn.khandle,
  		     parent->refn.fs_id);
8bb8aefd5   Yi Liu   OrangeFS: Change ...
245
  	new_op = op_alloc(ORANGEFS_VFS_OP_REMOVE);
274dcf55b   Mike Marshall   Orangefs: kernel ...
246
247
248
249
250
  	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,
47b4948fd   Martin Brandenburg   orangefs: use ORA...
251
  		ORANGEFS_NAME_MAX);
274dcf55b   Mike Marshall   Orangefs: kernel ...
252

8bb8aefd5   Yi Liu   OrangeFS: Change ...
253
  	ret = service_operation(new_op, "orangefs_unlink",
274dcf55b   Mike Marshall   Orangefs: kernel ...
254
  				get_interruptible_flag(inode));
5253487e0   Mike Marshall   Orangefs: make so...
255
256
257
258
259
  	gossip_debug(GOSSIP_NAME_DEBUG,
  		     "%s: service_operation returned:%d:
  ",
  		     __func__,
  		     ret);
274dcf55b   Mike Marshall   Orangefs: kernel ...
260
261
262
263
264
265
  	op_release(new_op);
  
  	if (!ret) {
  		drop_nlink(inode);
  
  		SetMtimeFlag(parent);
c2050a454   Deepa Dinamani   fs: Replace curre...
266
  		dir->i_mtime = dir->i_ctime = current_time(dir);
274dcf55b   Mike Marshall   Orangefs: kernel ...
267
268
269
270
  		mark_inode_dirty_sync(dir);
  	}
  	return ret;
  }
8bb8aefd5   Yi Liu   OrangeFS: Change ...
271
  static int orangefs_symlink(struct inode *dir,
274dcf55b   Mike Marshall   Orangefs: kernel ...
272
273
274
  			 struct dentry *dentry,
  			 const char *symname)
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
275
276
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
274dcf55b   Mike Marshall   Orangefs: kernel ...
277
278
279
280
281
282
283
284
285
  	struct inode *inode;
  	int mode = 755;
  	int ret;
  
  	gossip_debug(GOSSIP_NAME_DEBUG, "%s: called
  ", __func__);
  
  	if (!symname)
  		return -EINVAL;
c62da5853   Martin Brandenburg   orangefs: Avoid s...
286
287
  	if (strlen(symname)+1 > ORANGEFS_NAME_MAX)
  		return -ENAMETOOLONG;
8bb8aefd5   Yi Liu   OrangeFS: Change ...
288
  	new_op = op_alloc(ORANGEFS_VFS_OP_SYMLINK);
274dcf55b   Mike Marshall   Orangefs: kernel ...
289
290
291
292
293
294
  	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 ...
295
  			       ORANGEFS_TYPE_SYMLINK,
274dcf55b   Mike Marshall   Orangefs: kernel ...
296
297
298
299
  			       mode);
  
  	strncpy(new_op->upcall.req.sym.entry_name,
  		dentry->d_name.name,
47b4948fd   Martin Brandenburg   orangefs: use ORA...
300
301
  		ORANGEFS_NAME_MAX);
  	strncpy(new_op->upcall.req.sym.target, symname, ORANGEFS_NAME_MAX);
274dcf55b   Mike Marshall   Orangefs: kernel ...
302
303
304
305
  
  	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
306
307
  		     "Symlink Got ORANGEFS handle %pU on fsid %d (ret=%d)
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
308
309
310
311
312
313
314
315
316
317
  		     &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;
  	}
8bb8aefd5   Yi Liu   OrangeFS: Change ...
318
  	inode = orangefs_new_inode(dir->i_sb, dir, S_IFLNK | mode, 0,
274dcf55b   Mike Marshall   Orangefs: kernel ...
319
320
321
  				&new_op->downcall.resp.sym.refn);
  	if (IS_ERR(inode)) {
  		gossip_err
8bb8aefd5   Yi Liu   OrangeFS: Change ...
322
323
  		    ("*** Failed to allocate orangefs symlink inode
  ");
274dcf55b   Mike Marshall   Orangefs: kernel ...
324
325
326
327
328
329
330
331
332
333
334
  		ret = PTR_ERR(inode);
  		goto out;
  	}
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
  		     "Assigned symlink inode new number of %pU
  ",
  		     get_khandle_from_ino(inode));
  
  	d_instantiate(dentry, inode);
  	unlock_new_inode(inode);
804b1737d   Miklos Szeredi   orangefs: don't u...
335
  	orangefs_set_timeout(dentry);
8bbb20a86   Martin Brandenburg   orangefs: Account...
336
  	ORANGEFS_I(inode)->getattr_time = jiffies - 1;
274dcf55b   Mike Marshall   Orangefs: kernel ...
337
338
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
339
340
  		     "Inode (Symlink) %pU -> %pd
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
341
  		     get_khandle_from_ino(inode),
f66debf1b   Al Viro   orangefs: use %pd...
342
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
343
344
  
  	SetMtimeFlag(parent);
c2050a454   Deepa Dinamani   fs: Replace curre...
345
  	dir->i_mtime = dir->i_ctime = current_time(dir);
274dcf55b   Mike Marshall   Orangefs: kernel ...
346
347
348
349
350
351
  	mark_inode_dirty_sync(dir);
  	ret = 0;
  out:
  	op_release(new_op);
  	return ret;
  }
8bb8aefd5   Yi Liu   OrangeFS: Change ...
352
  static int orangefs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
274dcf55b   Mike Marshall   Orangefs: kernel ...
353
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
354
355
  	struct orangefs_inode_s *parent = ORANGEFS_I(dir);
  	struct orangefs_kernel_op_s *new_op;
274dcf55b   Mike Marshall   Orangefs: kernel ...
356
357
  	struct inode *inode;
  	int ret;
8bb8aefd5   Yi Liu   OrangeFS: Change ...
358
  	new_op = op_alloc(ORANGEFS_VFS_OP_MKDIR);
274dcf55b   Mike Marshall   Orangefs: kernel ...
359
360
361
362
363
364
  	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 ...
365
  			      ORANGEFS_TYPE_DIRECTORY, mode);
274dcf55b   Mike Marshall   Orangefs: kernel ...
366
367
  
  	strncpy(new_op->upcall.req.mkdir.d_name,
47b4948fd   Martin Brandenburg   orangefs: use ORA...
368
  		dentry->d_name.name, ORANGEFS_NAME_MAX);
274dcf55b   Mike Marshall   Orangefs: kernel ...
369
370
371
372
  
  	ret = service_operation(new_op, __func__, get_interruptible_flag(dir));
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
373
374
  		     "Mkdir Got ORANGEFS handle %pU on fsid %d
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
375
376
377
378
379
380
381
382
383
384
  		     &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;
  	}
8bb8aefd5   Yi Liu   OrangeFS: Change ...
385
  	inode = orangefs_new_inode(dir->i_sb, dir, S_IFDIR | mode, 0,
274dcf55b   Mike Marshall   Orangefs: kernel ...
386
387
  				&new_op->downcall.resp.mkdir.refn);
  	if (IS_ERR(inode)) {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
388
389
  		gossip_err("*** Failed to allocate orangefs dir inode
  ");
274dcf55b   Mike Marshall   Orangefs: kernel ...
390
391
392
393
394
395
396
397
398
399
400
  		ret = PTR_ERR(inode);
  		goto out;
  	}
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
  		     "Assigned dir inode new number of %pU
  ",
  		     get_khandle_from_ino(inode));
  
  	d_instantiate(dentry, inode);
  	unlock_new_inode(inode);
804b1737d   Miklos Szeredi   orangefs: don't u...
401
  	orangefs_set_timeout(dentry);
8bbb20a86   Martin Brandenburg   orangefs: Account...
402
  	ORANGEFS_I(inode)->getattr_time = jiffies - 1;
274dcf55b   Mike Marshall   Orangefs: kernel ...
403
404
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
f66debf1b   Al Viro   orangefs: use %pd...
405
406
  		     "Inode (Directory) %pU -> %pd
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
407
  		     get_khandle_from_ino(inode),
f66debf1b   Al Viro   orangefs: use %pd...
408
  		     dentry);
274dcf55b   Mike Marshall   Orangefs: kernel ...
409
410
411
412
413
414
  
  	/*
  	 * NOTE: we have no good way to keep nlink consistent for directories
  	 * across clients; keep constant at 1.
  	 */
  	SetMtimeFlag(parent);
c2050a454   Deepa Dinamani   fs: Replace curre...
415
  	dir->i_mtime = dir->i_ctime = current_time(dir);
274dcf55b   Mike Marshall   Orangefs: kernel ...
416
417
418
419
420
  	mark_inode_dirty_sync(dir);
  out:
  	op_release(new_op);
  	return ret;
  }
8bb8aefd5   Yi Liu   OrangeFS: Change ...
421
  static int orangefs_rename(struct inode *old_dir,
274dcf55b   Mike Marshall   Orangefs: kernel ...
422
423
  			struct dentry *old_dentry,
  			struct inode *new_dir,
1cd66c93b   Miklos Szeredi   fs: make remainin...
424
425
  			struct dentry *new_dentry,
  			unsigned int flags)
274dcf55b   Mike Marshall   Orangefs: kernel ...
426
  {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
427
  	struct orangefs_kernel_op_s *new_op;
274dcf55b   Mike Marshall   Orangefs: kernel ...
428
  	int ret;
1cd66c93b   Miklos Szeredi   fs: make remainin...
429
430
  	if (flags)
  		return -EINVAL;
274dcf55b   Mike Marshall   Orangefs: kernel ...
431
  	gossip_debug(GOSSIP_NAME_DEBUG,
96b0cffba   Al Viro   orangefs: don't o...
432
433
434
  		     "orangefs_rename: called (%pd2 => %pd2) ct=%d
  ",
  		     old_dentry, new_dentry, d_count(new_dentry));
274dcf55b   Mike Marshall   Orangefs: kernel ...
435

8bbb20a86   Martin Brandenburg   orangefs: Account...
436
  	ORANGEFS_I(new_dentry->d_parent->d_inode)->getattr_time = jiffies - 1;
71680c18c   Martin Brandenburg   orangefs: Cache g...
437

8bb8aefd5   Yi Liu   OrangeFS: Change ...
438
  	new_op = op_alloc(ORANGEFS_VFS_OP_RENAME);
274dcf55b   Mike Marshall   Orangefs: kernel ...
439
440
  	if (!new_op)
  		return -EINVAL;
8bb8aefd5   Yi Liu   OrangeFS: Change ...
441
442
  	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 ...
443
444
445
  
  	strncpy(new_op->upcall.req.rename.d_old_name,
  		old_dentry->d_name.name,
47b4948fd   Martin Brandenburg   orangefs: use ORA...
446
  		ORANGEFS_NAME_MAX);
274dcf55b   Mike Marshall   Orangefs: kernel ...
447
448
  	strncpy(new_op->upcall.req.rename.d_new_name,
  		new_dentry->d_name.name,
47b4948fd   Martin Brandenburg   orangefs: use ORA...
449
  		ORANGEFS_NAME_MAX);
274dcf55b   Mike Marshall   Orangefs: kernel ...
450
451
  
  	ret = service_operation(new_op,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
452
  				"orangefs_rename",
274dcf55b   Mike Marshall   Orangefs: kernel ...
453
454
455
  				get_interruptible_flag(old_dentry->d_inode));
  
  	gossip_debug(GOSSIP_NAME_DEBUG,
8bb8aefd5   Yi Liu   OrangeFS: Change ...
456
457
  		     "orangefs_rename: got downcall status %d
  ",
274dcf55b   Mike Marshall   Orangefs: kernel ...
458
459
460
  		     ret);
  
  	if (new_dentry->d_inode)
c2050a454   Deepa Dinamani   fs: Replace curre...
461
  		new_dentry->d_inode->i_ctime = current_time(new_dentry->d_inode);
274dcf55b   Mike Marshall   Orangefs: kernel ...
462
463
464
465
  
  	op_release(new_op);
  	return ret;
  }
8bb8aefd5   Yi Liu   OrangeFS: Change ...
466
  /* ORANGEFS implementation of VFS inode operations for directories */
6f3fc1070   Al Viro   orangefs: constif...
467
  const struct inode_operations orangefs_dir_inode_operations = {
8bb8aefd5   Yi Liu   OrangeFS: Change ...
468
469
470
471
472
473
474
475
476
477
478
  	.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 ...
479
  	.listxattr = orangefs_listxattr,
933287da7   Martin Brandenburg   orangefs: Impleme...
480
  	.permission = orangefs_permission,
274dcf55b   Mike Marshall   Orangefs: kernel ...
481
  };