Whamcloud - gitweb
LU-12657 llite: forget cached ACLs properly
[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                 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         if (bits & (MDS_INODELOCK_LOOKUP | MDS_INODELOCK_PERM))
366                 forget_all_cached_acls(inode);
367
368         iput(inode);
369         RETURN_EXIT;
370 }
371
372 /* Check if the given lock may be downgraded instead of canceling and
373  * that convert is really needed. */
374 int ll_md_need_convert(struct ldlm_lock *lock)
375 {
376         struct ldlm_namespace *ns = ldlm_lock_to_ns(lock);
377         struct inode *inode;
378         __u64 wanted = lock->l_policy_data.l_inodebits.cancel_bits;
379         __u64 bits = lock->l_policy_data.l_inodebits.bits & ~wanted;
380         enum ldlm_mode mode = LCK_MINMODE;
381
382         if (!lock->l_conn_export ||
383             !exp_connect_lock_convert(lock->l_conn_export))
384                 return 0;
385
386         if (!wanted || !bits || ldlm_is_cancel(lock))
387                 return 0;
388
389         /* do not convert locks other than DOM for now */
390         if (!((bits | wanted) & MDS_INODELOCK_DOM))
391                 return 0;
392
393         /* We may have already remaining bits in some other lock so
394          * lock convert will leave us just extra lock for the same bit.
395          * Check if client has other lock with the same bits and the same
396          * or lower mode and don't convert if any.
397          */
398         switch (lock->l_req_mode) {
399         case LCK_PR:
400                 mode = LCK_PR;
401         case LCK_PW:
402                 mode |= LCK_CR;
403                 break;
404         case LCK_CW:
405                 mode = LCK_CW;
406         case LCK_CR:
407                 mode |= LCK_CR;
408                 break;
409         default:
410                 /* do not convert other modes */
411                 return 0;
412         }
413
414         /* is lock is too old to be converted? */
415         lock_res_and_lock(lock);
416         if (ktime_after(ktime_get(),
417                         ktime_add(lock->l_last_used,
418                                   ktime_set(ns->ns_dirty_age_limit, 0)))) {
419                 unlock_res_and_lock(lock);
420                 return 0;
421         }
422         unlock_res_and_lock(lock);
423
424         inode = ll_inode_from_resource_lock(lock);
425         ll_have_md_lock(inode, &bits, mode);
426         iput(inode);
427         return !!(bits);
428 }
429
430 int ll_md_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
431                        void *data, int flag)
432 {
433         struct lustre_handle lockh;
434         __u64 bits = lock->l_policy_data.l_inodebits.bits;
435         int rc;
436
437         ENTRY;
438
439         switch (flag) {
440         case LDLM_CB_BLOCKING:
441         {
442                 __u64 cancel_flags = LCF_ASYNC;
443
444                 if (ll_md_need_convert(lock)) {
445                         cancel_flags |= LCF_CONVERT;
446                         /* For lock convert some cancel actions may require
447                          * this lock with non-dropped canceled bits, e.g. page
448                          * flush for DOM lock. So call ll_lock_cancel_bits()
449                          * here while canceled bits are still set.
450                          */
451                         bits = lock->l_policy_data.l_inodebits.cancel_bits;
452                         if (bits & MDS_INODELOCK_DOM)
453                                 ll_lock_cancel_bits(lock, MDS_INODELOCK_DOM);
454                 }
455                 ldlm_lock2handle(lock, &lockh);
456                 rc = ldlm_cli_cancel(&lockh, cancel_flags);
457                 if (rc < 0) {
458                         CDEBUG(D_INODE, "ldlm_cli_cancel: rc = %d\n", rc);
459                         RETURN(rc);
460                 }
461                 break;
462         }
463         case LDLM_CB_CANCELING:
464                 /* Nothing to do for non-granted locks */
465                 if (!ldlm_is_granted(lock))
466                         break;
467
468                 if (ldlm_is_converting(lock)) {
469                         /* this is called on already converted lock, so
470                          * ibits has remained bits only and cancel_bits
471                          * are bits that were dropped.
472                          * Note that DOM lock is handled prior lock convert
473                          * and is excluded here.
474                          */
475                         bits = lock->l_policy_data.l_inodebits.cancel_bits &
476                                 ~MDS_INODELOCK_DOM;
477                 } else {
478                         LASSERT(ldlm_is_canceling(lock));
479                 }
480                 ll_lock_cancel_bits(lock, bits);
481                 break;
482         default:
483                 LBUG();
484         }
485
486         RETURN(0);
487 }
488
489 __u32 ll_i2suppgid(struct inode *i)
490 {
491         if (in_group_p(i->i_gid))
492                 return (__u32)from_kgid(&init_user_ns, i->i_gid);
493         else
494                 return (__u32) __kgid_val(INVALID_GID);
495 }
496
497 /* Pack the required supplementary groups into the supplied groups array.
498  * If we don't need to use the groups from the target inode(s) then we
499  * instead pack one or more groups from the user's supplementary group
500  * array in case it might be useful.  Not needed if doing an MDS-side upcall. */
501 void ll_i2gids(__u32 *suppgids, struct inode *i1, struct inode *i2)
502 {
503         LASSERT(i1 != NULL);
504         LASSERT(suppgids != NULL);
505
506         suppgids[0] = ll_i2suppgid(i1);
507
508         if (i2)
509                 suppgids[1] = ll_i2suppgid(i2);
510         else
511                 suppgids[1] = -1;
512 }
513
514 /*
515  * try to reuse three types of dentry:
516  * 1. unhashed alias, this one is unhashed by d_invalidate (but it may be valid
517  *    by concurrent .revalidate).
518  * 2. INVALID alias (common case for no valid ldlm lock held, but this flag may
519  *    be cleared by others calling d_lustre_revalidate).
520  * 3. DISCONNECTED alias.
521  */
522 static struct dentry *ll_find_alias(struct inode *inode, struct dentry *dentry)
523 {
524         struct dentry *alias, *discon_alias, *invalid_alias;
525         DECLARE_LL_D_HLIST_NODE_PTR(p);
526
527         if (ll_d_hlist_empty(&inode->i_dentry))
528                 return NULL;
529
530         discon_alias = invalid_alias = NULL;
531
532         spin_lock(&inode->i_lock);
533         ll_d_hlist_for_each_entry(alias, p, &inode->i_dentry) {
534                 LASSERT(alias != dentry);
535
536                 spin_lock(&alias->d_lock);
537                 if ((alias->d_flags & DCACHE_DISCONNECTED) &&
538                     S_ISDIR(inode->i_mode))
539                         /* LASSERT(last_discon == NULL); LU-405, bz 20055 */
540                         discon_alias = alias;
541                 else if (alias->d_parent == dentry->d_parent             &&
542                          alias->d_name.hash == dentry->d_name.hash       &&
543                          alias->d_name.len == dentry->d_name.len         &&
544                          memcmp(alias->d_name.name, dentry->d_name.name,
545                                 dentry->d_name.len) == 0)
546                         invalid_alias = alias;
547                 spin_unlock(&alias->d_lock);
548
549                 if (invalid_alias)
550                         break;
551         }
552         alias = invalid_alias ?: discon_alias ?: NULL;
553         if (alias) {
554                 spin_lock(&alias->d_lock);
555                 dget_dlock(alias);
556                 spin_unlock(&alias->d_lock);
557         }
558         spin_unlock(&inode->i_lock);
559
560         return alias;
561 }
562
563 /*
564  * Similar to d_splice_alias(), but lustre treats invalid alias
565  * similar to DCACHE_DISCONNECTED, and tries to use it anyway.
566  */
567 struct dentry *ll_splice_alias(struct inode *inode, struct dentry *de)
568 {
569         struct dentry *new;
570         int rc;
571
572         if (inode) {
573                 new = ll_find_alias(inode, de);
574                 if (new) {
575                         rc = ll_d_init(new);
576                         if (rc < 0) {
577                                 dput(new);
578                                 return ERR_PTR(rc);
579                         }
580                         d_move(new, de);
581                         iput(inode);
582                         CDEBUG(D_DENTRY,
583                                "Reuse dentry %p inode %p refc %d flags %#x\n",
584                               new, new->d_inode, ll_d_count(new), new->d_flags);
585                         return new;
586                 }
587         }
588         rc = ll_d_init(de);
589         if (rc < 0)
590                 return ERR_PTR(rc);
591         d_add(de, inode);
592         CDEBUG(D_DENTRY, "Add dentry %p inode %p refc %d flags %#x\n",
593                de, de->d_inode, ll_d_count(de), de->d_flags);
594         return de;
595 }
596
597 static int ll_lookup_it_finish(struct ptlrpc_request *request,
598                                struct lookup_intent *it,
599                                struct inode *parent, struct dentry **de,
600                                void *secctx, __u32 secctxlen)
601 {
602         struct inode             *inode = NULL;
603         __u64                     bits = 0;
604         int                       rc;
605         struct dentry *alias;
606         ENTRY;
607
608         /* NB 1 request reference will be taken away by ll_intent_lock()
609          * when I return */
610         CDEBUG(D_DENTRY, "it %p it_disposition %x\n", it,
611                it->it_disposition);
612         if (!it_disposition(it, DISP_LOOKUP_NEG)) {
613                 struct req_capsule *pill = &request->rq_pill;
614                 struct mdt_body *body = req_capsule_server_get(pill,
615                                                                &RMF_MDT_BODY);
616
617                 rc = ll_prep_inode(&inode, request, (*de)->d_sb, it);
618                 if (rc)
619                         RETURN(rc);
620
621                 if (it->it_op & IT_OPEN)
622                         ll_dom_finish_open(inode, request, it);
623
624                 ll_set_lock_data(ll_i2sbi(parent)->ll_md_exp, inode, it, &bits);
625
626                 /* We used to query real size from OSTs here, but actually
627                  * this is not needed. For stat() calls size would be updated
628                  * from subsequent do_revalidate()->ll_inode_revalidate_it() in
629                  * 2.4 and
630                  * vfs_getattr_it->ll_getattr()->ll_inode_revalidate_it() in 2.6
631                  * Everybody else who needs correct file size would call
632                  * ll_glimpse_size or some equivalent themselves anyway.
633                  * Also see bug 7198.
634                  */
635
636                 /* If security context was returned by MDT, put it in
637                  * inode now to save an extra getxattr from security hooks,
638                  * and avoid deadlock.
639                  */
640                 if (body->mbo_valid & OBD_MD_SECCTX) {
641                         secctx = req_capsule_server_get(pill, &RMF_FILE_SECCTX);
642                         secctxlen = req_capsule_get_size(pill,
643                                                            &RMF_FILE_SECCTX,
644                                                            RCL_SERVER);
645
646                         if (secctxlen)
647                                 CDEBUG(D_SEC, "server returned security context"
648                                        " for "DFID"\n",
649                                        PFID(ll_inode2fid(inode)));
650                 }
651
652                 if (secctx != NULL && secctxlen != 0) {
653                         inode_lock(inode);
654                         rc = security_inode_notifysecctx(inode, secctx,
655                                                          secctxlen);
656                         inode_unlock(inode);
657                         if (rc)
658                                 CWARN("cannot set security context for "
659                                       DFID": rc = %d\n",
660                                       PFID(ll_inode2fid(inode)), rc);
661                 }
662         }
663
664         /* Only hash *de if it is unhashed (new dentry).
665          * Atoimc_open may passin hashed dentries for open.
666          */
667         alias = ll_splice_alias(inode, *de);
668         if (IS_ERR(alias))
669                 GOTO(out, rc = PTR_ERR(alias));
670
671         *de = alias;
672
673         if (!it_disposition(it, DISP_LOOKUP_NEG)) {
674                 /* we have lookup look - unhide dentry */
675                 if (bits & MDS_INODELOCK_LOOKUP)
676                         d_lustre_revalidate(*de);
677         } else if (!it_disposition(it, DISP_OPEN_CREATE)) {
678                 /*
679                  * If file was created on the server, the dentry is revalidated
680                  * in ll_create_it if the lock allows for it.
681                  */
682                 /* Check that parent has UPDATE lock. */
683                 struct lookup_intent parent_it = {
684                                         .it_op = IT_GETATTR,
685                                         .it_lock_handle = 0 };
686                 struct lu_fid   fid = ll_i2info(parent)->lli_fid;
687
688                 /* If it is striped directory, get the real stripe parent */
689                 if (unlikely(ll_dir_striped(parent))) {
690                         rc = md_get_fid_from_lsm(ll_i2mdexp(parent),
691                                                  ll_i2info(parent)->lli_lsm_md,
692                                                  (*de)->d_name.name,
693                                                  (*de)->d_name.len, &fid);
694                         if (rc != 0)
695                                 GOTO(out, rc);
696                 }
697
698                 if (md_revalidate_lock(ll_i2mdexp(parent), &parent_it, &fid,
699                                        NULL)) {
700                         d_lustre_revalidate(*de);
701                         ll_intent_release(&parent_it);
702                 }
703         }
704
705         GOTO(out, rc = 0);
706
707 out:
708         if (rc != 0 && it->it_op & IT_OPEN)
709                 ll_open_cleanup((*de)->d_sb, request);
710
711         return rc;
712 }
713
714 struct pcc_create_attach {
715         struct pcc_dataset *pca_dataset;
716         struct dentry *pca_dentry;
717 };
718
719 static struct dentry *ll_lookup_it(struct inode *parent, struct dentry *dentry,
720                                    struct lookup_intent *it,
721                                    void **secctx, __u32 *secctxlen,
722                                    struct pcc_create_attach *pca)
723 {
724         struct lookup_intent lookup_it = { .it_op = IT_LOOKUP };
725         struct dentry *save = dentry, *retval;
726         struct ptlrpc_request *req = NULL;
727         struct md_op_data *op_data = NULL;
728         struct lov_user_md *lum = NULL;
729         __u32 opc;
730         int rc;
731         char secctx_name[XATTR_NAME_MAX + 1];
732
733         ENTRY;
734
735         if (dentry->d_name.len > ll_i2sbi(parent)->ll_namelen)
736                 RETURN(ERR_PTR(-ENAMETOOLONG));
737
738         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), intent=%s\n",
739                dentry->d_name.len, dentry->d_name.name,
740                PFID(ll_inode2fid(parent)), parent, LL_IT2STR(it));
741
742         if (d_mountpoint(dentry))
743                 CERROR("Tell Peter, lookup on mtpt, it %s\n", LL_IT2STR(it));
744
745         if (it == NULL || it->it_op == IT_GETXATTR)
746                 it = &lookup_it;
747
748         if (it->it_op == IT_GETATTR && dentry_may_statahead(parent, dentry)) {
749                 rc = ll_statahead(parent, &dentry, 0);
750                 if (rc == 1)
751                         RETURN(dentry == save ? NULL : dentry);
752         }
753
754         if (it->it_op & IT_OPEN && it->it_flags & FMODE_WRITE &&
755             dentry->d_sb->s_flags & SB_RDONLY)
756                 RETURN(ERR_PTR(-EROFS));
757
758         if (it->it_op & IT_CREAT)
759                 opc = LUSTRE_OPC_CREATE;
760         else
761                 opc = LUSTRE_OPC_ANY;
762
763         op_data = ll_prep_md_op_data(NULL, parent, NULL, dentry->d_name.name,
764                                      dentry->d_name.len, 0, opc, NULL);
765         if (IS_ERR(op_data))
766                 GOTO(out, retval = ERR_CAST(op_data));
767
768         /* enforce umask if acl disabled or MDS doesn't support umask */
769         if (!IS_POSIXACL(parent) || !exp_connect_umask(ll_i2mdexp(parent)))
770                 it->it_create_mode &= ~current_umask();
771
772         if (it->it_op & IT_CREAT &&
773             ll_i2sbi(parent)->ll_flags & LL_SBI_FILE_SECCTX) {
774                 rc = ll_dentry_init_security(dentry, it->it_create_mode,
775                                              &dentry->d_name,
776                                              &op_data->op_file_secctx_name,
777                                              &op_data->op_file_secctx,
778                                              &op_data->op_file_secctx_size);
779                 if (rc < 0)
780                         GOTO(out, retval = ERR_PTR(rc));
781                 if (secctx != NULL)
782                         *secctx = op_data->op_file_secctx;
783                 if (secctxlen != NULL)
784                         *secctxlen = op_data->op_file_secctx_size;
785         } else {
786                 if (secctx != NULL)
787                         *secctx = NULL;
788                 if (secctxlen != NULL)
789                         *secctxlen = 0;
790         }
791
792         /* ask for security context upon intent */
793         if (it->it_op & (IT_LOOKUP | IT_GETATTR | IT_OPEN)) {
794                 /* get name of security xattr to request to server */
795                 rc = ll_listsecurity(parent, secctx_name,
796                                      sizeof(secctx_name));
797                 if (rc < 0) {
798                         CDEBUG(D_SEC, "cannot get security xattr name for "
799                                DFID": rc = %d\n",
800                                PFID(ll_inode2fid(parent)), rc);
801                 } else if (rc > 0) {
802                         op_data->op_file_secctx_name = secctx_name;
803                         op_data->op_file_secctx_name_size = rc;
804                         CDEBUG(D_SEC, "'%.*s' is security xattr for "DFID"\n",
805                                rc, secctx_name, PFID(ll_inode2fid(parent)));
806                 }
807         }
808
809         if (pca && pca->pca_dataset) {
810                 struct pcc_dataset *dataset = pca->pca_dataset;
811
812                 OBD_ALLOC_PTR(lum);
813                 if (lum == NULL)
814                         GOTO(out, retval = ERR_PTR(-ENOMEM));
815
816                 lum->lmm_magic = LOV_USER_MAGIC_V1;
817                 lum->lmm_pattern = LOV_PATTERN_F_RELEASED | LOV_PATTERN_RAID0;
818                 op_data->op_data = lum;
819                 op_data->op_data_size = sizeof(*lum);
820                 op_data->op_archive_id = dataset->pccd_rwid;
821
822                 rc = obd_fid_alloc(NULL, ll_i2mdexp(parent), &op_data->op_fid2,
823                                    op_data);
824                 if (rc)
825                         GOTO(out, retval = ERR_PTR(rc));
826
827                 rc = pcc_inode_create(parent->i_sb, dataset, &op_data->op_fid2,
828                                       &pca->pca_dentry);
829                 if (rc)
830                         GOTO(out, retval = ERR_PTR(rc));
831
832                 it->it_flags |= MDS_OPEN_PCC;
833         }
834
835         rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
836                             &ll_md_blocking_ast, 0);
837         /* If the MDS allows the client to chgrp (CFS_SETGRP_PERM), but the
838          * client does not know which suppgid should be sent to the MDS, or
839          * some other(s) changed the target file's GID after this RPC sent
840          * to the MDS with the suppgid as the original GID, then we should
841          * try again with right suppgid. */
842         if (rc == -EACCES && it->it_op & IT_OPEN &&
843             it_disposition(it, DISP_OPEN_DENY)) {
844                 struct mdt_body *body;
845
846                 LASSERT(req != NULL);
847
848                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
849                 if (op_data->op_suppgids[0] == body->mbo_gid ||
850                     op_data->op_suppgids[1] == body->mbo_gid ||
851                     !in_group_p(make_kgid(&init_user_ns, body->mbo_gid)))
852                         GOTO(out, retval = ERR_PTR(-EACCES));
853
854                 fid_zero(&op_data->op_fid2);
855                 op_data->op_suppgids[1] = body->mbo_gid;
856                 ptlrpc_req_finished(req);
857                 req = NULL;
858                 ll_intent_release(it);
859                 rc = md_intent_lock(ll_i2mdexp(parent), op_data, it, &req,
860                                     &ll_md_blocking_ast, 0);
861         }
862
863         if (rc < 0)
864                 GOTO(out, retval = ERR_PTR(rc));
865
866         /* dir layout may change */
867         ll_unlock_md_op_lsm(op_data);
868         rc = ll_lookup_it_finish(req, it, parent, &dentry,
869                                  secctx != NULL ? *secctx : NULL,
870                                  secctxlen != NULL ? *secctxlen : 0);
871         if (rc != 0) {
872                 ll_intent_release(it);
873                 GOTO(out, retval = ERR_PTR(rc));
874         }
875
876         if ((it->it_op & IT_OPEN) && dentry->d_inode &&
877             !S_ISREG(dentry->d_inode->i_mode) &&
878             !S_ISDIR(dentry->d_inode->i_mode)) {
879                 ll_release_openhandle(dentry, it);
880         }
881         ll_lookup_finish_locks(it, dentry);
882
883         GOTO(out, retval = (dentry == save) ? NULL : dentry);
884
885 out:
886         if (op_data != NULL && !IS_ERR(op_data)) {
887                 if (secctx != NULL && secctxlen != NULL) {
888                         /* caller needs sec ctx info, so reset it in op_data to
889                          * prevent it from being freed */
890                         op_data->op_file_secctx = NULL;
891                         op_data->op_file_secctx_size = 0;
892                 }
893                 ll_finish_md_op_data(op_data);
894         }
895
896         if (lum != NULL)
897                 OBD_FREE_PTR(lum);
898
899         ptlrpc_req_finished(req);
900         return retval;
901 }
902
903 #ifdef HAVE_IOP_ATOMIC_OPEN
904 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
905                                    unsigned int flags)
906 {
907         struct lookup_intent *itp, it = { .it_op = IT_GETATTR };
908         struct dentry *de;
909
910         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), flags=%u\n",
911                dentry->d_name.len, dentry->d_name.name,
912                PFID(ll_inode2fid(parent)), parent, flags);
913
914         /*
915          * Optimize away (CREATE && !OPEN). Let .create handle the race.
916          * but only if we have write permissions there, otherwise we need
917          * to proceed with lookup. LU-4185
918          */
919         if ((flags & LOOKUP_CREATE) && !(flags & LOOKUP_OPEN) &&
920             (inode_permission(parent, MAY_WRITE | MAY_EXEC) == 0))
921                 return NULL;
922
923         if (flags & (LOOKUP_PARENT|LOOKUP_OPEN|LOOKUP_CREATE))
924                 itp = NULL;
925         else
926                 itp = &it;
927         de = ll_lookup_it(parent, dentry, itp, NULL, NULL, NULL);
928
929         if (itp != NULL)
930                 ll_intent_release(itp);
931
932         return de;
933 }
934
935 #ifdef FMODE_CREATED /* added in Linux v4.18-rc1-20-g73a09dd */
936 # define ll_is_opened(o, f)             ((f)->f_mode & FMODE_OPENED)
937 # define ll_finish_open(f, d, o)        finish_open((f), (d), NULL)
938 # define ll_last_arg
939 # define ll_set_created(o, f)                                           \
940 do {                                                                    \
941         (f)->f_mode |= FMODE_CREATED;                                   \
942 } while (0)
943
944 #else
945 # define ll_is_opened(o, f)             (*(o))
946 # define ll_finish_open(f, d, o)        finish_open((f), (d), NULL, (o))
947 # define ll_last_arg                    , int *opened
948 # define ll_set_created(o, f)                                           \
949 do {                                                                    \
950         *(o) |= FILE_CREATED;                                           \
951 } while (0)
952
953 #endif
954
955 /*
956  * For cached negative dentry and new dentry, handle lookup/create/open
957  * together.
958  */
959 static int ll_atomic_open(struct inode *dir, struct dentry *dentry,
960                           struct file *file, unsigned open_flags,
961                           umode_t mode ll_last_arg)
962 {
963         struct lookup_intent *it;
964         struct dentry *de;
965         long long lookup_flags = LOOKUP_OPEN;
966         void *secctx = NULL;
967         __u32 secctxlen = 0;
968         struct ll_sb_info *sbi;
969         struct pcc_create_attach pca = {NULL, NULL};
970         struct pcc_dataset *dataset = NULL;
971         int rc = 0;
972         ENTRY;
973
974         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), file %p,"
975                            "open_flags %x, mode %x opened %d\n",
976                dentry->d_name.len, dentry->d_name.name,
977                PFID(ll_inode2fid(dir)), dir, file, open_flags, mode,
978                ll_is_opened(opened, file));
979
980         /* Only negative dentries enter here */
981         LASSERT(dentry->d_inode == NULL);
982
983         if (!d_unhashed(dentry)) {
984                 /* A valid negative dentry that just passed revalidation,
985                  * there's little point to try and open it server-side,
986                  * even though there's a minuscule chance it might succeed.
987                  * Either way it's a valid race to just return -ENOENT here.
988                  */
989                 if (!(open_flags & O_CREAT))
990                         return -ENOENT;
991
992                 /* Otherwise we just unhash it to be rehashed afresh via
993                  * lookup if necessary
994                  */
995                 d_drop(dentry);
996         }
997
998         OBD_ALLOC(it, sizeof(*it));
999         if (!it)
1000                 RETURN(-ENOMEM);
1001
1002         it->it_op = IT_OPEN;
1003         if (open_flags & O_CREAT) {
1004                 it->it_op |= IT_CREAT;
1005                 lookup_flags |= LOOKUP_CREATE;
1006                 sbi = ll_i2sbi(dir);
1007                 /* Volatile file is used for HSM restore, so do not use PCC */
1008                 if (!filename_is_volatile(dentry->d_name.name,
1009                                           dentry->d_name.len, NULL)) {
1010                         struct pcc_matcher item;
1011
1012                         item.pm_uid = from_kuid(&init_user_ns, current_uid());
1013                         item.pm_gid = from_kgid(&init_user_ns, current_gid());
1014                         item.pm_projid = ll_i2info(dir)->lli_projid;
1015                         item.pm_name = &dentry->d_name;
1016                         dataset = pcc_dataset_match_get(&sbi->ll_pcc_super,
1017                                                         &item);
1018                         pca.pca_dataset = dataset;
1019                 }
1020         }
1021         it->it_create_mode = (mode & S_IALLUGO) | S_IFREG;
1022         it->it_flags = (open_flags & ~O_ACCMODE) | OPEN_FMODE(open_flags);
1023         it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
1024
1025         /* Dentry added to dcache tree in ll_lookup_it */
1026         de = ll_lookup_it(dir, dentry, it, &secctx, &secctxlen, &pca);
1027         if (IS_ERR(de))
1028                 rc = PTR_ERR(de);
1029         else if (de != NULL)
1030                 dentry = de;
1031
1032         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_FILE_PAUSE, cfs_fail_val);
1033
1034         if (!rc) {
1035                 if (it_disposition(it, DISP_OPEN_CREATE)) {
1036                         /* Dentry instantiated in ll_create_it. */
1037                         rc = ll_create_it(dir, dentry, it, secctx, secctxlen);
1038                         security_release_secctx(secctx, secctxlen);
1039                         if (rc) {
1040                                 /* We dget in ll_splice_alias. */
1041                                 if (de != NULL)
1042                                         dput(de);
1043                                 goto out_release;
1044                         }
1045                         if (dataset != NULL && dentry->d_inode) {
1046                                 rc = pcc_inode_create_fini(dataset,
1047                                                            dentry->d_inode,
1048                                                            pca.pca_dentry);
1049                                 if (rc) {
1050                                         if (de != NULL)
1051                                                 dput(de);
1052                                         GOTO(out_release, rc);
1053                                 }
1054                         }
1055                         ll_set_created(opened, file);
1056                 }
1057
1058                 if (dentry->d_inode && it_disposition(it, DISP_OPEN_OPEN)) {
1059                         /* Open dentry. */
1060                         if (S_ISFIFO(dentry->d_inode->i_mode)) {
1061                                 /* We cannot call open here as it might
1062                                  * deadlock. This case is unreachable in
1063                                  * practice because of OBD_CONNECT_NODEVOH. */
1064                                 rc = finish_no_open(file, de);
1065                         } else {
1066                                 file->private_data = it;
1067                                 rc = ll_finish_open(file, dentry, opened);
1068                                 /* We dget in ll_splice_alias. finish_open takes
1069                                  * care of dget for fd open.
1070                                  */
1071                                 if (de != NULL)
1072                                         dput(de);
1073                         }
1074                 } else {
1075                         rc = finish_no_open(file, de);
1076                 }
1077         }
1078
1079 out_release:
1080         if (dataset != NULL)
1081                 pcc_dataset_put(dataset);
1082         ll_intent_release(it);
1083         OBD_FREE(it, sizeof(*it));
1084
1085         RETURN(rc);
1086 }
1087
1088 #else /* !HAVE_IOP_ATOMIC_OPEN */
1089 static struct lookup_intent *
1090 ll_convert_intent(struct open_intent *oit, int lookup_flags, bool is_readonly)
1091 {
1092         struct lookup_intent *it;
1093
1094         OBD_ALLOC_PTR(it);
1095         if (!it)
1096                 return ERR_PTR(-ENOMEM);
1097
1098         if (lookup_flags & LOOKUP_OPEN) {
1099                 it->it_op = IT_OPEN;
1100                 /* Avoid file creation for ro bind mount point(is_readonly) */
1101                 if ((lookup_flags & LOOKUP_CREATE) && !is_readonly)
1102                         it->it_op |= IT_CREAT;
1103                 it->it_create_mode = (oit->create_mode & S_IALLUGO) | S_IFREG;
1104                 it->it_flags = ll_namei_to_lookup_intent_flag(oit->flags &
1105                                                 ~(is_readonly ? O_CREAT : 0));
1106                 it->it_flags &= ~MDS_OPEN_FL_INTERNAL;
1107         } else {
1108                 it->it_op = IT_GETATTR;
1109         }
1110
1111         return it;
1112 }
1113
1114 static struct dentry *ll_lookup_nd(struct inode *parent, struct dentry *dentry,
1115                                    struct nameidata *nd)
1116 {
1117         struct dentry *de;
1118         ENTRY;
1119
1120         if (nd && !(nd->flags & (LOOKUP_CONTINUE|LOOKUP_PARENT))) {
1121                 struct lookup_intent *it;
1122
1123                 if (ll_d2d(dentry) && ll_d2d(dentry)->lld_it) {
1124                         it = ll_d2d(dentry)->lld_it;
1125                         ll_d2d(dentry)->lld_it = NULL;
1126                 } else {
1127                         /*
1128                          * Optimize away (CREATE && !OPEN). Let .create handle
1129                          * the race. But only if we have write permissions
1130                          * there, otherwise we need to proceed with lookup.
1131                          * LU-4185
1132                          */
1133                         if ((nd->flags & LOOKUP_CREATE) &&
1134                             !(nd->flags & LOOKUP_OPEN) &&
1135                             (inode_permission(parent,
1136                                               MAY_WRITE | MAY_EXEC) == 0))
1137                                 RETURN(NULL);
1138
1139                         it = ll_convert_intent(&nd->intent.open, nd->flags,
1140                                 (nd->path.mnt->mnt_flags & MNT_READONLY) ||
1141                                 (nd->path.mnt->mnt_sb->s_flags & SB_RDONLY));
1142                         if (IS_ERR(it))
1143                                 RETURN((struct dentry *)it);
1144                 }
1145
1146                 de = ll_lookup_it(parent, dentry, it, NULL, NULL, NULL);
1147                 if (de)
1148                         dentry = de;
1149                 if ((nd->flags & LOOKUP_OPEN) && !IS_ERR(dentry)) { /* Open */
1150                         if (dentry->d_inode &&
1151                             it_disposition(it, DISP_OPEN_OPEN)) { /* nocreate */
1152                                 if (S_ISFIFO(dentry->d_inode->i_mode)) {
1153                                         /* We cannot call open here as it might
1154                                          * deadlock. This case is unreachable in
1155                                          * practice because of
1156                                          * OBD_CONNECT_NODEVOH. */
1157                                 } else {
1158                                         struct file *filp;
1159
1160                                         nd->intent.open.file->private_data = it;
1161                                         filp = lookup_instantiate_filp(nd,
1162                                                                        dentry,
1163                                                                        NULL);
1164                                         if (IS_ERR(filp)) {
1165                                                 if (de)
1166                                                         dput(de);
1167                                                 de = (struct dentry *)filp;
1168                                         }
1169                                 }
1170                         } else if (it_disposition(it, DISP_OPEN_CREATE)) {
1171                                 /* XXX This can only reliably work on assumption
1172                                  * that there are NO hashed negative dentries.*/
1173                                 ll_d2d(dentry)->lld_it = it;
1174                                 it = NULL; /* Will be freed in ll_create_nd */
1175                                 /* We absolutely depend on ll_create_nd to be
1176                                  * called to not leak this intent and possible
1177                                  * data attached to it */
1178                         }
1179                 }
1180
1181                 if (it) {
1182                         ll_intent_release(it);
1183                         OBD_FREE(it, sizeof(*it));
1184                 }
1185         } else {
1186                 de = ll_lookup_it(parent, dentry, NULL, NULL, NULL, NULL);
1187         }
1188
1189         RETURN(de);
1190 }
1191 #endif /* HAVE_IOP_ATOMIC_OPEN */
1192
1193 /* We depend on "mode" being set with the proper file type/umask by now */
1194 static struct inode *ll_create_node(struct inode *dir, struct lookup_intent *it)
1195 {
1196         struct inode *inode = NULL;
1197         struct ptlrpc_request *request = NULL;
1198         struct ll_sb_info *sbi = ll_i2sbi(dir);
1199         int rc;
1200         ENTRY;
1201
1202         LASSERT(it && it->it_disposition);
1203
1204         LASSERT(it_disposition(it, DISP_ENQ_CREATE_REF));
1205         request = it->it_request;
1206         it_clear_disposition(it, DISP_ENQ_CREATE_REF);
1207         rc = ll_prep_inode(&inode, request, dir->i_sb, it);
1208         if (rc)
1209                 GOTO(out, inode = ERR_PTR(rc));
1210
1211         /* Pause to allow for a race with concurrent access by fid */
1212         OBD_FAIL_TIMEOUT(OBD_FAIL_LLITE_CREATE_NODE_PAUSE, cfs_fail_val);
1213
1214         /* We asked for a lock on the directory, but were granted a
1215          * lock on the inode.  Since we finally have an inode pointer,
1216          * stuff it in the lock. */
1217         CDEBUG(D_DLMTRACE, "setting l_ast_data to inode "DFID"(%p)\n",
1218                PFID(ll_inode2fid(inode)), inode);
1219         ll_set_lock_data(sbi->ll_md_exp, inode, it, NULL);
1220         EXIT;
1221  out:
1222         ptlrpc_req_finished(request);
1223         return inode;
1224 }
1225
1226 /*
1227  * By the time this is called, we already have created the directory cache
1228  * entry for the new file, but it is so far negative - it has no inode.
1229  *
1230  * We defer creating the OBD object(s) until open, to keep the intent and
1231  * non-intent code paths similar, and also because we do not have the MDS
1232  * inode number before calling ll_create_node() (which is needed for LOV),
1233  * so we would need to do yet another RPC to the MDS to store the LOV EA
1234  * data on the MDS.  If needed, we would pass the PACKED lmm as data and
1235  * lmm_size in datalen (the MDS still has code which will handle that).
1236  *
1237  * If the create succeeds, we fill in the inode information
1238  * with d_instantiate().
1239  */
1240 static int ll_create_it(struct inode *dir, struct dentry *dentry,
1241                         struct lookup_intent *it,
1242                         void *secctx, __u32 secctxlen)
1243 {
1244         struct inode *inode;
1245         __u64 bits = 0;
1246         int rc = 0;
1247         ENTRY;
1248
1249         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p), intent=%s\n",
1250                dentry->d_name.len, dentry->d_name.name,
1251                PFID(ll_inode2fid(dir)), dir, LL_IT2STR(it));
1252
1253         rc = it_open_error(DISP_OPEN_CREATE, it);
1254         if (rc)
1255                 RETURN(rc);
1256
1257         inode = ll_create_node(dir, it);
1258         if (IS_ERR(inode))
1259                 RETURN(PTR_ERR(inode));
1260
1261         if ((ll_i2sbi(inode)->ll_flags & LL_SBI_FILE_SECCTX) &&
1262             secctx != NULL) {
1263                 inode_lock(inode);
1264                 /* must be done before d_instantiate, because it calls
1265                  * security_d_instantiate, which means a getxattr if security
1266                  * context is not set yet */
1267                 rc = security_inode_notifysecctx(inode, secctx, secctxlen);
1268                 inode_unlock(inode);
1269                 if (rc)
1270                         RETURN(rc);
1271         }
1272
1273         d_instantiate(dentry, inode);
1274
1275         if (!(ll_i2sbi(inode)->ll_flags & LL_SBI_FILE_SECCTX)) {
1276                 rc = ll_inode_init_security(dentry, inode, dir);
1277                 if (rc)
1278                         RETURN(rc);
1279         }
1280
1281         ll_set_lock_data(ll_i2sbi(dir)->ll_md_exp, inode, it, &bits);
1282         if (bits & MDS_INODELOCK_LOOKUP)
1283                 d_lustre_revalidate(dentry);
1284
1285         RETURN(0);
1286 }
1287
1288 void ll_update_times(struct ptlrpc_request *request, struct inode *inode)
1289 {
1290         struct mdt_body *body = req_capsule_server_get(&request->rq_pill,
1291                                                        &RMF_MDT_BODY);
1292
1293         LASSERT(body);
1294         if (body->mbo_valid & OBD_MD_FLMTIME &&
1295             body->mbo_mtime > inode->i_mtime.tv_sec) {
1296                 CDEBUG(D_INODE,
1297                        "setting fid " DFID " mtime from %lld to %llu\n",
1298                        PFID(ll_inode2fid(inode)),
1299                        (s64)inode->i_mtime.tv_sec, body->mbo_mtime);
1300                 inode->i_mtime.tv_sec = body->mbo_mtime;
1301         }
1302
1303         if (body->mbo_valid & OBD_MD_FLCTIME &&
1304             body->mbo_ctime > inode->i_ctime.tv_sec)
1305                 inode->i_ctime.tv_sec = body->mbo_ctime;
1306 }
1307
1308 static int ll_new_node(struct inode *dir, struct dentry *dchild,
1309                        const char *tgt, umode_t mode, int rdev, __u32 opc)
1310 {
1311         struct qstr *name = &dchild->d_name;
1312         struct ptlrpc_request *request = NULL;
1313         struct md_op_data *op_data;
1314         struct inode *inode = NULL;
1315         struct ll_sb_info *sbi = ll_i2sbi(dir);
1316         int tgt_len = 0;
1317         int err;
1318
1319         ENTRY;
1320         if (unlikely(tgt != NULL))
1321                 tgt_len = strlen(tgt) + 1;
1322
1323 again:
1324         op_data = ll_prep_md_op_data(NULL, dir, NULL, name->name,
1325                                      name->len, 0, opc, NULL);
1326         if (IS_ERR(op_data))
1327                 GOTO(err_exit, err = PTR_ERR(op_data));
1328
1329         if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
1330                 err = ll_dentry_init_security(dchild, mode, &dchild->d_name,
1331                                               &op_data->op_file_secctx_name,
1332                                               &op_data->op_file_secctx,
1333                                               &op_data->op_file_secctx_size);
1334                 if (err < 0)
1335                         GOTO(err_exit, err);
1336         }
1337
1338         err = md_create(sbi->ll_md_exp, op_data, tgt, tgt_len, mode,
1339                         from_kuid(&init_user_ns, current_fsuid()),
1340                         from_kgid(&init_user_ns, current_fsgid()),
1341                         cfs_curproc_cap_pack(), rdev, &request);
1342 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 14, 58, 0)
1343         /*
1344          * server < 2.12.58 doesn't pack default LMV in intent_getattr reply,
1345          * fetch default LMV here.
1346          */
1347         if (unlikely(err == -EREMOTE)) {
1348                 struct ll_inode_info    *lli = ll_i2info(dir);
1349                 struct lmv_user_md      *lum;
1350                 int                     lumsize;
1351                 int                     err2;
1352
1353                 ptlrpc_req_finished(request);
1354                 request = NULL;
1355
1356                 err2 = ll_dir_getstripe(dir, (void **)&lum, &lumsize, &request,
1357                                         OBD_MD_DEFAULT_MEA);
1358                 ll_finish_md_op_data(op_data);
1359                 op_data = NULL;
1360                 if (err2 == 0) {
1361                         struct lustre_md md = { NULL };
1362
1363                         md.body = req_capsule_server_get(&request->rq_pill,
1364                                                          &RMF_MDT_BODY);
1365                         if (!md.body)
1366                                 GOTO(err_exit, err = -EPROTO);
1367
1368                         OBD_ALLOC_PTR(md.default_lmv);
1369                         if (!md.default_lmv)
1370                                 GOTO(err_exit, err = -ENOMEM);
1371
1372                         md.default_lmv->lsm_md_magic = lum->lum_magic;
1373                         md.default_lmv->lsm_md_stripe_count =
1374                                 lum->lum_stripe_count;
1375                         md.default_lmv->lsm_md_master_mdt_index =
1376                                 lum->lum_stripe_offset;
1377                         md.default_lmv->lsm_md_hash_type = lum->lum_hash_type;
1378
1379                         err = ll_update_inode(dir, &md);
1380                         md_free_lustre_md(sbi->ll_md_exp, &md);
1381                         if (err)
1382                                 GOTO(err_exit, err);
1383                 } else if (err2 == -ENODATA && lli->lli_default_lsm_md) {
1384                         /*
1385                          * If there are no default stripe EA on the MDT, but the
1386                          * client has default stripe, then it probably means
1387                          * default stripe EA has just been deleted.
1388                          */
1389                         down_write(&lli->lli_lsm_sem);
1390                         if (lli->lli_default_lsm_md)
1391                                 OBD_FREE_PTR(lli->lli_default_lsm_md);
1392                         lli->lli_default_lsm_md = NULL;
1393                         up_write(&lli->lli_lsm_sem);
1394                 } else {
1395                         GOTO(err_exit, err);
1396                 }
1397
1398                 ptlrpc_req_finished(request);
1399                 request = NULL;
1400                 goto again;
1401         }
1402 #endif
1403
1404         if (err < 0)
1405                 GOTO(err_exit, err);
1406
1407         ll_update_times(request, dir);
1408
1409         CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_NEWNODE_PAUSE, cfs_fail_val);
1410
1411         err = ll_prep_inode(&inode, request, dchild->d_sb, NULL);
1412         if (err)
1413                 GOTO(err_exit, err);
1414
1415         if (sbi->ll_flags & LL_SBI_FILE_SECCTX) {
1416                 inode_lock(inode);
1417                 /* must be done before d_instantiate, because it calls
1418                  * security_d_instantiate, which means a getxattr if security
1419                  * context is not set yet */
1420                 err = security_inode_notifysecctx(inode,
1421                                                   op_data->op_file_secctx,
1422                                                   op_data->op_file_secctx_size);
1423                 inode_unlock(inode);
1424                 if (err)
1425                         GOTO(err_exit, err);
1426         }
1427
1428         d_instantiate(dchild, inode);
1429
1430         if (!(sbi->ll_flags & LL_SBI_FILE_SECCTX)) {
1431                 err = ll_inode_init_security(dchild, inode, dir);
1432                 if (err)
1433                         GOTO(err_exit, err);
1434         }
1435
1436         EXIT;
1437 err_exit:
1438         if (request != NULL)
1439                 ptlrpc_req_finished(request);
1440
1441         if (!IS_ERR_OR_NULL(op_data))
1442                 ll_finish_md_op_data(op_data);
1443
1444         return err;
1445 }
1446
1447 static int ll_mknod(struct inode *dir, struct dentry *dchild, ll_umode_t mode,
1448                     dev_t rdev)
1449 {
1450         struct qstr *name = &dchild->d_name;
1451         int err;
1452         ENTRY;
1453
1454         CDEBUG(D_VFSTRACE, "VFS Op:name=%.*s, dir="DFID"(%p) mode %o dev %x\n",
1455                name->len, name->name, PFID(ll_inode2fid(dir)), dir,
1456                mode, rdev);
1457
1458         if (!IS_POSIXACL(dir) || !exp_connect_umask(ll_i2mdexp(dir)))
1459                 mode &= ~current_umask();
1460
1461         switch (mode & S_IFMT) {
1462         case 0:
1463                 mode |= S_IFREG; /* for mode = 0 case, 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 };