Whamcloud - gitweb
LU-12681 osc: wrong cache of LVB attrs
[fs/lustre-release.git] / lustre / llite / namei.c
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.gnu.org/licenses/gpl-2.0.html
19  *
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  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
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 #include <linux/user_namespace.h>
41 #ifdef HAVE_UIDGID_HEADER
42 # include <linux/uidgid.h>
43 #endif
44
45 #define DEBUG_SUBSYSTEM S_LLITE
46
47 #include <obd_support.h>
48 #include <lustre_fid.h>
49 #include <lustre_dlm.h>
50 #include "llite_internal.h"
51
52 static int ll_create_it(struct inode *dir, struct dentry *dentry,
53                         struct lookup_intent *it,
54                         void *secctx, __u32 secctxlen);
55
56 /* called from iget5_locked->find_inode() under inode_lock spinlock */
57 static int ll_test_inode(struct inode *inode, void *opaque)
58 {
59         struct ll_inode_info    *lli = ll_i2info(inode);
60         struct lustre_md        *md = opaque;
61
62         if (unlikely(!(md->body->mbo_valid & OBD_MD_FLID))) {
63                 CERROR("MDS body missing FID\n");
64                 return 0;
65         }
66
67         if (!lu_fid_eq(&lli->lli_fid, &md->body->mbo_fid1))
68                 return 0;
69
70         return 1;
71 }
72
73 static int ll_set_inode(struct inode *inode, void *opaque)
74 {
75         struct ll_inode_info *lli = ll_i2info(inode);
76         struct mdt_body *body = ((struct lustre_md *)opaque)->body;
77
78         if (unlikely(!(body->mbo_valid & OBD_MD_FLID))) {
79                 CERROR("MDS body missing FID\n");
80                 return -EINVAL;
81         }
82
83         lli->lli_fid = body->mbo_fid1;
84         if (unlikely(!(body->mbo_valid & OBD_MD_FLTYPE))) {
85                 CERROR("Can not initialize inode "DFID" without object type: "
86                        "valid = %#llx\n",
87                        PFID(&lli->lli_fid), body->mbo_valid);
88                 return -EINVAL;
89         }
90
91         inode->i_mode = (inode->i_mode & ~S_IFMT) | (body->mbo_mode & S_IFMT);
92         if (unlikely(inode->i_mode == 0)) {
93                 CERROR("Invalid inode "DFID" type\n", PFID(&lli->lli_fid));
94                 return -EINVAL;
95         }
96
97         ll_lli_init(lli);
98
99         return 0;
100 }
101
102
103 /**
104  * Get an inode by inode number(@hash), which is already instantiated by
105  * the intent lookup).
106  */
107 struct inode *ll_iget(struct super_block *sb, ino_t hash,
108                       struct lustre_md *md)
109 {
110         struct inode    *inode;
111         int             rc = 0;
112
113         ENTRY;
114
115         LASSERT(hash != 0);
116         inode = iget5_locked(sb, hash, ll_test_inode, ll_set_inode, md);
117         if (inode == NULL)
118                 RETURN(ERR_PTR(-ENOMEM));
119
120         if (inode->i_state & I_NEW) {
121                 rc = ll_read_inode2(inode, md);
122                 if (rc == 0 && S_ISREG(inode->i_mode) &&
123                     ll_i2info(inode)->lli_clob == NULL)
124                         rc = cl_file_inode_init(inode, md);
125
126                 if (rc != 0) {
127                         /* Let's clear directory lsm here, otherwise
128                          * make_bad_inode() will reset the inode mode
129                          * to regular, then ll_clear_inode will not
130                          * be able to clear lsm_md */
131                         if (S_ISDIR(inode->i_mode))
132                                 ll_dir_clear_lsm_md(inode);
133                         make_bad_inode(inode);
134                         unlock_new_inode(inode);
135                         iput(inode);
136                         inode = ERR_PTR(rc);
137                 } else {
138                         inode_has_no_xattr(inode);
139                         unlock_new_inode(inode);
140                 }
141         } else if (is_bad_inode(inode)) {
142                 iput(inode);
143                 inode = ERR_PTR(-ESTALE);
144         } else if (!(inode->i_state & (I_FREEING | I_CLEAR))) {
145                 rc = ll_update_inode(inode, md);
146                 CDEBUG(D_VFSTRACE, "got inode: "DFID"(%p): rc = %d\n",
147                        PFID(&md->body->mbo_fid1), inode, rc);
148                 if (rc != 0) {
149                         if (S_ISDIR(inode->i_mode))
150                                 ll_dir_clear_lsm_md(inode);
151                         iput(inode);
152                         inode = ERR_PTR(rc);
153                 }
154         }
155
156         RETURN(inode);
157 }
158
159 static void ll_invalidate_negative_children(struct inode *dir)
160 {
161         struct dentry *dentry, *tmp_subdir;
162         DECLARE_LL_D_HLIST_NODE_PTR(p);
163
164         spin_lock(&dir->i_lock);
165         ll_d_hlist_for_each_entry(dentry, p, &dir->i_dentry) {
166                 spin_lock(&dentry->d_lock);
167                 if (!list_empty(&dentry->d_subdirs)) {
168                         struct dentry *child;
169
170                         list_for_each_entry_safe(child, tmp_subdir,
171                                                  &dentry->d_subdirs,
172                                                  d_child) {
173                                 if (child->d_inode == NULL)
174                                         d_lustre_invalidate(child, 1);
175                         }
176                 }
177                 spin_unlock(&dentry->d_lock);
178         }
179         spin_unlock(&dir->i_lock);
180 }
181
182 int ll_test_inode_by_fid(struct inode *inode, void *opaque)
183 {
184         return lu_fid_eq(&ll_i2info(inode)->lli_fid, opaque);
185 }
186
187 static int ll_dom_lock_cancel(struct inode *inode, struct ldlm_lock *lock)
188 {
189         struct lu_env *env;
190         struct ll_inode_info *lli = ll_i2info(inode);
191         __u16 refcheck;
192         int rc;
193         ENTRY;
194
195         if (!lli->lli_clob) {
196                 /* due to DoM read on open, there may exist pages for Lustre
197                  * regular file even though cl_object is not set up yet. */
198                 truncate_inode_pages(inode->i_mapping, 0);
199                 RETURN(0);
200         }
201
202         env = cl_env_get(&refcheck);
203         if (IS_ERR(env))
204                 RETURN(PTR_ERR(env));
205
206         /* reach MDC layer to flush data under  the DoM ldlm lock */
207         rc = cl_object_flush(env, lli->lli_clob, lock);
208
209         cl_env_put(env, &refcheck);
210         RETURN(rc);
211 }
212
213 static void ll_lock_cancel_bits(struct ldlm_lock *lock, __u64 to_cancel)
214 {
215         struct inode *inode = ll_inode_from_resource_lock(lock);
216         struct ll_inode_info *lli;
217         __u64 bits = to_cancel;
218         int rc;
219
220         ENTRY;
221
222         if (!inode) {
223                 /* That means the inode is evicted most likely and may cause
224                  * the skipping of lock cleanups below, so print the message
225                  * about that in log.
226                  */
227                 if (lock->l_resource->lr_lvb_inode)
228                         LDLM_DEBUG(lock,
229                                    "can't take inode for the lock (%sevicted)\n",
230                                    lock->l_resource->lr_lvb_inode->i_state &
231                                    I_FREEING ? "" : "not ");
232                 RETURN_EXIT;
233         }
234
235         if (!fid_res_name_eq(ll_inode2fid(inode),
236                              &lock->l_resource->lr_name)) {
237                 LDLM_ERROR(lock, "data mismatch with object "DFID"(%p)",
238                            PFID(ll_inode2fid(inode)), inode);
239                 LBUG();
240         }
241
242         if (bits & MDS_INODELOCK_XATTR) {
243                 ll_xattr_cache_destroy(inode);
244                 bits &= ~MDS_INODELOCK_XATTR;
245         }
246
247         /* For OPEN locks we differentiate between lock modes
248          * LCK_CR, LCK_CW, LCK_PR - bug 22891 */
249         if (bits & MDS_INODELOCK_OPEN)
250                 ll_have_md_lock(inode, &bits, lock->l_req_mode);
251
252         if (bits & MDS_INODELOCK_OPEN) {
253                 fmode_t fmode;
254
255                 switch (lock->l_req_mode) {
256                 case LCK_CW:
257                         fmode = FMODE_WRITE;
258                         break;
259                 case LCK_PR:
260                         fmode = FMODE_EXEC;
261                         break;
262                 case LCK_CR:
263                         fmode = FMODE_READ;
264                         break;
265                 default:
266                         LDLM_ERROR(lock, "bad lock mode for OPEN lock");
267                         LBUG();
268                 }
269
270                 ll_md_real_close(inode, fmode);
271
272                 bits &= ~MDS_INODELOCK_OPEN;
273         }
274
275         if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_UPDATE |
276                     MDS_INODELOCK_LAYOUT | MDS_INODELOCK_PERM |
277                     MDS_INODELOCK_DOM))
278                 ll_have_md_lock(inode, &bits, LCK_MINMODE);
279
280         if (bits & MDS_INODELOCK_DOM) {
281                 rc =  ll_dom_lock_cancel(inode, lock);
282                 if (rc < 0)
283                         CDEBUG(D_INODE, "cannot flush DoM data "
284                                DFID": rc = %d\n",
285                                PFID(ll_inode2fid(inode)), rc);
286         }
287
288         if (bits & MDS_INODELOCK_LAYOUT) {
289                 struct cl_object_conf conf = {
290                         .coc_opc = OBJECT_CONF_INVALIDATE,
291                         .coc_inode = inode,
292                 };
293
294                 rc = ll_layout_conf(inode, &conf);
295                 if (rc < 0)
296                         CDEBUG(D_INODE, "cannot invalidate layout of "
297                                DFID": rc = %d\n",
298                                PFID(ll_inode2fid(inode)), rc);
299         }
300
301         lli = ll_i2info(inode);
302
303         if (bits & MDS_INODELOCK_UPDATE)
304                 lli->lli_update_atime = 1;
305
306         if ((bits & MDS_INODELOCK_UPDATE) && S_ISDIR(inode->i_mode)) {
307                 CDEBUG(D_INODE, "invalidating inode "DFID" lli = %p, "
308                        "pfid  = "DFID"\n", PFID(ll_inode2fid(inode)),
309                        lli, PFID(&lli->lli_pfid));
310                 truncate_inode_pages(inode->i_mapping, 0);
311
312                 if (unlikely(!fid_is_zero(&lli->lli_pfid))) {
313                         struct inode *master_inode = NULL;
314                         unsigned long hash;
315
316                         /* This is slave inode, since all of the child dentry
317                          * is connected on the master inode, so we have to
318                          * invalidate the negative children on master inode */
319                         CDEBUG(D_INODE, "Invalidate s"DFID" m"DFID"\n",
320                                PFID(ll_inode2fid(inode)), PFID(&lli->lli_pfid));
321
322                         hash = cl_fid_build_ino(&lli->lli_pfid,
323                                         ll_need_32bit_api(ll_i2sbi(inode)));
324
325                         /* Do not lookup the inode with ilookup5, otherwise
326                          * it will cause dead lock,
327                          * 1. Client1 send chmod req to the MDT0, then on MDT0,
328                          * it enqueues master and all of its slaves lock,
329                          * (mdt_attr_set() -> mdt_lock_slaves()), after gets
330                          * master and stripe0 lock, it will send the enqueue
331                          * req (for stripe1) to MDT1, then MDT1 finds the lock
332                          * has been granted to client2. Then MDT1 sends blocking
333                          * ast to client2.
334                          * 2. At the same time, client2 tries to unlink
335                          * the striped dir (rm -rf striped_dir), and during
336                          * lookup, it will hold the master inode of the striped
337                          * directory, whose inode state is NEW, then tries to
338                          * revalidate all of its slaves, (ll_prep_inode()->
339                          * ll_iget()->ll_read_inode2()-> ll_update_inode().).
340                          * And it will be blocked on the server side because
341                          * of 1.
342                          * 3. Then the client get the blocking_ast req, cancel
343                          * the lock, but being blocked if using ->ilookup5()),
344                          * because master inode state is NEW. */
345                         master_inode = ilookup5_nowait(inode->i_sb, hash,
346                                                         ll_test_inode_by_fid,
347                                                         (void *)&lli->lli_pfid);
348                         if (master_inode) {
349                                 ll_invalidate_negative_children(master_inode);
350                                 iput(master_inode);
351                         }
352                 } else {
353                         ll_invalidate_negative_children(inode);
354                 }
355         }
356
357         if ((bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM)) &&
358             inode->i_sb->s_root != NULL &&
359             inode != inode->i_sb->s_root->d_inode)
360                 ll_invalidate_aliases(inode);
361
362         if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM))
363                 forget_all_cached_acls(inode);
364
365         iput(inode);
366         RETURN_EXIT;
367 }
368
369 /* Check if the given lock may be downgraded instead of canceling and
370  * that convert is really needed. */
371 int ll_md_need_convert(struct ldlm_lock *lock)
372 {
373         struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
374         struct inode *inode;
375         __u64 wanted = lock->l_policy_data.l_inodebits.cancel_bits;
376         __u64 bits = lock->l_policy_data.l_inodebits.bits & ~wanted;
377         enum ldlm_mode mode = LCK_MINMODE;
378
379         if (!lock->l_conn_export ||
380             !exp_connect_lock_convert(lock->l_conn_export))
381                 return 0;
382
383         if (!wanted || !bits || ldlm_is_cancel(lock))
384                 return 0;
385
386         /* do not convert locks other than DOM for now */
387         if (!((bits | wanted) & MDS_INODELOCK_DOM))
388                 return 0;
389
390         /* We may have already remaining bits in some other lock so
391          * lock convert will leave us just extra lock for the same bit.
392          * Check if client has other lock with the same bits and the same
393          * or lower mode and don't convert if any.
394          */
395         switch (lock->l_req_mode) {
396         case LCK_PR:
397                 mode = LCK_PR;
398                 /* fallthrough */
399         case LCK_PW:
400                 mode |= LCK_CR;
401                 break;
402         case LCK_CW:
403                 mode = LCK_CW;
404                 /* fallthrough */
405         case LCK_CR:
406                 mode |= LCK_CR;
407                 break;
408         default:
409                 /* do not convert other modes */
410                 return 0;
411         }
412
413         /* is lock is too old to be converted? */
414         lock_res_and_lock(lock);
415         if (ktime_after(ktime_get(),
416                         ktime_add(lock->l_last_used,
417                                   ktime_set(ns->ns_dirty_age_limit, 0)))) {
418                 unlock_res_and_lock(lock);
419                 return 0;
420         }
421         unlock_res_and_lock(lock);
422
423         inode = ll_inode_from_resource_lock(lock);
424         ll_have_md_lock(inode, &bits, mode);
425         iput(inode);
426         return !!(bits);
427 }
428
429 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
430                        void *data, int flag)
431 {
432         struct lustre_handle lockh;
433         __u64 bits = lock->l_policy_data.l_inodebits.bits;
434         int rc;
435
436         ENTRY;
437
438         switch (flag) {
439         case LDLM_CB_BLOCKING:
440         {
441                 __u64 cancel_flags = LCF_ASYNC;
442
443                 if (ll_md_need_convert(lock)) {
444                         cancel_flags |= LCF_CONVERT;
445                         /* For lock convert some cancel actions may require
446                          * this lock with non-dropped canceled bits, e.g. page
447                          * flush for DOM lock. So call ll_lock_cancel_bits()
448                          * here while canceled bits are still set.
449                          */
450                         bits = lock->l_policy_data.l_inodebits.cancel_bits;
451                         if (bits & MDS_INODELOCK_DOM)
452                                 ll_lock_cancel_bits(lock, MDS_INODELOCK_DOM);
453                 }
454                 ldlm_lock2handle(lock, &lockh);
455                 rc = ldlm_cli_cancel(&lockh, cancel_flags);
456                 if (rc < 0) {
457                         CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
458                         RETURN(rc);
459                 }
460                 break;
461         }
462         case LDLM_CB_CANCELING:
463                 /* Nothing to do for non-granted locks */
464                 if (!ldlm_is_granted(lock))
465                         break;
466
467                 if (ldlm_is_converting(lock)) {
468                         /* this is called on already converted lock, so
469                          * ibits has remained bits only and cancel_bits
470                          * are bits that were dropped.
471                          * Note that DOM lock is handled prior lock convert
472                          * and is excluded here.
473                          */
474                         bits = lock->l_policy_data.l_inodebits.cancel_bits &
475                                 ~MDS_INODELOCK_DOM;
476                 } else {
477                         LASSERT(ldlm_is_canceling(lock));
478                 }
479                 ll_lock_cancel_bits(lock, bits);
480                 break;
481         default:
482                 LBUG();
483         }
484
485         RETURN(0);
486 }
487
488 __u32 ll_i2suppgid(struct inode *i)
489 {
490         if (in_group_p(i->i_gid))
491                 return (__u32)from_kgid(&init_user_ns, i->i_gid);
492         else
493                 return (__u32) __kgid_val(INVALID_GID);
494 }
495
496 /* Pack the required supplementary groups into the supplied groups array.
497  * If we don't need to use the groups from the target inode(s) then we
498  * instead pack one or more groups from the user's supplementary group
499  * array in case it might be useful.  Not needed if doing an MDS-side upcall. */
500 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
501 {
502         LASSERT(i1 != NULL);
503         LASSERT(suppgids != NULL);
504
505         suppgids[0] = ll_i2suppgid(i1);
506
507         if (i2)
508                 suppgids[1] = ll_i2suppgid(i2);
509         else
510                 suppgids[1] = -1;
511 }
512
513 /*
514  * try to reuse three types of dentry:
515  * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
516  *    by concurrent .revalidate).
517  * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
518  *    be cleared by others calling d_lustre_revalidate).
519  * 3. DISCONNECTED alias.
520  */
521 static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
522 {
523         struct dentry *alias, *discon_alias, *invalid_alias;
524         DECLARE_LL_D_HLIST_NODE_PTR(p);
525
526         if (ll_d_hlist_empty(&inode->i_dentry))
527                 return NULL;
528
529         discon_alias = invalid_alias = NULL;
530
531         spin_lock(&inode->i_lock);
532         ll_d_hlist_for_each_entry(alias, p, &inode->i_dentry) {
533                 LASSERT(alias != dentry);
534
535                 spin_lock(&alias->d_lock);
536                 if ((alias->d_flags & DCACHE_DISCONNECTED) &&
537                     S_ISDIR(inode->i_mode))
538                         /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
539                         discon_alias = alias;
540                 else if (alias->d_parent == dentry->d_parent             &&
541                          alias->d_name.hash == dentry->d_name.hash       &&
542                          alias->d_name.len == dentry->d_name.len         &&
543                          memcmp(alias->d_name.name, dentry->d_name.name,
544                                 dentry->d_name.len) == 0)
545                         invalid_alias = alias;
546                 spin_unlock(&alias->d_lock);
547
548                 if (invalid_alias)
549                         break;
550         }
551         alias = invalid_alias ?: discon_alias ?: NULL;
552         if (alias) {
553                 spin_lock(&alias->d_lock);
554                 dget_dlock(alias);
555                 spin_unlock(&alias->d_lock);
556         }
557         spin_unlock(&inode->i_lock);
558
559         return alias;
560 }
561
562 /*
563  * Similar to d_splice_alias(), but lustre treats invalid alias
564  * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
565  */
566 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
567 {
568         struct dentry *new;
569         int rc;
570
571         if (inode) {
572                 new = ll_find_alias(inode, de);
573                 if (new) {
574                         rc = ll_d_init(new);
575                         if (rc < 0) {
576                                 dput(new);
577                                 return ERR_PTR(rc);
578                         }
579                         d_move(new, de);
580                         iput(inode);
581                         CDEBUG(D_DENTRY,
582                                "Reuse dentry %p inode %p refc %d flags %#x\n",
583                               new, new->d_inode, ll_d_count(new), new->d_flags);
584                         return new;
585                 }
586         }
587         rc = ll_d_init(de);
588         if (rc < 0)
589                 return ERR_PTR(rc);
590         d_add(de, inode);
591         CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n",
592                de, de->d_inode, ll_d_count(de), de->d_flags);
593         return de;
594 }
595
596 static int ll_lookup_it_finish(struct ptlrpc_request *request,
597                                struct lookup_intent *it,
598                                struct inode *parent, struct dentry **de,
599                                void *secctx, __u32 secctxlen)
600 {
601         struct inode             *inode = NULL;
602         __u64                     bits = 0;
603         int                       rc;
604         struct dentry *alias;
605         ENTRY;
606
607         /* NB 1 request reference will be taken away by ll_intent_lock()
608          * when I return */
609         CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it,
610                it->it_disposition);
611         if (!it_disposition(it, DISP_LOOKUP_NEG)) {
612                 struct req_capsule *pill = &request->rq_pill;
613                 struct mdt_body *body = req_capsule_server_get(pill,
614                                                                &RMF_MDT_BODY);
615
616                 rc = ll_prep_inode(&inode, request, (*de)->d_sb, it);
617                 if (rc)
618                         RETURN(rc);
619
620                 if (it->it_op & IT_OPEN)
621                         ll_dom_finish_open(inode, request, it);
622
623                 ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits);
624
625                 /* We used to query real size from OSTs here, but actually
626                  * this is not needed. For stat() calls size would be updated
627                  * from subsequent do_revalidate()->ll_inode_revalidate_it() in
628                  * 2.4 and
629                  * vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
630                  * Everybody else who needs correct file size would call
631                  * ll_glimpse_size or some equivalent themselves anyway.
632                  * Also see bug 7198.
633                  */
634
635                 /* If security context was returned by MDT, put it in
636                  * inode now to save an extra getxattr from security hooks,
637                  * and avoid deadlock.
638                  */
639                 if (body->mbo_valid & OBD_MD_SECCTX) {
640                         secctx = req_capsule_server_get(pill, &RMF_FILE_SECCTX);
641                         secctxlen = req_capsule_get_size(pill,
642                                                            &RMF_FILE_SECCTX,
643                                                            RCL_SERVER);
644
645                         if (secctxlen)
646                                 CDEBUG(D_SEC, "server returned security context"
647                                        " for "DFID"\n",
648                                        PFID(ll_inode2fid(inode)));
649                 }
650
651                 if (secctx != NULL && secctxlen != 0) {
652                         inode_lock(inode);
653                         rc = security_inode_notifysecctx(inode, secctx,
654                                                          secctxlen);
655                         inode_unlock(inode);
656                         if (rc)
657                                 CWARN("cannot set security context for "
658                                       DFID": rc = %d\n",
659                                       PFID(ll_inode2fid(inode)), rc);
660                 }
661         }
662
663         /* Only hash *de if it is unhashed (new dentry).
664          * Atoimc_open may passin hashed dentries for open.
665          */
666         alias = ll_splice_alias(inode, *de);
667         if (IS_ERR(alias))
668                 GOTO(out, rc = PTR_ERR(alias));
669
670         *de = alias;
671
672         if (!it_disposition(it, DISP_LOOKUP_NEG)) {
673                 /* we have lookup look - unhide dentry */
674                 if (bits & MDS_INODELOCK_LOOKUP)
675                         d_lustre_revalidate(*de);
676         } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
677                 /*
678                  * If file was created on the server, the dentry is revalidated
679                  * in ll_create_it if the lock allows for it.
680                  */
681                 /* Check that parent has UPDATE lock. */
682                 struct lookup_intent parent_it = {
683                                         .it_op = IT_GETATTR,
684                                         .it_lock_handle = 0 };
685                 struct lu_fid   fid = ll_i2info(parent)->lli_fid;
686
687                 /* If it is striped directory, get the real stripe parent */
688                 if (unlikely(ll_dir_striped(parent))) {
689                         rc = md_get_fid_from_lsm(ll_i2mdexp(parent),
690                                                  ll_i2info(parent)->lli_lsm_md,
691                                                  (*de)->d_name.name,
692                                                  (*de)->d_name.len, &fid);
693                         if (rc != 0)
694                                 GOTO(out, rc);
695                 }
696
697                 if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it, &fid,
698                                        NULL)) {
699                         d_lustre_revalidate(*de);
700                         ll_intent_release(&parent_it);
701                 }
702         }
703
704         GOTO(out, rc = 0);
705
706 out:
707         if (rc != 0 && it->it_op & IT_OPEN)
708                 ll_open_cleanup((*de)->d_sb, request);
709
710         return rc;
711 }
712
713 struct pcc_create_attach {
714         struct pcc_dataset *pca_dataset;
715         struct dentry *pca_dentry;
716 };
717
718 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
719                                    struct lookup_intent *it,
720                                    void **secctx, __u32 *secctxlen,
721                                    struct pcc_create_attach *pca)
722 {
723         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
724         struct dentry *save = dentry, *retval;
725         struct ptlrpc_request *req = NULL;
726         struct md_op_data *op_data = NULL;
727         struct lov_user_md *lum = NULL;
728         __u32 opc;
729         int rc;
730         char secctx_name[XATTR_NAME_MAX + 1];
731
732         ENTRY;
733
734         if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
735                 RETURN(ERR_PTR(-ENAMETOOLONG));
736
737         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), intent=%s\n",
738                dentry->d_name.len, dentry->d_name.name,
739                PFID(ll_inode2fid(parent)), parent, LL_IT2STR(it));
740
741         if (d_mountpoint(dentry))
742                 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
743
744         if (it == NULL || it->it_op == IT_GETXATTR)
745                 it = &lookup_it;
746
747         if (it->it_op == IT_GETATTR && dentry_may_statahead(parent, dentry)) {
748                 rc = ll_statahead(parent, &dentry, 0);
749                 if (rc == 1)
750                         RETURN(dentry == save ? NULL : dentry);
751         }
752
753         if (it->it_op & IT_OPEN && it->it_flags & FMODE_WRITE &&
754             dentry->d_sb->s_flags & SB_RDONLY)
755                 RETURN(ERR_PTR(-EROFS));
756
757         if (it->it_op & IT_CREAT)
758                 opc = LUSTRE_OPC_CREATE;
759         else
760                 opc = LUSTRE_OPC_ANY;
761
762         op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
763                                      dentry->d_name.len, 0, opc, NULL);
764         if (IS_ERR(op_data))
765                 GOTO(out, retval = ERR_CAST(op_data));
766
767         /* enforce umask if acl disabled or MDS doesn't support umask */
768         if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
769                 it->it_create_mode &= ~current_umask();
770
771         if (it->it_op & IT_CREAT &&
772             ll_i2sbi(parent)->ll_flags & LL_SBI_FILE_SECCTX) {
773                 rc = ll_dentry_init_security(dentry, it->it_create_mode,
774                                              &dentry->d_name,
775                                              &op_data->op_file_secctx_name,
776                                              &op_data->op_file_secctx,
777                                              &op_data->op_file_secctx_size);
778                 if (rc < 0)
779                         GOTO(out, retval = ERR_PTR(rc));
780                 if (secctx != NULL)
781                         *secctx = op_data->op_file_secctx;
782                 if (secctxlen != NULL)
783                         *secctxlen = op_data->op_file_secctx_size;
784         } else {
785                 if (secctx != NULL)
786                         *secctx = NULL;
787                 if (secctxlen != NULL)
788                         *secctxlen = 0;
789         }
790
791         /* ask for security context upon intent */
792         if (it->it_op & (IT_LOOKUP | IT_GETATTR | IT_OPEN)) {
793                 /* get name of security xattr to request to server */
794                 rc = ll_listsecurity(parent, secctx_name,
795                                      sizeof(secctx_name));
796                 if (rc < 0) {
797                         CDEBUG(D_SEC, "cannot get security xattr name for "
798                                DFID": rc = %d\n",
799                                PFID(ll_inode2fid(parent)), rc);
800                 } else if (rc > 0) {
801                         op_data->op_file_secctx_name = secctx_name;
802                         op_data->op_file_secctx_name_size = rc;
803                         CDEBUG(D_SEC, "'%.*s' is security xattr for "DFID"\n",
804                                rc, secctx_name, PFID(ll_inode2fid(parent)));
805                 }
806         }
807
808         if (pca && pca->pca_dataset) {
809                 struct pcc_dataset *dataset = pca->pca_dataset;
810
811                 OBD_ALLOC_PTR(lum);
812                 if (lum == NULL)
813                         GOTO(out, retval = ERR_PTR(-ENOMEM));
814
815                 lum->lmm_magic = LOV_USER_MAGIC_V1;
816                 lum->lmm_pattern = LOV_PATTERN_F_RELEASED | LOV_PATTERN_RAID0;
817                 op_data->op_data = lum;
818                 op_data->op_data_size = sizeof(*lum);
819                 op_data->op_archive_id = dataset->pccd_rwid;
820
821                 rc = obd_fid_alloc(NULL, ll_i2mdexp(parent), &op_data->op_fid2,
822                                    op_data);
823                 if (rc)
824                         GOTO(out, retval = ERR_PTR(rc));
825
826                 rc = pcc_inode_create(parent->i_sb, dataset, &op_data->op_fid2,
827                                       &pca->pca_dentry);
828                 if (rc)
829                         GOTO(out, retval = ERR_PTR(rc));
830
831                 it->it_flags |= MDS_OPEN_PCC;
832         }
833
834         rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
835                             &ll_md_blocking_ast, 0);
836         /* If the MDS allows the client to chgrp (CFS_SETGRP_PERM), but the
837          * client does not know which suppgid should be sent to the MDS, or
838          * some other(s) changed the target file's GID after this RPC sent
839          * to the MDS with the suppgid as the original GID, then we should
840          * try again with right suppgid. */
841         if (rc == -EACCES && it->it_op & IT_OPEN &&
842             it_disposition(it, DISP_OPEN_DENY)) {
843                 struct mdt_body *body;
844
845                 LASSERT(req != NULL);
846
847                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
848                 if (op_data->op_suppgids[0] == body->mbo_gid ||
849                     op_data->op_suppgids[1] == body->mbo_gid ||
850                     !in_group_p(make_kgid(&init_user_ns, body->mbo_gid)))
851                         GOTO(out, retval = ERR_PTR(-EACCES));
852
853                 fid_zero(&op_data->op_fid2);
854                 op_data->op_suppgids[1] = body->mbo_gid;
855                 ptlrpc_req_finished(req);
856                 req = NULL;
857                 ll_intent_release(it);
858                 rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
859                                     &ll_md_blocking_ast, 0);
860         }
861
862         if (rc < 0)
863                 GOTO(out, retval = ERR_PTR(rc));
864
865         /* dir layout may change */
866         ll_unlock_md_op_lsm(op_data);
867         rc = ll_lookup_it_finish(req, it, parent, &dentry,
868                                  secctx != NULL ? *secctx : NULL,
869                                  secctxlen != NULL ? *secctxlen : 0);
870         if (rc != 0) {
871                 ll_intent_release(it);
872                 GOTO(out, retval = ERR_PTR(rc));
873         }
874
875         if ((it->it_op & IT_OPEN) && dentry->d_inode &&
876             !S_ISREG(dentry->d_inode->i_mode) &&
877             !S_ISDIR(dentry->d_inode->i_mode)) {
878                 ll_release_openhandle(dentry, it);
879         }
880         ll_lookup_finish_locks(it, dentry);
881
882         GOTO(out, retval = (dentry == save) ? NULL : dentry);
883
884 out:
885         if (op_data != NULL && !IS_ERR(op_data)) {
886                 if (secctx != NULL && secctxlen != NULL) {
887                         /* caller needs sec ctx info, so reset it in op_data to
888                          * prevent it from being freed */
889                         op_data->op_file_secctx = NULL;
890                         op_data->op_file_secctx_size = 0;
891                 }
892                 ll_finish_md_op_data(op_data);
893         }
894
895         if (lum != NULL)
896                 OBD_FREE_PTR(lum);
897
898         ptlrpc_req_finished(req);
899         return retval;
900 }
901
902 #ifdef HAVE_IOP_ATOMIC_OPEN
903 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
904                                    unsigned int flags)
905 {
906         struct lookup_intent *itp, it = { .it_op = IT_GETATTR };
907         struct dentry *de;
908
909         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), flags=%u\n",
910                dentry->d_name.len, dentry->d_name.name,
911                PFID(ll_inode2fid(parent)), parent, flags);
912
913         /*
914          * Optimize away (CREATE && !OPEN). Let .create handle the race.
915          * but only if we have write permissions there, otherwise we need
916          * to proceed with lookup. LU-4185
917          */
918         if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN) &&
919             (inode_permission(parent, MAY_WRITE | MAY_EXEC) == 0))
920                 return NULL;
921
922         if (flags & (LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE))
923                 itp = NULL;
924         else
925                 itp = &it;
926         de = ll_lookup_it(parent, dentry, itp, NULL, NULL, NULL);
927
928         if (itp != NULL)
929                 ll_intent_release(itp);
930
931         return de;
932 }
933
934 #ifdef FMODE_CREATED /* added in Linux v4.18-rc1-20-g73a09dd */
935 # define ll_is_opened(o, f)             ((f)->f_mode & FMODE_OPENED)
936 # define ll_finish_open(f, d, o)        finish_open((f), (d), NULL)
937 # define ll_last_arg
938 # define ll_set_created(o, f)                                           \
939 do {                                                                    \
940         (f)->f_mode |= FMODE_CREATED;                                   \
941 } while (0)
942
943 #else
944 # define ll_is_opened(o, f)             (*(o))
945 # define ll_finish_open(f, d, o)        finish_open((f), (d), NULL, (o))
946 # define ll_last_arg                    , int *opened
947 # define ll_set_created(o, f)                                           \
948 do {                                                                    \
949         *(o) |= FILE_CREATED;                                           \
950 } while (0)
951
952 #endif
953
954 /*
955  * For cached negative dentry and new dentry, handle lookup/create/open
956  * together.
957  */
958 static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
959                           struct file *file, unsigned open_flags,
960                           umode_t mode ll_last_arg)
961 {
962         struct lookup_intent *it;
963         struct dentry *de;
964         long long lookup_flags = LOOKUP_OPEN;
965         void *secctx = NULL;
966         __u32 secctxlen = 0;
967         struct ll_sb_info *sbi;
968         struct pcc_create_attach pca = {NULL, NULL};
969         struct pcc_dataset *dataset = NULL;
970         int rc = 0;
971         ENTRY;
972
973         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), file %p,"
974                            "open_flags %x, mode %x opened %d\n",
975                dentry->d_name.len, dentry->d_name.name,
976                PFID(ll_inode2fid(dir)), dir, file, open_flags, mode,
977                ll_is_opened(opened, file));
978
979         /* Only negative dentries enter here */
980         LASSERT(dentry->d_inode == NULL);
981
982         if (!d_unhashed(dentry)) {
983                 /* A valid negative dentry that just passed revalidation,
984                  * there's little point to try and open it server-side,
985                  * even though there's a minuscule chance it might succeed.
986                  * Either way it's a valid race to just return -ENOENT here.
987                  */
988                 if (!(open_flags & O_CREAT))
989                         return -ENOENT;
990
991                 /* Otherwise we just unhash it to be rehashed afresh via
992                  * lookup if necessary
993                  */
994                 d_drop(dentry);
995         }
996
997         OBD_ALLOC(it, sizeof(*it));
998         if (!it)
999                 RETURN(-ENOMEM);
1000
1001         it->it_op = IT_OPEN;
1002         if (open_flags & O_CREAT) {
1003                 it->it_op |= IT_CREAT;
1004                 lookup_flags |= LOOKUP_CREATE;
1005                 sbi = ll_i2sbi(dir);
1006                 /* Volatile file is used for HSM restore, so do not use PCC */
1007                 if (!filename_is_volatile(dentry->d_name.name,
1008                                           dentry->d_name.len, NULL)) {
1009                         struct pcc_matcher item;
1010
1011                         item.pm_uid = from_kuid(&init_user_ns, current_uid());
1012                         item.pm_gid = from_kgid(&init_user_ns, current_gid());
1013                         item.pm_projid = ll_i2info(dir)->lli_projid;
1014                         item.pm_name = &dentry->d_name;
1015                         dataset = pcc_dataset_match_get(&sbi->ll_pcc_super,
1016                                                         &item);
1017                         pca.pca_dataset = dataset;
1018                 }
1019         }
1020         it->it_create_mode = (mode & S_IALLUGO) | S_IFREG;
1021         it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags);
1022         it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
1023
1024         /* Dentry added to dcache tree in ll_lookup_it */
1025         de = ll_lookup_it(dir, dentry, it, &secctx, &secctxlen, &pca);
1026         if (IS_ERR(de))
1027                 rc = PTR_ERR(de);
1028         else if (de != NULL)
1029                 dentry = de;
1030
1031         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1032
1033         if (!rc) {
1034                 if (it_disposition(it, DISP_OPEN_CREATE)) {
1035                         /* Dentry instantiated in ll_create_it. */
1036                         rc = ll_create_it(dir, dentry, it, secctx, secctxlen);
1037                         security_release_secctx(secctx, secctxlen);
1038                         if (rc) {
1039                                 /* We dget in ll_splice_alias. */
1040                                 if (de != NULL)
1041                                         dput(de);
1042                                 goto out_release;
1043                         }
1044                         if (dataset != NULL && dentry->d_inode) {
1045                                 rc = pcc_inode_create_fini(dataset,
1046                                                            dentry->d_inode,
1047                                                            pca.pca_dentry);
1048                                 if (rc) {
1049                                         if (de != NULL)
1050                                                 dput(de);
1051                                         GOTO(out_release, rc);
1052                                 }
1053                         }
1054                         ll_set_created(opened, file);
1055                 }
1056
1057                 if (dentry->d_inode && it_disposition(it, DISP_OPEN_OPEN)) {
1058                         /* Open dentry. */
1059                         if (S_ISFIFO(dentry->d_inode->i_mode)) {
1060                                 /* We cannot call open here as it might
1061                                  * deadlock. This case is unreachable in
1062                                  * practice because of OBD_CONNECT_NODEVOH. */
1063                                 rc = finish_no_open(file, de);
1064                         } else {
1065                                 file->private_data = it;
1066                                 rc = ll_finish_open(file, dentry, opened);
1067                                 /* We dget in ll_splice_alias. finish_open takes
1068                                  * care of dget for fd open.
1069                                  */
1070                                 if (de != NULL)
1071                                         dput(de);
1072                         }
1073                 } else {
1074                         rc = finish_no_open(file, de);
1075                 }
1076         }
1077
1078 out_release:
1079         if (dataset != NULL)
1080                 pcc_dataset_put(dataset);
1081         ll_intent_release(it);
1082         OBD_FREE(it, sizeof(*it));
1083
1084         RETURN(rc);
1085 }
1086
1087 #else /* !HAVE_IOP_ATOMIC_OPEN */
1088 static struct lookup_intent *
1089 ll_convert_intent(struct open_intent *oit, int lookup_flags, bool is_readonly)
1090 {
1091         struct lookup_intent *it;
1092
1093         OBD_ALLOC_PTR(it);
1094         if (!it)
1095                 return ERR_PTR(-ENOMEM);
1096
1097         if (lookup_flags & LOOKUP_OPEN) {
1098                 it->it_op = IT_OPEN;
1099                 /* Avoid file creation for ro bind mount point(is_readonly) */
1100                 if ((lookup_flags & LOOKUP_CREATE) && !is_readonly)
1101                         it->it_op |= IT_CREAT;
1102                 it->it_create_mode = (oit->create_mode & S_IALLUGO) | S_IFREG;
1103                 it->it_flags = ll_namei_to_lookup_intent_flag(oit->flags &
1104                                                 ~(is_readonly ? O_CREAT : 0));
1105                 it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
1106         } else {
1107                 it->it_op = IT_GETATTR;
1108         }
1109
1110         return it;
1111 }
1112
1113 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
1114                                    struct nameidata *nd)
1115 {
1116         struct dentry *de;
1117         ENTRY;
1118
1119         if (nd && !(nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT))) {
1120                 struct lookup_intent *it;
1121
1122                 if (ll_d2d(dentry) && ll_d2d(dentry)->lld_it) {
1123                         it = ll_d2d(dentry)->lld_it;
1124                         ll_d2d(dentry)->lld_it = NULL;
1125                 } else {
1126                         /*
1127                          * Optimize away (CREATE && !OPEN). Let .create handle
1128                          * the race. But only if we have write permissions
1129                          * there, otherwise we need to proceed with lookup.
1130                          * LU-4185
1131                          */
1132                         if ((nd->flags & LOOKUP_CREATE) &&
1133                             !(nd->flags & LOOKUP_OPEN) &&
1134                             (inode_permission(parent,
1135                                               MAY_WRITE | MAY_EXEC) == 0))
1136                                 RETURN(NULL);
1137
1138                         it = ll_convert_intent(&nd->intent.open, nd->flags,
1139                                 (nd->path.mnt->mnt_flags & MNT_READONLY) ||
1140                                 (nd->path.mnt->mnt_sb->s_flags & SB_RDONLY));
1141                         if (IS_ERR(it))
1142                                 RETURN((struct dentry *)it);
1143                 }
1144
1145                 de = ll_lookup_it(parent, dentry, it, NULL, NULL, NULL);
1146                 if (de)
1147                         dentry = de;
1148                 if ((nd->flags & LOOKUP_OPEN) && !IS_ERR(dentry)) { /* Open */
1149                         if (dentry->d_inode &&
1150                             it_disposition(it, DISP_OPEN_OPEN)) { /* nocreate */
1151                                 if (S_ISFIFO(dentry->d_inode->i_mode)) {
1152                                         /* We cannot call open here as it might
1153                                          * deadlock. This case is unreachable in
1154                                          * practice because of
1155                                          * OBD_CONNECT_NODEVOH. */
1156                                 } else {
1157                                         struct file *filp;
1158
1159                                         nd->intent.open.file->private_data = it;
1160                                         filp = lookup_instantiate_filp(nd,
1161                                                                        dentry,
1162                                                                        NULL);
1163                                         if (IS_ERR(filp)) {
1164                                                 if (de)
1165                                                         dput(de);
1166                                                 de = (struct dentry *)filp;
1167                                         }
1168                                 }
1169                         } else if (it_disposition(it, DISP_OPEN_CREATE)) {
1170                                 /* XXX This can only reliably work on assumption
1171                                  * that there are NO hashed negative dentries.*/
1172                                 ll_d2d(dentry)->lld_it = it;
1173                                 it = NULL; /* Will be freed in ll_create_nd */
1174                                 /* We absolutely depend on ll_create_nd to be
1175                                  * called to not leak this intent and possible
1176                                  * data attached to it */
1177                         }
1178                 }
1179
1180                 if (it) {
1181                         ll_intent_release(it);
1182                         OBD_FREE(it, sizeof(*it));
1183                 }
1184         } else {
1185                 de = ll_lookup_it(parent, dentry, NULL, NULL, NULL, NULL);
1186         }
1187
1188         RETURN(de);
1189 }
1190 #endif /* HAVE_IOP_ATOMIC_OPEN */
1191
1192 /* We depend on "mode" being set with the proper file type/umask by now */
1193 static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
1194 {
1195         struct inode *inode = NULL;
1196         struct ptlrpc_request *request = NULL;
1197         struct ll_sb_info *sbi = ll_i2sbi(dir);
1198         int rc;
1199         ENTRY;
1200
1201         LASSERT(it && it->it_disposition);
1202
1203         LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
1204         request = it->it_request;
1205         it_clear_disposition(it, DISP_ENQ_CREATE_REF);
1206         rc = ll_prep_inode(&inode, request, dir->i_sb, it);
1207         if (rc)
1208                 GOTO(out, inode = ERR_PTR(rc));
1209
1210         /* Pause to allow for a race with concurrent access by fid */
1211         OBD_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_NODE_PAUSE, cfs_fail_val);
1212
1213         /* We asked for a lock on the directory, but were granted a
1214          * lock on the inode.  Since we finally have an inode pointer,
1215          * stuff it in the lock. */
1216         CDEBUG(D_DLMTRACE, "setting l_ast_data to inode "DFID"(%p)\n",
1217                PFID(ll_inode2fid(inode)), inode);
1218         ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
1219         EXIT;
1220  out:
1221         ptlrpc_req_finished(request);
1222         return inode;
1223 }
1224
1225 /*
1226  * By the time this is called, we already have created the directory cache
1227  * entry for the new file, but it is so far negative - it has no inode.
1228  *
1229  * We defer creating the OBD object(s) until open, to keep the intent and
1230  * non-intent code paths similar, and also because we do not have the MDS
1231  * inode number before calling ll_create_node() (which is needed for LOV),
1232  * so we would need to do yet another RPC to the MDS to store the LOV EA
1233  * data on the MDS.  If needed, we would pass the PACKED lmm as data and
1234  * lmm_size in datalen (the MDS still has code which will handle that).
1235  *
1236  * If the create succeeds, we fill in the inode information
1237  * with d_instantiate().
1238  */
1239 static int ll_create_it(struct inode *dir, struct dentry *dentry,
1240                         struct lookup_intent *it,
1241                         void *secctx, __u32 secctxlen)
1242 {
1243         struct inode *inode;
1244         __u64 bits = 0;
1245         int rc = 0;
1246         ENTRY;
1247
1248         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), intent=%s\n",
1249                dentry->d_name.len, dentry->d_name.name,
1250                PFID(ll_inode2fid(dir)), dir, LL_IT2STR(it));
1251
1252         rc = it_open_error(DISP_OPEN_CREATE, it);
1253         if (rc)
1254                 RETURN(rc);
1255
1256         inode = ll_create_node(dir, it);
1257         if (IS_ERR(inode))
1258                 RETURN(PTR_ERR(inode));
1259
1260         if ((ll_i2sbi(inode)->ll_flags & LL_SBI_FILE_SECCTX) &&
1261             secctx != NULL) {
1262                 inode_lock(inode);
1263                 /* must be done before d_instantiate, because it calls
1264                  * security_d_instantiate, which means a getxattr if security
1265                  * context is not set yet */
1266                 rc = security_inode_notifysecctx(inode, secctx, secctxlen);
1267                 inode_unlock(inode);
1268                 if (rc)
1269                         RETURN(rc);
1270         }
1271
1272         d_instantiate(dentry, inode);
1273
1274         if (!(ll_i2sbi(inode)->ll_flags & LL_SBI_FILE_SECCTX)) {
1275                 rc = ll_inode_init_security(dentry, inode, dir);
1276                 if (rc)
1277                         RETURN(rc);
1278         }
1279
1280         ll_set_lock_data(ll_i2sbi(dir)->ll_md_exp, inode, it, &bits);
1281         if (bits & MDS_INODELOCK_LOOKUP)
1282                 d_lustre_revalidate(dentry);
1283
1284         RETURN(0);
1285 }
1286
1287 void ll_update_times(struct ptlrpc_request *request, struct inode *inode)
1288 {
1289         struct mdt_body *body = req_capsule_server_get(&request->rq_pill,
1290                                                        &RMF_MDT_BODY);
1291
1292         LASSERT(body);
1293         if (body->mbo_valid & OBD_MD_FLMTIME &&
1294             body->mbo_mtime > inode->i_mtime.tv_sec) {
1295                 CDEBUG(D_INODE,
1296                        "setting fid " DFID " mtime from %lld to %llu\n",
1297                        PFID(ll_inode2fid(inode)),
1298                        (s64)inode->i_mtime.tv_sec, body->mbo_mtime);
1299                 inode->i_mtime.tv_sec = body->mbo_mtime;
1300         }
1301
1302         if (body->mbo_valid & OBD_MD_FLCTIME &&
1303             body->mbo_ctime > inode->i_ctime.tv_sec)
1304                 inode->i_ctime.tv_sec = body->mbo_ctime;
1305 }
1306
1307 static int ll_new_node(struct inode *dir, struct dentry *dchild,
1308                        const char *tgt, umode_t mode, int rdev, __u32 opc)
1309 {
1310         struct qstr *name = &dchild->d_name;
1311         struct ptlrpc_request *request = NULL;
1312         struct md_op_data *op_data;
1313         struct inode *inode = NULL;
1314         struct ll_sb_info *sbi = ll_i2sbi(dir);
1315         int tgt_len = 0;
1316         int err;
1317
1318         ENTRY;
1319         if (unlikely(tgt != NULL))
1320                 tgt_len = strlen(tgt) + 1;
1321
1322 again:
1323         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name,
1324                                      name->len, 0, opc, NULL);
1325         if (IS_ERR(op_data))
1326                 GOTO(err_exit, err = PTR_ERR(op_data));
1327
1328         if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
1329                 err = ll_dentry_init_security(dchild, mode, &dchild->d_name,
1330                                               &op_data->op_file_secctx_name,
1331                                               &op_data->op_file_secctx,
1332                                               &op_data->op_file_secctx_size);
1333                 if (err < 0)
1334                         GOTO(err_exit, err);
1335         }
1336
1337         err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
1338                         from_kuid(&init_user_ns, current_fsuid()),
1339                         from_kgid(&init_user_ns, current_fsgid()),
1340                         cfs_curproc_cap_pack(), rdev, &request);
1341 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 58, 0)
1342         /*
1343          * server < 2.12.58 doesn't pack default LMV in intent_getattr reply,
1344          * fetch default LMV here.
1345          */
1346         if (unlikely(err == -EREMOTE)) {
1347                 struct ll_inode_info    *lli = ll_i2info(dir);
1348                 struct lmv_user_md      *lum;
1349                 int                     lumsize;
1350                 int                     err2;
1351
1352                 ptlrpc_req_finished(request);
1353                 request = NULL;
1354
1355                 err2 = ll_dir_getstripe(dir, (void **)&lum, &lumsize, &request,
1356                                         OBD_MD_DEFAULT_MEA);
1357                 ll_finish_md_op_data(op_data);
1358                 op_data = NULL;
1359                 if (err2 == 0) {
1360                         struct lustre_md md = { NULL };
1361
1362                         md.body = req_capsule_server_get(&request->rq_pill,
1363                                                          &RMF_MDT_BODY);
1364                         if (!md.body)
1365                                 GOTO(err_exit, err = -EPROTO);
1366
1367                         OBD_ALLOC_PTR(md.default_lmv);
1368                         if (!md.default_lmv)
1369                                 GOTO(err_exit, err = -ENOMEM);
1370
1371                         md.default_lmv->lsm_md_magic = lum->lum_magic;
1372                         md.default_lmv->lsm_md_stripe_count =
1373                                 lum->lum_stripe_count;
1374                         md.default_lmv->lsm_md_master_mdt_index =
1375                                 lum->lum_stripe_offset;
1376                         md.default_lmv->lsm_md_hash_type = lum->lum_hash_type;
1377
1378                         err = ll_update_inode(dir, &md);
1379                         md_free_lustre_md(sbi->ll_md_exp, &md);
1380                         if (err)
1381                                 GOTO(err_exit, err);
1382                 } else if (err2 == -ENODATA && lli->lli_default_lsm_md) {
1383                         /*
1384                          * If there are no default stripe EA on the MDT, but the
1385                          * client has default stripe, then it probably means
1386                          * default stripe EA has just been deleted.
1387                          */
1388                         down_write(&lli->lli_lsm_sem);
1389                         if (lli->lli_default_lsm_md)
1390                                 OBD_FREE_PTR(lli->lli_default_lsm_md);
1391                         lli->lli_default_lsm_md = NULL;
1392                         up_write(&lli->lli_lsm_sem);
1393                 } else {
1394                         GOTO(err_exit, err);
1395                 }
1396
1397                 ptlrpc_req_finished(request);
1398                 request = NULL;
1399                 goto again;
1400         }
1401 #endif
1402
1403         if (err < 0)
1404                 GOTO(err_exit, err);
1405
1406         ll_update_times(request, dir);
1407
1408         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_NEWNODE_PAUSE, cfs_fail_val);
1409
1410         err = ll_prep_inode(&inode, request, dchild->d_sb, NULL);
1411         if (err)
1412                 GOTO(err_exit, err);
1413
1414         if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
1415                 inode_lock(inode);
1416                 /* must be done before d_instantiate, because it calls
1417                  * security_d_instantiate, which means a getxattr if security
1418                  * context is not set yet */
1419                 err = security_inode_notifysecctx(inode,
1420                                                   op_data->op_file_secctx,
1421                                                   op_data->op_file_secctx_size);
1422                 inode_unlock(inode);
1423                 if (err)
1424                         GOTO(err_exit, err);
1425         }
1426
1427         d_instantiate(dchild, inode);
1428
1429         if (!(sbi->ll_flags & LL_SBI_FILE_SECCTX)) {
1430                 err = ll_inode_init_security(dchild, inode, dir);
1431                 if (err)
1432                         GOTO(err_exit, err);
1433         }
1434
1435         EXIT;
1436 err_exit:
1437         if (request != NULL)
1438                 ptlrpc_req_finished(request);
1439
1440         if (!IS_ERR_OR_NULL(op_data))
1441                 ll_finish_md_op_data(op_data);
1442
1443         return err;
1444 }
1445
1446 static int ll_mknod(struct inode *dir, struct dentry *dchild, ll_umode_t mode,
1447                     dev_t rdev)
1448 {
1449         struct qstr *name = &dchild->d_name;
1450         int err;
1451         ENTRY;
1452
1453         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p) mode %o dev %x\n",
1454                name->len, name->name, PFID(ll_inode2fid(dir)), dir,
1455                mode, rdev);
1456
1457         if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1458                 mode &= ~current_umask();
1459
1460         switch (mode & S_IFMT) {
1461         case 0:
1462                 mode |= S_IFREG;
1463                 /* fallthrough */
1464         case S_IFREG:
1465         case S_IFCHR:
1466         case S_IFBLK:
1467         case S_IFIFO:
1468         case S_IFSOCK:
1469                 err = ll_new_node(dir, dchild, NULL, mode, old_encode_dev(rdev),
1470                                   LUSTRE_OPC_MKNOD);
1471                 break;
1472         case S_IFDIR:
1473                 err = -EPERM;
1474                 break;
1475         default:
1476                 err = -EINVAL;
1477         }
1478
1479         if (!err)
1480                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKNOD, 1);
1481
1482         RETURN(err);
1483 }
1484
1485 #ifdef HAVE_IOP_ATOMIC_OPEN
1486 /*
1487  * Plain create. Intent create is handled in atomic_open.
1488  */
1489 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
1490                         umode_t mode, bool want_excl)
1491 {
1492         int rc;
1493
1494         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1495
1496         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), "
1497                            "flags=%u, excl=%d\n", dentry->d_name.len,
1498                dentry->d_name.name, PFID(ll_inode2fid(dir)),
1499                dir, mode, want_excl);
1500
1501         /* Using mknod(2) to create a regular file is designed to not recognize
1502          * volatile file name, so we use ll_mknod() here. */
1503         rc = ll_mknod(dir, dentry, mode, 0);
1504
1505         ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
1506
1507         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, unhashed %d\n",
1508                dentry->d_name.len, dentry->d_name.name, d_unhashed(dentry));
1509
1510         return rc;
1511 }
1512 #else /* !HAVE_IOP_ATOMIC_OPEN */
1513 static int ll_create_nd(struct inode *dir, struct dentry *dentry,
1514                         ll_umode_t mode, struct nameidata *nd)
1515 {
1516         struct ll_dentry_data *lld = ll_d2d(dentry);
1517         struct lookup_intent *it = NULL;
1518         int rc;
1519
1520         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1521
1522         if (lld != NULL)
1523                 it = lld->lld_it;
1524
1525         if (!it) {
1526                 /* LU-8559: use LUSTRE_OPC_CREATE for non atomic open case
1527                  * so that volatile file name is recoginized.
1528                  * Mknod(2), however, is designed to not recognize volatile
1529                  * file name to avoid inode leak under orphan directory until
1530                  * MDT reboot */
1531                 return ll_new_node(dir, dentry, NULL, mode, 0,
1532                                    LUSTRE_OPC_CREATE);
1533         }
1534
1535         lld->lld_it = NULL;
1536
1537         /* Was there an error? Propagate it! */
1538         if (it->it_status) {
1539                 rc = it->it_status;
1540                 goto out;
1541         }
1542
1543         rc = ll_create_it(dir, dentry, it, NULL, 0);
1544         if (nd && (nd->flags & LOOKUP_OPEN) && dentry->d_inode) { /* Open */
1545                 struct file *filp;
1546
1547                 nd->intent.open.file->private_data = it;
1548                 filp = lookup_instantiate_filp(nd, dentry, NULL);
1549                 if (IS_ERR(filp))
1550                         rc = PTR_ERR(filp);
1551         }
1552
1553 out:
1554         ll_intent_release(it);
1555         OBD_FREE(it, sizeof(*it));
1556
1557         if (!rc)
1558                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_CREATE, 1);
1559
1560         return rc;
1561 }
1562 #endif /* HAVE_IOP_ATOMIC_OPEN */
1563
1564 static int ll_symlink(struct inode *dir, struct dentry *dchild,
1565                       const char *oldpath)
1566 {
1567         struct qstr *name = &dchild->d_name;
1568         int err;
1569         ENTRY;
1570
1571         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), target=%.*s\n",
1572                name->len, name->name, PFID(ll_inode2fid(dir)),
1573                dir, 3000, oldpath);
1574
1575         err = ll_new_node(dir, dchild, oldpath, S_IFLNK | S_IRWXUGO, 0,
1576                           LUSTRE_OPC_SYMLINK);
1577
1578         if (!err)
1579                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_SYMLINK, 1);
1580
1581         RETURN(err);
1582 }
1583
1584 static int ll_link(struct dentry *old_dentry, struct inode *dir,
1585                    struct dentry *new_dentry)
1586 {
1587         struct inode *src = old_dentry->d_inode;
1588         struct qstr *name = &new_dentry->d_name;
1589         struct ll_sb_info *sbi = ll_i2sbi(dir);
1590         struct ptlrpc_request *request = NULL;
1591         struct md_op_data *op_data;
1592         int err;
1593
1594         ENTRY;
1595         CDEBUG(D_VFSTRACE, "VFS Op: inode="DFID"(%p), dir="DFID"(%p), "
1596                "target=%.*s\n", PFID(ll_inode2fid(src)), src,
1597                PFID(ll_inode2fid(dir)), dir, name->len, name->name);
1598
1599         op_data = ll_prep_md_op_data(NULL, src, dir, name->name, name->len,
1600                                      0, LUSTRE_OPC_ANY, NULL);
1601         if (IS_ERR(op_data))
1602                 RETURN(PTR_ERR(op_data));
1603
1604         err = md_link(sbi->ll_md_exp, op_data, &request);
1605         ll_finish_md_op_data(op_data);
1606         if (err)
1607                 GOTO(out, err);
1608
1609         ll_update_times(request, dir);
1610         ll_stats_ops_tally(sbi, LPROC_LL_LINK, 1);
1611         EXIT;
1612 out:
1613         ptlrpc_req_finished(request);
1614         RETURN(err);
1615 }
1616
1617 static int ll_mkdir(struct inode *dir, struct dentry *dchild, ll_umode_t mode)
1618 {
1619         struct qstr *name = &dchild->d_name;
1620         int err;
1621         ENTRY;
1622
1623         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1624                name->len, name->name, PFID(ll_inode2fid(dir)), dir);
1625
1626         if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1627                 mode &= ~current_umask();
1628
1629         mode = (mode & (S_IRWXUGO|S_ISVTX)) | S_IFDIR;
1630
1631         err = ll_new_node(dir, dchild, NULL, mode, 0, LUSTRE_OPC_MKDIR);
1632         if (err == 0)
1633                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_MKDIR, 1);
1634
1635         RETURN(err);
1636 }
1637
1638 static int ll_rmdir(struct inode *dir, struct dentry *dchild)
1639 {
1640         struct qstr *name = &dchild->d_name;
1641         struct ptlrpc_request *request = NULL;
1642         struct md_op_data *op_data;
1643         int rc;
1644         ENTRY;
1645
1646         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1647                name->len, name->name, PFID(ll_inode2fid(dir)), dir);
1648
1649         if (unlikely(d_mountpoint(dchild)))
1650                 RETURN(-EBUSY);
1651
1652         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len,
1653                                      S_IFDIR, LUSTRE_OPC_ANY, NULL);
1654         if (IS_ERR(op_data))
1655                 RETURN(PTR_ERR(op_data));
1656
1657         if (dchild->d_inode != NULL)
1658                 op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
1659
1660         op_data->op_fid2 = op_data->op_fid3;
1661         rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1662         ll_finish_md_op_data(op_data);
1663         if (rc == 0) {
1664                 ll_update_times(request, dir);
1665                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1666         }
1667
1668         ptlrpc_req_finished(request);
1669         RETURN(rc);
1670 }
1671
1672 /**
1673  * Remove dir entry
1674  **/
1675 int ll_rmdir_entry(struct inode *dir, char *name, int namelen)
1676 {
1677         struct ptlrpc_request *request = NULL;
1678         struct md_op_data *op_data;
1679         int rc;
1680         ENTRY;
1681
1682         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1683                namelen, name, PFID(ll_inode2fid(dir)), dir);
1684
1685         op_data = ll_prep_md_op_data(NULL, dir, NULL, name, strlen(name),
1686                                      S_IFDIR, LUSTRE_OPC_ANY, NULL);
1687         if (IS_ERR(op_data))
1688                 RETURN(PTR_ERR(op_data));
1689         op_data->op_cli_flags |= CLI_RM_ENTRY;
1690         rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1691         ll_finish_md_op_data(op_data);
1692         if (rc == 0) {
1693                 ll_update_times(request, dir);
1694                 ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_RMDIR, 1);
1695         }
1696
1697         ptlrpc_req_finished(request);
1698         RETURN(rc);
1699 }
1700
1701 static int ll_unlink(struct inode *dir, struct dentry *dchild)
1702 {
1703         struct qstr *name = &dchild->d_name;
1704         struct ptlrpc_request *request = NULL;
1705         struct md_op_data *op_data;
1706         struct mdt_body *body;
1707         int rc;
1708         ENTRY;
1709         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p)\n",
1710                name->len, name->name, PFID(ll_inode2fid(dir)), dir);
1711
1712         /*
1713          * XXX: unlink bind mountpoint maybe call to here,
1714          * just check it as vfs_unlink does.
1715          */
1716         if (unlikely(d_mountpoint(dchild)))
1717                 RETURN(-EBUSY);
1718
1719         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name, name->len, 0,
1720                                      LUSTRE_OPC_ANY, NULL);
1721         if (IS_ERR(op_data))
1722                 RETURN(PTR_ERR(op_data));
1723
1724         op_data->op_fid3 = *ll_inode2fid(dchild->d_inode);
1725
1726         op_data->op_fid2 = op_data->op_fid3;
1727         rc = md_unlink(ll_i2sbi(dir)->ll_md_exp, op_data, &request);
1728         ll_finish_md_op_data(op_data);
1729         if (rc)
1730                 GOTO(out, rc);
1731
1732         /*
1733          * The server puts attributes in on the last unlink, use them to update
1734          * the link count so the inode can be freed immediately.
1735          */
1736         body = req_capsule_server_get(&request->rq_pill, &RMF_MDT_BODY);
1737         if (body->mbo_valid & OBD_MD_FLNLINK)
1738                 set_nlink(dchild->d_inode, body->mbo_nlink);
1739
1740         ll_update_times(request, dir);
1741         ll_stats_ops_tally(ll_i2sbi(dir), LPROC_LL_UNLINK, 1);
1742
1743 out:
1744         ptlrpc_req_finished(request);
1745         RETURN(rc);
1746 }
1747
1748 static int ll_rename(struct inode *src, struct dentry *src_dchild,
1749                      struct inode *tgt, struct dentry *tgt_dchild
1750 #ifdef HAVE_IOPS_RENAME_WITH_FLAGS
1751                      , unsigned int flags
1752 #endif
1753                      )
1754 {
1755         struct qstr *src_name = &src_dchild->d_name;
1756         struct qstr *tgt_name = &tgt_dchild->d_name;
1757         struct ptlrpc_request *request = NULL;
1758         struct ll_sb_info *sbi = ll_i2sbi(src);
1759         struct md_op_data *op_data;
1760         int err;
1761         ENTRY;
1762
1763 #ifdef HAVE_IOPS_RENAME_WITH_FLAGS
1764         if (flags)
1765                 return -EINVAL;
1766 #endif
1767
1768         CDEBUG(D_VFSTRACE, "VFS Op:oldname=%.*s, src_dir="DFID
1769                "(%p), newname=%.*s, tgt_dir="DFID"(%p)\n",
1770                src_name->len, src_name->name,
1771                PFID(ll_inode2fid(src)), src, tgt_name->len,
1772                tgt_name->name, PFID(ll_inode2fid(tgt)), tgt);
1773
1774         if (unlikely(d_mountpoint(src_dchild) || d_mountpoint(tgt_dchild)))
1775                 RETURN(-EBUSY);
1776
1777         op_data = ll_prep_md_op_data(NULL, src, tgt, NULL, 0, 0,
1778                                      LUSTRE_OPC_ANY, NULL);
1779         if (IS_ERR(op_data))
1780                 RETURN(PTR_ERR(op_data));
1781
1782         if (src_dchild->d_inode != NULL)
1783                 op_data->op_fid3 = *ll_inode2fid(src_dchild->d_inode);
1784
1785         if (tgt_dchild->d_inode != NULL)
1786                 op_data->op_fid4 = *ll_inode2fid(tgt_dchild->d_inode);
1787
1788         err = md_rename(sbi->ll_md_exp, op_data,
1789                         src_name->name, src_name->len,
1790                         tgt_name->name, tgt_name->len, &request);
1791         ll_finish_md_op_data(op_data);
1792         if (!err) {
1793                 ll_update_times(request, src);
1794                 ll_update_times(request, tgt);
1795                 ll_stats_ops_tally(sbi, LPROC_LL_RENAME, 1);
1796         }
1797
1798         ptlrpc_req_finished(request);
1799
1800         if (err == 0)
1801                 d_move(src_dchild, tgt_dchild);
1802
1803         RETURN(err);
1804 }
1805
1806 const struct inode_operations ll_dir_inode_operations = {
1807         .mknod          = ll_mknod,
1808 #ifdef HAVE_IOP_ATOMIC_OPEN
1809         .atomic_open    = ll_atomic_open,
1810 #endif
1811         .lookup         = ll_lookup_nd,
1812         .create         = ll_create_nd,
1813         /* We need all these non-raw things for NFSD, to not patch it. */
1814         .unlink         = ll_unlink,
1815         .mkdir          = ll_mkdir,
1816         .rmdir          = ll_rmdir,
1817         .symlink        = ll_symlink,
1818         .link           = ll_link,
1819         .rename         = ll_rename,
1820         .setattr        = ll_setattr,
1821         .getattr        = ll_getattr,
1822         .permission     = ll_inode_permission,
1823 #ifdef HAVE_IOP_XATTR
1824         .setxattr       = ll_setxattr,
1825         .getxattr       = ll_getxattr,
1826         .removexattr    = ll_removexattr,
1827 #endif
1828         .listxattr      = ll_listxattr,
1829 #ifdef HAVE_IOP_GET_ACL
1830         .get_acl        = ll_get_acl,
1831 #endif
1832 #ifdef HAVE_IOP_SET_ACL
1833         .set_acl        = ll_set_acl,
1834 #endif
1835 };
1836
1837 const struct inode_operations ll_special_inode_operations = {
1838         .setattr        = ll_setattr,
1839         .getattr        = ll_getattr,
1840         .permission     = ll_inode_permission,
1841 #ifdef HAVE_IOP_XATTR
1842         .setxattr       = ll_setxattr,
1843         .getxattr       = ll_getxattr,
1844         .removexattr    = ll_removexattr,
1845 #endif
1846         .listxattr      = ll_listxattr,
1847 #ifdef HAVE_IOP_GET_ACL
1848         .get_acl        = ll_get_acl,
1849 #endif
1850 #ifdef HAVE_IOP_SET_ACL
1851         .set_acl        = ll_set_acl,
1852 #endif
1853 };