Merge remote-tracking branch 'staging/staging-next'
[deliverable/linux.git] / drivers / staging / lustre / lustre / llite / namei.c
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
6a5b99a4 18 * http://www.gnu.org/licenses/gpl-2.0.html
d7e09d03 19 *
d7e09d03
PT
20 * GPL HEADER END
21 */
22/*
23 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
25 *
1dc563a6 26 * Copyright (c) 2011, 2015, Intel Corporation.
d7e09d03
PT
27 */
28/*
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
31 */
32
33#include <linux/fs.h>
34#include <linux/sched.h>
35#include <linux/mm.h>
36#include <linux/quotaops.h>
37#include <linux/highmem.h>
38#include <linux/pagemap.h>
39#include <linux/security.h>
40
41#define DEBUG_SUBSYSTEM S_LLITE
42
67a235f5
GKH
43#include "../include/obd_support.h"
44#include "../include/lustre_fid.h"
45#include "../include/lustre_lite.h"
46#include "../include/lustre_dlm.h"
47#include "../include/lustre_ver.h"
d7e09d03
PT
48#include "llite_internal.h"
49
50static int ll_create_it(struct inode *, struct dentry *,
51 int, struct lookup_intent *);
52
5a3cd992 53/* called from iget5_locked->find_inode() under inode_hash_lock spinlock */
d7e09d03
PT
54static int ll_test_inode(struct inode *inode, void *opaque)
55{
56 struct ll_inode_info *lli = ll_i2info(inode);
57 struct lustre_md *md = opaque;
58
2e1b5b8b 59 if (unlikely(!(md->body->mbo_valid & OBD_MD_FLID))) {
d7e09d03
PT
60 CERROR("MDS body missing FID\n");
61 return 0;
62 }
63
2e1b5b8b 64 if (!lu_fid_eq(&lli->lli_fid, &md->body->mbo_fid1))
d7e09d03
PT
65 return 0;
66
67 return 1;
68}
69
70static int ll_set_inode(struct inode *inode, void *opaque)
71{
72 struct ll_inode_info *lli = ll_i2info(inode);
73 struct mdt_body *body = ((struct lustre_md *)opaque)->body;
74
2e1b5b8b 75 if (unlikely(!(body->mbo_valid & OBD_MD_FLID))) {
d7e09d03
PT
76 CERROR("MDS body missing FID\n");
77 return -EINVAL;
78 }
79
2e1b5b8b
JH
80 lli->lli_fid = body->mbo_fid1;
81 if (unlikely(!(body->mbo_valid & OBD_MD_FLTYPE))) {
267d9c8a
LM
82 CERROR("Can not initialize inode " DFID
83 " without object type: valid = %#llx\n",
2e1b5b8b 84 PFID(&lli->lli_fid), body->mbo_valid);
d7e09d03
PT
85 return -EINVAL;
86 }
87
2e1b5b8b 88 inode->i_mode = (inode->i_mode & ~S_IFMT) | (body->mbo_mode & S_IFMT);
d7e09d03
PT
89 if (unlikely(inode->i_mode == 0)) {
90 CERROR("Invalid inode "DFID" type\n", PFID(&lli->lli_fid));
91 return -EINVAL;
92 }
93
94 ll_lli_init(lli);
95
96 return 0;
97}
98
c3397e7e 99/**
100 * Get an inode by inode number(@hash), which is already instantiated by
101 * the intent lookup).
d7e09d03
PT
102 */
103struct inode *ll_iget(struct super_block *sb, ino_t hash,
104 struct lustre_md *md)
105{
106 struct inode *inode;
c3397e7e 107 int rc = 0;
d7e09d03
PT
108
109 LASSERT(hash != 0);
110 inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode, md);
c3397e7e 111 if (!inode)
112 return ERR_PTR(-ENOMEM);
113
114 if (inode->i_state & I_NEW) {
115 rc = ll_read_inode2(inode, md);
116 if (!rc && S_ISREG(inode->i_mode) &&
117 !ll_i2info(inode)->lli_clob) {
118 CDEBUG(D_INODE, "%s: apply lsm %p to inode "DFID"\n",
119 ll_get_fsname(sb, NULL, 0), md->lsm,
120 PFID(ll_inode2fid(inode)));
121 rc = cl_file_inode_init(inode, md);
122 }
123 if (rc) {
124 make_bad_inode(inode);
125 unlock_new_inode(inode);
126 iput(inode);
127 inode = ERR_PTR(rc);
128 } else {
129 unlock_new_inode(inode);
130 }
131 } else if (!(inode->i_state & (I_FREEING | I_CLEAR))) {
132 rc = ll_update_inode(inode, md);
133 CDEBUG(D_VFSTRACE, "got inode: "DFID"(%p): rc = %d\n",
2e1b5b8b 134 PFID(&md->body->mbo_fid1), inode, rc);
c3397e7e 135 if (rc) {
136 make_bad_inode(inode);
137 iput(inode);
138 inode = ERR_PTR(rc);
da5ecb4d 139 }
d7e09d03 140 }
0a3bdb00 141 return inode;
d7e09d03
PT
142}
143
144static void ll_invalidate_negative_children(struct inode *dir)
145{
146 struct dentry *dentry, *tmp_subdir;
d7e09d03 147
2bbec0ed 148 spin_lock(&dir->i_lock);
9d5be52f 149 hlist_for_each_entry(dentry, &dir->i_dentry, d_u.d_alias) {
d7e09d03
PT
150 spin_lock(&dentry->d_lock);
151 if (!list_empty(&dentry->d_subdirs)) {
152 struct dentry *child;
153
154 list_for_each_entry_safe(child, tmp_subdir,
155 &dentry->d_subdirs,
946e51f2 156 d_child) {
2b0143b5 157 if (d_really_is_negative(child))
b1d2a127 158 d_lustre_invalidate(child, 1);
d7e09d03
PT
159 }
160 }
161 spin_unlock(&dentry->d_lock);
162 }
2bbec0ed 163 spin_unlock(&dir->i_lock);
d7e09d03
PT
164}
165
2de35386 166int ll_test_inode_by_fid(struct inode *inode, void *opaque)
167{
168 return lu_fid_eq(&ll_i2info(inode)->lli_fid, opaque);
169}
170
d7e09d03
PT
171int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
172 void *data, int flag)
173{
d7e09d03 174 struct lustre_handle lockh;
45b2a010 175 int rc;
d7e09d03
PT
176
177 switch (flag) {
178 case LDLM_CB_BLOCKING:
179 ldlm_lock2handle(lock, &lockh);
180 rc = ldlm_cli_cancel(&lockh, LCF_ASYNC);
181 if (rc < 0) {
45b2a010 182 CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
0a3bdb00 183 return rc;
d7e09d03
PT
184 }
185 break;
186 case LDLM_CB_CANCELING: {
187 struct inode *inode = ll_inode_from_resource_lock(lock);
d7e09d03 188 __u64 bits = lock->l_policy_data.l_inodebits.bits;
d7e09d03
PT
189
190 /* Inode is set to lock->l_resource->lr_lvb_inode
c0894c6c
OD
191 * for mdc - bug 24555
192 */
6e16818b 193 LASSERT(!lock->l_ast_data);
d7e09d03 194
6e16818b 195 if (!inode)
d7e09d03
PT
196 break;
197
45b2a010 198 /* Invalidate all dentries associated with this inode */
5a9a80ba 199 LASSERT(ldlm_is_canceling(lock));
7fc1f831 200
45b2a010
JH
201 if (!fid_res_name_eq(ll_inode2fid(inode),
202 &lock->l_resource->lr_name)) {
203 LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)",
204 PFID(ll_inode2fid(inode)), inode);
205 LBUG();
206 }
207
208 if (bits & MDS_INODELOCK_XATTR) {
7fc1f831 209 ll_xattr_cache_destroy(inode);
45b2a010
JH
210 bits &= ~MDS_INODELOCK_XATTR;
211 }
7fc1f831 212
d7e09d03 213 /* For OPEN locks we differentiate between lock modes
c0894c6c
OD
214 * LCK_CR, LCK_CW, LCK_PR - bug 22891
215 */
d7e09d03 216 if (bits & MDS_INODELOCK_OPEN)
45b2a010 217 ll_have_md_lock(inode, &bits, lock->l_req_mode);
d7e09d03
PT
218
219 if (bits & MDS_INODELOCK_OPEN) {
45b2a010
JH
220 fmode_t fmode;
221
d7e09d03
PT
222 switch (lock->l_req_mode) {
223 case LCK_CW:
45b2a010 224 fmode = FMODE_WRITE;
d7e09d03
PT
225 break;
226 case LCK_PR:
45b2a010 227 fmode = FMODE_EXEC;
d7e09d03
PT
228 break;
229 case LCK_CR:
45b2a010 230 fmode = FMODE_READ;
d7e09d03
PT
231 break;
232 default:
45b2a010
JH
233 LDLM_ERROR(lock, "bad lock mode for OPEN lock");
234 LBUG();
d7e09d03 235 }
45b2a010
JH
236
237 ll_md_real_close(inode, fmode);
d7e09d03
PT
238 }
239
45b2a010
JH
240 if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
241 MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM))
242 ll_have_md_lock(inode, &bits, LCK_MINMODE);
243
d7e09d03 244 if (bits & MDS_INODELOCK_LAYOUT) {
45b2a010
JH
245 struct cl_object_conf conf = {
246 .coc_opc = OBJECT_CONF_INVALIDATE,
247 .coc_inode = inode,
248 };
d7e09d03 249
d7e09d03 250 rc = ll_layout_conf(inode, &conf);
45b2a010
JH
251 if (rc < 0)
252 CDEBUG(D_INODE, "cannot invalidate layout of "
253 DFID": rc = %d\n",
254 PFID(ll_inode2fid(inode)), rc);
d7e09d03
PT
255 }
256
ae5ef67b 257 if (bits & MDS_INODELOCK_UPDATE) {
45b2a010
JH
258 struct ll_inode_info *lli = ll_i2info(inode);
259
ae5ef67b 260 spin_lock(&lli->lli_lock);
d7e09d03 261 lli->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
ae5ef67b
SB
262 spin_unlock(&lli->lli_lock);
263 }
d7e09d03 264
45b2a010 265 if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
2de35386 266 struct ll_inode_info *lli = ll_i2info(inode);
267
268 CDEBUG(D_INODE, "invalidating inode "DFID" lli = %p, pfid = "DFID"\n",
269 PFID(ll_inode2fid(inode)), lli,
270 PFID(&lli->lli_pfid));
271
d7e09d03 272 truncate_inode_pages(inode->i_mapping, 0);
2de35386 273
274 if (unlikely(!fid_is_zero(&lli->lli_pfid))) {
275 struct inode *master_inode = NULL;
276 unsigned long hash;
277
278 /*
279 * This is slave inode, since all of the child
280 * dentry is connected on the master inode, so
281 * we have to invalidate the negative children
282 * on master inode
283 */
284 CDEBUG(D_INODE, "Invalidate s"DFID" m"DFID"\n",
285 PFID(ll_inode2fid(inode)),
286 PFID(&lli->lli_pfid));
287
288 hash = cl_fid_build_ino(&lli->lli_pfid,
289 ll_need_32bit_api(ll_i2sbi(inode)));
290
291 master_inode = ilookup5(inode->i_sb, hash,
292 ll_test_inode_by_fid,
293 (void *)&lli->lli_pfid);
294 if (master_inode && !IS_ERR(master_inode)) {
295 ll_invalidate_negative_children(master_inode);
296 iput(master_inode);
297 }
298 } else {
299 ll_invalidate_negative_children(inode);
300 }
d7e09d03
PT
301 }
302
45b2a010 303 if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) &&
6e16818b 304 inode->i_sb->s_root &&
5242d422 305 !is_root_inode(inode))
d7e09d03 306 ll_invalidate_aliases(inode);
45b2a010 307
d7e09d03
PT
308 iput(inode);
309 break;
310 }
311 default:
312 LBUG();
313 }
314
0a3bdb00 315 return 0;
d7e09d03
PT
316}
317
318__u32 ll_i2suppgid(struct inode *i)
319{
4b1a25f0
PT
320 if (in_group_p(i->i_gid))
321 return (__u32)from_kgid(&init_user_ns, i->i_gid);
d7e09d03
PT
322 else
323 return (__u32)(-1);
324}
325
326/* Pack the required supplementary groups into the supplied groups array.
327 * If we don't need to use the groups from the target inode(s) then we
328 * instead pack one or more groups from the user's supplementary group
c0894c6c
OD
329 * array in case it might be useful. Not needed if doing an MDS-side upcall.
330 */
d7e09d03
PT
331void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
332{
6e16818b 333 LASSERT(i1);
d7e09d03
PT
334
335 suppgids[0] = ll_i2suppgid(i1);
336
337 if (i2)
338 suppgids[1] = ll_i2suppgid(i2);
339 else
340 suppgids[1] = -1;
d7e09d03
PT
341}
342
343/*
344 * try to reuse three types of dentry:
345 * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
346 * by concurrent .revalidate).
347 * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
348 * be cleared by others calling d_lustre_revalidate).
349 * 3. DISCONNECTED alias.
350 */
351static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
352{
353 struct dentry *alias, *discon_alias, *invalid_alias;
d7e09d03 354
9d5be52f 355 if (hlist_empty(&inode->i_dentry))
d7e09d03
PT
356 return NULL;
357
7551b8b5
NC
358 discon_alias = NULL;
359 invalid_alias = NULL;
d7e09d03 360
2bbec0ed 361 spin_lock(&inode->i_lock);
9d5be52f 362 hlist_for_each_entry(alias, &inode->i_dentry, d_u.d_alias) {
d7e09d03
PT
363 LASSERT(alias != dentry);
364
365 spin_lock(&alias->d_lock);
f7368144
LNJ
366 if ((alias->d_flags & DCACHE_DISCONNECTED) &&
367 S_ISDIR(inode->i_mode))
d7e09d03
PT
368 /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
369 discon_alias = alias;
370 else if (alias->d_parent == dentry->d_parent &&
371 alias->d_name.hash == dentry->d_name.hash &&
372 alias->d_name.len == dentry->d_name.len &&
373 memcmp(alias->d_name.name, dentry->d_name.name,
374 dentry->d_name.len) == 0)
375 invalid_alias = alias;
376 spin_unlock(&alias->d_lock);
377
378 if (invalid_alias)
379 break;
380 }
381 alias = invalid_alias ?: discon_alias ?: NULL;
382 if (alias) {
383 spin_lock(&alias->d_lock);
384 dget_dlock(alias);
385 spin_unlock(&alias->d_lock);
386 }
2bbec0ed 387 spin_unlock(&inode->i_lock);
d7e09d03
PT
388
389 return alias;
390}
391
392/*
393 * Similar to d_splice_alias(), but lustre treats invalid alias
394 * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
395 */
396struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
397{
398 struct dentry *new;
3ea8f3bc 399 int rc;
d7e09d03
PT
400
401 if (inode) {
402 new = ll_find_alias(inode, de);
403 if (new) {
3ea8f3bc
LS
404 rc = ll_d_init(new);
405 if (rc < 0) {
406 dput(new);
407 return ERR_PTR(rc);
408 }
d7e09d03
PT
409 d_move(new, de);
410 iput(inode);
411 CDEBUG(D_DENTRY,
412 "Reuse dentry %p inode %p refc %d flags %#x\n",
2b0143b5 413 new, d_inode(new), d_count(new), new->d_flags);
d7e09d03
PT
414 return new;
415 }
416 }
3ea8f3bc
LS
417 rc = ll_d_init(de);
418 if (rc < 0)
419 return ERR_PTR(rc);
d7e09d03
PT
420 d_add(de, inode);
421 CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n",
2b0143b5 422 de, d_inode(de), d_count(de), de->d_flags);
d7e09d03
PT
423 return de;
424}
425
2d95f10e
JH
426static int ll_lookup_it_finish(struct ptlrpc_request *request,
427 struct lookup_intent *it,
428 struct inode *parent, struct dentry **de)
d7e09d03 429{
d7e09d03
PT
430 struct inode *inode = NULL;
431 __u64 bits = 0;
44ecac68 432 int rc = 0;
99f1c013 433 struct dentry *alias;
d7e09d03
PT
434
435 /* NB 1 request reference will be taken away by ll_intent_lock()
c0894c6c
OD
436 * when I return
437 */
d7e09d03 438 CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it,
e476f2e5 439 it->it_disposition);
d7e09d03
PT
440 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
441 rc = ll_prep_inode(&inode, request, (*de)->d_sb, it);
442 if (rc)
0a3bdb00 443 return rc;
d7e09d03
PT
444
445 ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits);
446
447 /* We used to query real size from OSTs here, but actually
c0894c6c
OD
448 * this is not needed. For stat() calls size would be updated
449 * from subsequent do_revalidate()->ll_inode_revalidate_it() in
450 * 2.4 and
451 * vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
452 * Everybody else who needs correct file size would call
453 * ll_glimpse_size or some equivalent themselves anyway.
454 * Also see bug 7198.
455 */
d7e09d03
PT
456 }
457
99f1c013
OD
458 alias = ll_splice_alias(inode, *de);
459 if (IS_ERR(alias)) {
460 rc = PTR_ERR(alias);
461 goto out;
3ea8f3bc 462 }
99f1c013 463 *de = alias;
d7e09d03
PT
464
465 if (!it_disposition(it, DISP_LOOKUP_NEG)) {
466 /* we have lookup look - unhide dentry */
467 if (bits & MDS_INODELOCK_LOOKUP)
468 d_lustre_revalidate(*de);
469 } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
470 /* If file created on server, don't depend on parent UPDATE
471 * lock to unhide it. It is left hidden and next lookup can
472 * find it in ll_splice_alias.
473 */
474 /* Check that parent has UPDATE lock. */
475 struct lookup_intent parent_it = {
476 .it_op = IT_GETATTR,
e476f2e5 477 .it_lock_handle = 0 };
a609c393 478 struct lu_fid fid = ll_i2info(parent)->lli_fid;
479
480 /* If it is striped directory, get the real stripe parent */
481 if (unlikely(ll_i2info(parent)->lli_lsm_md)) {
482 rc = md_get_fid_from_lsm(ll_i2mdexp(parent),
483 ll_i2info(parent)->lli_lsm_md,
484 (*de)->d_name.name,
485 (*de)->d_name.len, &fid);
486 if (rc)
487 return rc;
488 }
d7e09d03 489
a609c393 490 if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it, &fid,
491 NULL)) {
d7e09d03
PT
492 d_lustre_revalidate(*de);
493 ll_intent_release(&parent_it);
494 }
495 }
496
44ecac68
FY
497out:
498 if (rc != 0 && it->it_op & IT_OPEN)
499 ll_open_cleanup((*de)->d_sb, request);
500
501 return rc;
d7e09d03
PT
502}
503
504static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
505 struct lookup_intent *it, int lookup_flags)
506{
507 struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
508 struct dentry *save = dentry, *retval;
509 struct ptlrpc_request *req = NULL;
dbca51dd 510 struct inode *inode;
d7e09d03 511 struct md_op_data *op_data;
d7e09d03
PT
512 __u32 opc;
513 int rc;
d7e09d03
PT
514
515 if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
0a3bdb00 516 return ERR_PTR(-ENAMETOOLONG);
d7e09d03 517
97a075cd
JN
518 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),intent=%s\n",
519 dentry, PFID(ll_inode2fid(parent)), parent, LL_IT2STR(it));
d7e09d03
PT
520
521 if (d_mountpoint(dentry))
522 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
523
6e16818b 524 if (!it || it->it_op == IT_GETXATTR)
2d95f10e 525 it = &lookup_it;
d7e09d03 526
d7e09d03
PT
527 if (it->it_op == IT_GETATTR) {
528 rc = ll_statahead_enter(parent, &dentry, 0);
529 if (rc == 1) {
530 if (dentry == save)
34e1f2bb
JL
531 retval = NULL;
532 else
533 retval = dentry;
534 goto out;
d7e09d03
PT
535 }
536 }
537
1e8a576e 538 if (it->it_op & IT_CREAT)
d7e09d03
PT
539 opc = LUSTRE_OPC_CREATE;
540 else
541 opc = LUSTRE_OPC_ANY;
542
543 op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
544 dentry->d_name.len, lookup_flags, opc,
545 NULL);
546 if (IS_ERR(op_data))
0a3bdb00 547 return (void *)op_data;
d7e09d03
PT
548
549 /* enforce umask if acl disabled or MDS doesn't support umask */
550 if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
551 it->it_create_mode &= ~current_umask();
552
70a251f6
JH
553 rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
554 &ll_md_blocking_ast, 0);
d7e09d03 555 ll_finish_md_op_data(op_data);
34e1f2bb
JL
556 if (rc < 0) {
557 retval = ERR_PTR(rc);
558 goto out;
559 }
d7e09d03 560
2d95f10e 561 rc = ll_lookup_it_finish(req, it, parent, &dentry);
d7e09d03
PT
562 if (rc != 0) {
563 ll_intent_release(it);
34e1f2bb
JL
564 retval = ERR_PTR(rc);
565 goto out;
d7e09d03
PT
566 }
567
2b0143b5 568 inode = d_inode(dentry);
dbca51dd
AV
569 if ((it->it_op & IT_OPEN) && inode &&
570 !S_ISREG(inode->i_mode) &&
571 !S_ISDIR(inode->i_mode)) {
572 ll_release_openhandle(inode, it);
d7e09d03 573 }
dbca51dd 574 ll_lookup_finish_locks(it, inode);
d7e09d03
PT
575
576 if (dentry == save)
34e1f2bb 577 retval = NULL;
d7e09d03 578 else
34e1f2bb 579 retval = dentry;
d7e09d03
PT
580 out:
581 if (req)
582 ptlrpc_req_finished(req);
6e16818b 583 if (it->it_op == IT_GETATTR && (!retval || retval == dentry))
d7e09d03
PT
584 ll_statahead_mark(parent, dentry);
585 return retval;
586}
587
588static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
589 unsigned int flags)
590{
591 struct lookup_intent *itp, it = { .it_op = IT_GETATTR };
592 struct dentry *de;
593
97a075cd
JN
594 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),flags=%u\n",
595 dentry, PFID(ll_inode2fid(parent)), parent, flags);
d7e09d03 596
3a77df11
OD
597 /* Optimize away (CREATE && !OPEN). Let .create handle the race.
598 * but only if we have write permissions there, otherwise we need
599 * to proceed with lookup. LU-4185
600 */
601 if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN) &&
602 (inode_permission(parent, MAY_WRITE | MAY_EXEC) == 0))
d7e09d03 603 return NULL;
d7e09d03 604
cd94f231 605 if (flags & (LOOKUP_PARENT | LOOKUP_OPEN | LOOKUP_CREATE))
d7e09d03
PT
606 itp = NULL;
607 else
608 itp = &it;
609 de = ll_lookup_it(parent, dentry, itp, 0);
610
6e16818b 611 if (itp)
d7e09d03
PT
612 ll_intent_release(itp);
613
614 return de;
615}
616
617/*
618 * For cached negative dentry and new dentry, handle lookup/create/open
619 * together.
620 */
621static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
622 struct file *file, unsigned open_flags,
623 umode_t mode, int *opened)
624{
625 struct lookup_intent *it;
626 struct dentry *de;
627 long long lookup_flags = LOOKUP_OPEN;
628 int rc = 0;
d7e09d03 629
97a075cd
JN
630 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),file %p,open_flags %x,mode %x opened %d\n",
631 dentry, PFID(ll_inode2fid(dir)), dir, file, open_flags, mode,
632 *opened);
d7e09d03 633
99f1c013
OD
634 /* Only negative dentries enter here */
635 LASSERT(!d_inode(dentry));
636
637 if (!d_in_lookup(dentry)) {
638 /* A valid negative dentry that just passed revalidation,
639 * there's little point to try and open it server-side,
640 * even though there's a minuscle chance it might succeed.
641 * Either way it's a valid race to just return -ENOENT here.
642 */
643 if (!(open_flags & O_CREAT))
644 return -ENOENT;
645
646 /* Otherwise we just unhash it to be rehashed afresh via
647 * lookup if necessary
648 */
649 d_drop(dentry);
650 }
651
496a51bd 652 it = kzalloc(sizeof(*it), GFP_NOFS);
d7e09d03 653 if (!it)
0a3bdb00 654 return -ENOMEM;
d7e09d03
PT
655
656 it->it_op = IT_OPEN;
1e8a576e 657 if (open_flags & O_CREAT) {
d7e09d03
PT
658 it->it_op |= IT_CREAT;
659 lookup_flags |= LOOKUP_CREATE;
660 }
661 it->it_create_mode = (mode & S_IALLUGO) | S_IFREG;
662 it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags);
c1b66fcc 663 it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
d7e09d03
PT
664
665 /* Dentry added to dcache tree in ll_lookup_it */
666 de = ll_lookup_it(dir, dentry, it, lookup_flags);
667 if (IS_ERR(de))
668 rc = PTR_ERR(de);
6e16818b 669 else if (de)
d7e09d03
PT
670 dentry = de;
671
672 if (!rc) {
673 if (it_disposition(it, DISP_OPEN_CREATE)) {
674 /* Dentry instantiated in ll_create_it. */
675 rc = ll_create_it(dir, dentry, mode, it);
676 if (rc) {
677 /* We dget in ll_splice_alias. */
6e16818b 678 if (de)
d7e09d03
PT
679 dput(de);
680 goto out_release;
681 }
682
683 *opened |= FILE_CREATED;
684 }
2b0143b5 685 if (d_really_is_positive(dentry) && it_disposition(it, DISP_OPEN_OPEN)) {
d7e09d03 686 /* Open dentry. */
2b0143b5 687 if (S_ISFIFO(d_inode(dentry)->i_mode)) {
411c9699
JH
688 /* We cannot call open here as it might
689 * deadlock. This case is unreachable in
690 * practice because of OBD_CONNECT_NODEVOH.
d7e09d03 691 */
d7e09d03
PT
692 rc = finish_no_open(file, de);
693 } else {
694 file->private_data = it;
695 rc = finish_open(file, dentry, NULL, opened);
696 /* We dget in ll_splice_alias. finish_open takes
697 * care of dget for fd open.
698 */
6e16818b 699 if (de)
d7e09d03
PT
700 dput(de);
701 }
702 } else {
703 rc = finish_no_open(file, de);
704 }
705 }
706
707out_release:
708 ll_intent_release(it);
97903a26 709 kfree(it);
d7e09d03 710
0a3bdb00 711 return rc;
d7e09d03
PT
712}
713
d7e09d03 714/* We depend on "mode" being set with the proper file type/umask by now */
2d95f10e 715static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
d7e09d03
PT
716{
717 struct inode *inode = NULL;
718 struct ptlrpc_request *request = NULL;
719 struct ll_sb_info *sbi = ll_i2sbi(dir);
720 int rc;
d7e09d03 721
e476f2e5 722 LASSERT(it && it->it_disposition);
d7e09d03
PT
723
724 LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
8bf86fd9 725 request = it->it_request;
d7e09d03
PT
726 it_clear_disposition(it, DISP_ENQ_CREATE_REF);
727 rc = ll_prep_inode(&inode, request, dir->i_sb, it);
34e1f2bb
JL
728 if (rc) {
729 inode = ERR_PTR(rc);
730 goto out;
731 }
d7e09d03 732
9d5be52f 733 LASSERT(hlist_empty(&inode->i_dentry));
d7e09d03
PT
734
735 /* We asked for a lock on the directory, but were granted a
736 * lock on the inode. Since we finally have an inode pointer,
c0894c6c
OD
737 * stuff it in the lock.
738 */
97a075cd
JN
739 CDEBUG(D_DLMTRACE, "setting l_ast_data to inode "DFID"(%p)\n",
740 PFID(ll_inode2fid(dir)), inode);
d7e09d03 741 ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
d7e09d03
PT
742 out:
743 ptlrpc_req_finished(request);
744 return inode;
745}
746
747/*
748 * By the time this is called, we already have created the directory cache
749 * entry for the new file, but it is so far negative - it has no inode.
750 *
751 * We defer creating the OBD object(s) until open, to keep the intent and
752 * non-intent code paths similar, and also because we do not have the MDS
753 * inode number before calling ll_create_node() (which is needed for LOV),
754 * so we would need to do yet another RPC to the MDS to store the LOV EA
755 * data on the MDS. If needed, we would pass the PACKED lmm as data and
756 * lmm_size in datalen (the MDS still has code which will handle that).
757 *
758 * If the create succeeds, we fill in the inode information
759 * with d_instantiate().
760 */
761static int ll_create_it(struct inode *dir, struct dentry *dentry, int mode,
762 struct lookup_intent *it)
763{
764 struct inode *inode;
765 int rc = 0;
d7e09d03 766
97a075cd
JN
767 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), intent=%s\n",
768 dentry, PFID(ll_inode2fid(dir)), dir, LL_IT2STR(it));
d7e09d03
PT
769
770 rc = it_open_error(DISP_OPEN_CREATE, it);
771 if (rc)
0a3bdb00 772 return rc;
d7e09d03 773
2d95f10e 774 inode = ll_create_node(dir, it);
d7e09d03 775 if (IS_ERR(inode))
0a3bdb00 776 return PTR_ERR(inode);
d7e09d03 777
d7e09d03 778 d_instantiate(dentry, inode);
0a3bdb00 779 return 0;
d7e09d03
PT
780}
781
79496845 782void ll_update_times(struct ptlrpc_request *request, struct inode *inode)
d7e09d03
PT
783{
784 struct mdt_body *body = req_capsule_server_get(&request->rq_pill,
785 &RMF_MDT_BODY);
786
787 LASSERT(body);
2e1b5b8b
JH
788 if (body->mbo_valid & OBD_MD_FLMTIME &&
789 body->mbo_mtime > LTIME_S(inode->i_mtime)) {
97a075cd
JN
790 CDEBUG(D_INODE, "setting fid "DFID" mtime from %lu to %llu\n",
791 PFID(ll_inode2fid(inode)), LTIME_S(inode->i_mtime),
2e1b5b8b
JH
792 body->mbo_mtime);
793 LTIME_S(inode->i_mtime) = body->mbo_mtime;
d7e09d03 794 }
2e1b5b8b
JH
795 if (body->mbo_valid & OBD_MD_FLCTIME &&
796 body->mbo_ctime > LTIME_S(inode->i_ctime))
797 LTIME_S(inode->i_ctime) = body->mbo_ctime;
d7e09d03
PT
798}
799
b2037bb6 800static int ll_new_node(struct inode *dir, struct dentry *dentry,
d7e09d03 801 const char *tgt, int mode, int rdev,
b2037bb6 802 __u32 opc)
d7e09d03
PT
803{
804 struct ptlrpc_request *request = NULL;
805 struct md_op_data *op_data;
806 struct inode *inode = NULL;
807 struct ll_sb_info *sbi = ll_i2sbi(dir);
808 int tgt_len = 0;
809 int err;
810
6e16818b 811 if (unlikely(tgt))
d7e09d03
PT
812 tgt_len = strlen(tgt) + 1;
813
b2037bb6
AV
814 op_data = ll_prep_md_op_data(NULL, dir, NULL,
815 dentry->d_name.name,
816 dentry->d_name.len,
817 0, opc, NULL);
34e1f2bb
JL
818 if (IS_ERR(op_data)) {
819 err = PTR_ERR(op_data);
820 goto err_exit;
821 }
d7e09d03
PT
822
823 err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
4b1a25f0
PT
824 from_kuid(&init_user_ns, current_fsuid()),
825 from_kgid(&init_user_ns, current_fsgid()),
d7e09d03
PT
826 cfs_curproc_cap_pack(), rdev, &request);
827 ll_finish_md_op_data(op_data);
828 if (err)
34e1f2bb 829 goto err_exit;
d7e09d03
PT
830
831 ll_update_times(request, dir);
832
b2037bb6
AV
833 err = ll_prep_inode(&inode, request, dir->i_sb, NULL);
834 if (err)
835 goto err_exit;
d7e09d03 836
b2037bb6 837 d_instantiate(dentry, inode);
d7e09d03
PT
838err_exit:
839 ptlrpc_req_finished(request);
840
841 return err;
842}
843
d6689e5f
AV
844static int ll_mknod(struct inode *dir, struct dentry *dchild,
845 umode_t mode, dev_t rdev)
d7e09d03
PT
846{
847 int err;
d7e09d03 848
97a075cd
JN
849 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p) mode %o dev %x\n",
850 dchild, PFID(ll_inode2fid(dir)), dir, mode,
851 old_encode_dev(rdev));
d7e09d03
PT
852
853 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
854 mode &= ~current_umask();
855
856 switch (mode & S_IFMT) {
857 case 0:
858 mode |= S_IFREG; /* for mode = 0 case, fallthrough */
859 case S_IFREG:
860 case S_IFCHR:
861 case S_IFBLK:
862 case S_IFIFO:
863 case S_IFSOCK:
b2037bb6
AV
864 err = ll_new_node(dir, dchild, NULL, mode,
865 old_encode_dev(rdev),
d7e09d03
PT
866 LUSTRE_OPC_MKNOD);
867 break;
868 case S_IFDIR:
869 err = -EPERM;
870 break;
871 default:
872 err = -EINVAL;
873 }
874
875 if (!err)
876 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1);
877
0a3bdb00 878 return err;
d7e09d03
PT
879}
880
881/*
882 * Plain create. Intent create is handled in atomic_open.
883 */
884static int ll_create_nd(struct inode *dir, struct dentry *dentry,
885 umode_t mode, bool want_excl)
886{
887 int rc;
888
97a075cd
JN
889 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p), flags=%u, excl=%d\n",
890 dentry, PFID(ll_inode2fid(dir)), dir, mode, want_excl);
d7e09d03 891
d6689e5f 892 rc = ll_mknod(dir, dentry, mode, 0);
d7e09d03
PT
893
894 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
895
09561a53
AV
896 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, unhashed %d\n",
897 dentry, d_unhashed(dentry));
d7e09d03
PT
898
899 return rc;
900}
901
d7e09d03
PT
902int ll_objects_destroy(struct ptlrpc_request *request, struct inode *dir)
903{
904 struct mdt_body *body;
905 struct lov_mds_md *eadata;
906 struct lov_stripe_md *lsm = NULL;
907 struct obd_trans_info oti = { 0 };
908 struct obdo *oa;
d7e09d03 909 int rc;
d7e09d03
PT
910
911 /* req is swabbed so this is safe */
912 body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
2e1b5b8b 913 if (!(body->mbo_valid & OBD_MD_FLEASIZE))
0a3bdb00 914 return 0;
d7e09d03 915
2e1b5b8b 916 if (body->mbo_eadatasize == 0) {
d7e09d03 917 CERROR("OBD_MD_FLEASIZE set but eadatasize zero\n");
34e1f2bb
JL
918 rc = -EPROTO;
919 goto out;
d7e09d03
PT
920 }
921
922 /* The MDS sent back the EA because we unlinked the last reference
923 * to this file. Use this EA to unlink the objects on the OST.
924 * It's opaque so we don't swab here; we leave it to obd_unpackmd() to
c0894c6c
OD
925 * check it is complete and sensible.
926 */
d7e09d03 927 eadata = req_capsule_server_sized_get(&request->rq_pill, &RMF_MDT_MD,
2e1b5b8b 928 body->mbo_eadatasize);
6e16818b 929 LASSERT(eadata);
d7e09d03 930
2e1b5b8b 931 rc = obd_unpackmd(ll_i2dtexp(dir), &lsm, eadata, body->mbo_eadatasize);
d7e09d03
PT
932 if (rc < 0) {
933 CERROR("obd_unpackmd: %d\n", rc);
34e1f2bb 934 goto out;
d7e09d03
PT
935 }
936 LASSERT(rc >= sizeof(*lsm));
937
21068c46 938 oa = kmem_cache_zalloc(obdo_cachep, GFP_NOFS);
6e16818b 939 if (!oa) {
34e1f2bb
JL
940 rc = -ENOMEM;
941 goto out_free_memmd;
942 }
d7e09d03
PT
943
944 oa->o_oi = lsm->lsm_oi;
2e1b5b8b 945 oa->o_mode = body->mbo_mode & S_IFMT;
d7e09d03
PT
946 oa->o_valid = OBD_MD_FLID | OBD_MD_FLTYPE | OBD_MD_FLGROUP;
947
2e1b5b8b 948 if (body->mbo_valid & OBD_MD_FLCOOKIE) {
d7e09d03
PT
949 oa->o_valid |= OBD_MD_FLCOOKIE;
950 oti.oti_logcookies =
951 req_capsule_server_sized_get(&request->rq_pill,
952 &RMF_LOGCOOKIES,
953 sizeof(struct llog_cookie) *
954 lsm->lsm_stripe_count);
6e16818b 955 if (!oti.oti_logcookies) {
d7e09d03 956 oa->o_valid &= ~OBD_MD_FLCOOKIE;
2e1b5b8b 957 body->mbo_valid &= ~OBD_MD_FLCOOKIE;
d7e09d03
PT
958 }
959 }
960
d7e09d03 961 rc = obd_destroy(NULL, ll_i2dtexp(dir), oa, lsm, &oti,
ef2e0f55 962 ll_i2mdexp(dir));
d7e09d03
PT
963 if (rc)
964 CERROR("obd destroy objid "DOSTID" error %d\n",
965 POSTID(&lsm->lsm_oi), rc);
966out_free_memmd:
967 obd_free_memmd(ll_i2dtexp(dir), &lsm);
2ba262fb 968 kmem_cache_free(obdo_cachep, oa);
d7e09d03
PT
969out:
970 return rc;
971}
972
521f2ad7
AV
973/* ll_unlink() doesn't update the inode with the new link count.
974 * Instead, ll_ddelete() and ll_d_iput() will update it based upon if there
975 * is any lock existing. They will recycle dentries and inodes based upon locks
c0894c6c
OD
976 * too. b=20433
977 */
96d61c24 978static int ll_unlink(struct inode *dir, struct dentry *dchild)
d7e09d03 979{
521f2ad7
AV
980 struct ptlrpc_request *request = NULL;
981 struct md_op_data *op_data;
982 int rc;
43550121 983
521f2ad7 984 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd,dir=%lu/%u(%p)\n",
96d61c24 985 dchild, dir->i_ino, dir->i_generation, dir);
521f2ad7 986
521f2ad7 987 op_data = ll_prep_md_op_data(NULL, dir, NULL,
96d61c24
AP
988 dchild->d_name.name,
989 dchild->d_name.len,
521f2ad7
AV
990 0, LUSTRE_OPC_ANY, NULL);
991 if (IS_ERR(op_data))
992 return PTR_ERR(op_data);
993
3c4b9d09
AP
994 if (dchild && dchild->d_inode)
995 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
996
521f2ad7
AV
997 op_data->op_fid2 = op_data->op_fid3;
998 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
999 ll_finish_md_op_data(op_data);
1000 if (rc)
1001 goto out;
1002
1003 ll_update_times(request, dir);
1004 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);
1005
1006 rc = ll_objects_destroy(request, dir);
1007 out:
1008 ptlrpc_req_finished(request);
1009 return rc;
d7e09d03
PT
1010}
1011
e3befdc7 1012static int ll_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
d7e09d03 1013{
7c2f9094
AV
1014 int err;
1015
97a075cd
JN
1016 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir"DFID"(%p)\n",
1017 dentry, PFID(ll_inode2fid(dir)), dir);
7c2f9094
AV
1018
1019 if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1020 mode &= ~current_umask();
cd94f231 1021 mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
b2037bb6 1022 err = ll_new_node(dir, dentry, NULL, mode, 0, LUSTRE_OPC_MKDIR);
7c2f9094
AV
1023
1024 if (!err)
1025 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR, 1);
1026
1027 return err;
d7e09d03
PT
1028}
1029
96d61c24 1030static int ll_rmdir(struct inode *dir, struct dentry *dchild)
d7e09d03 1031{
55dec617
AV
1032 struct ptlrpc_request *request = NULL;
1033 struct md_op_data *op_data;
1034 int rc;
1035
97a075cd
JN
1036 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p)\n",
1037 dchild, PFID(ll_inode2fid(dir)), dir);
55dec617 1038
55dec617 1039 op_data = ll_prep_md_op_data(NULL, dir, NULL,
96d61c24
AP
1040 dchild->d_name.name,
1041 dchild->d_name.len,
55dec617
AV
1042 S_IFDIR, LUSTRE_OPC_ANY, NULL);
1043 if (IS_ERR(op_data))
1044 return PTR_ERR(op_data);
1045
3c4b9d09
AP
1046 if (dchild && dchild->d_inode)
1047 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
1048
55dec617
AV
1049 op_data->op_fid2 = op_data->op_fid3;
1050 rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1051 ll_finish_md_op_data(op_data);
1052 if (rc == 0) {
1053 ll_update_times(request, dir);
1054 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1055 }
1056
1057 ptlrpc_req_finished(request);
1058 return rc;
d7e09d03
PT
1059}
1060
1061static int ll_symlink(struct inode *dir, struct dentry *dentry,
1062 const char *oldname)
1063{
60dd654e
AV
1064 int err;
1065
97a075cd
JN
1066 CDEBUG(D_VFSTRACE, "VFS Op:name=%pd, dir="DFID"(%p),target=%.*s\n",
1067 dentry, PFID(ll_inode2fid(dir)), dir, 3000, oldname);
60dd654e 1068
b2037bb6 1069 err = ll_new_node(dir, dentry, oldname, S_IFLNK | S_IRWXUGO,
e15ba45d 1070 0, LUSTRE_OPC_SYMLINK);
60dd654e
AV
1071
1072 if (!err)
1073 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK, 1);
1074
1075 return err;
d7e09d03
PT
1076}
1077
1078static int ll_link(struct dentry *old_dentry, struct inode *dir,
1079 struct dentry *new_dentry)
1080{
2b0143b5 1081 struct inode *src = d_inode(old_dentry);
59cc93ef
AV
1082 struct ll_sb_info *sbi = ll_i2sbi(dir);
1083 struct ptlrpc_request *request = NULL;
1084 struct md_op_data *op_data;
1085 int err;
1086
97a075cd
JN
1087 CDEBUG(D_VFSTRACE, "VFS Op: inode="DFID"(%p), dir="DFID"(%p), target=%pd\n",
1088 PFID(ll_inode2fid(src)), src, PFID(ll_inode2fid(dir)), dir,
1089 new_dentry);
59cc93ef
AV
1090
1091 op_data = ll_prep_md_op_data(NULL, src, dir, new_dentry->d_name.name,
1092 new_dentry->d_name.len,
1093 0, LUSTRE_OPC_ANY, NULL);
1094 if (IS_ERR(op_data))
1095 return PTR_ERR(op_data);
1096
1097 err = md_link(sbi->ll_md_exp, op_data, &request);
1098 ll_finish_md_op_data(op_data);
1099 if (err)
1100 goto out;
1101
1102 ll_update_times(request, dir);
1103 ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1);
1104out:
1105 ptlrpc_req_finished(request);
1106 return err;
d7e09d03
PT
1107}
1108
96d61c24 1109static int ll_rename(struct inode *src, struct dentry *src_dchild,
1423ecc0
MS
1110 struct inode *tgt, struct dentry *tgt_dchild,
1111 unsigned int flags)
d7e09d03 1112{
78851093 1113 struct ptlrpc_request *request = NULL;
96d61c24 1114 struct ll_sb_info *sbi = ll_i2sbi(src);
78851093 1115 struct md_op_data *op_data;
d7e09d03 1116 int err;
78851093 1117
1423ecc0
MS
1118 if (flags)
1119 return -EINVAL;
1120
78851093 1121 CDEBUG(D_VFSTRACE,
97a075cd
JN
1122 "VFS Op:oldname=%pd, src_dir="DFID"(%p), newname=%pd, tgt_dir="DFID"(%p)\n",
1123 src_dchild, PFID(ll_inode2fid(src)), src,
1124 tgt_dchild, PFID(ll_inode2fid(tgt)), tgt);
78851093 1125
96d61c24 1126 op_data = ll_prep_md_op_data(NULL, src, tgt, NULL, 0, 0,
78851093
AV
1127 LUSTRE_OPC_ANY, NULL);
1128 if (IS_ERR(op_data))
1129 return PTR_ERR(op_data);
1130
3c4b9d09
AP
1131 if (src_dchild && src_dchild->d_inode)
1132 op_data->op_fid3 = *ll_inode2fid(src_dchild->d_inode);
1133 if (tgt_dchild && tgt_dchild->d_inode)
1134 op_data->op_fid4 = *ll_inode2fid(tgt_dchild->d_inode);
1135
78851093 1136 err = md_rename(sbi->ll_md_exp, op_data,
96d61c24
AP
1137 src_dchild->d_name.name,
1138 src_dchild->d_name.len,
1139 tgt_dchild->d_name.name,
1140 tgt_dchild->d_name.len, &request);
78851093 1141 ll_finish_md_op_data(op_data);
d7e09d03 1142 if (!err) {
96d61c24
AP
1143 ll_update_times(request, src);
1144 ll_update_times(request, tgt);
78851093 1145 ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1);
96d61c24 1146 err = ll_objects_destroy(request, src);
d7e09d03 1147 }
78851093
AV
1148
1149 ptlrpc_req_finished(request);
1150 if (!err)
96d61c24 1151 d_move(src_dchild, tgt_dchild);
d7e09d03
PT
1152 return err;
1153}
1154
2d95f10e 1155const struct inode_operations ll_dir_inode_operations = {
d7e09d03
PT
1156 .mknod = ll_mknod,
1157 .atomic_open = ll_atomic_open,
1158 .lookup = ll_lookup_nd,
1159 .create = ll_create_nd,
1160 /* We need all these non-raw things for NFSD, to not patch it. */
1161 .unlink = ll_unlink,
1162 .mkdir = ll_mkdir,
1163 .rmdir = ll_rmdir,
1164 .symlink = ll_symlink,
1165 .link = ll_link,
34332745 1166 .rename = ll_rename,
d7e09d03
PT
1167 .setattr = ll_setattr,
1168 .getattr = ll_getattr,
1169 .permission = ll_inode_permission,
2c563880
JS
1170 .setxattr = generic_setxattr,
1171 .getxattr = generic_getxattr,
d7e09d03 1172 .listxattr = ll_listxattr,
2c563880 1173 .removexattr = generic_removexattr,
d7e09d03
PT
1174 .get_acl = ll_get_acl,
1175};
1176
2d95f10e 1177const struct inode_operations ll_special_inode_operations = {
d7e09d03
PT
1178 .setattr = ll_setattr,
1179 .getattr = ll_getattr,
1180 .permission = ll_inode_permission,
2c563880
JS
1181 .setxattr = generic_setxattr,
1182 .getxattr = generic_getxattr,
d7e09d03 1183 .listxattr = ll_listxattr,
2c563880 1184 .removexattr = generic_removexattr,
d7e09d03
PT
1185 .get_acl = ll_get_acl,
1186};
This page took 0.619347 seconds and 5 git commands to generate.