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