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