Whamcloud - gitweb
ce919b718df8a1373e1a6aaee2e4931ce7ad0b32
[fs/lustre-release.git] / lustre / llite / llite_lib.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Lustre Light Super operations
5  *
6  *  Copyright (c) 2002, 2003 Cluster File Systems, Inc.
7  *
8  *   This file is part of Lustre, http://www.lustre.org.
9  *
10  *   Lustre is free software; you can redistribute it and/or
11  *   modify it under the terms of version 2 of the GNU General Public
12  *   License as published by the Free Software Foundation.
13  *
14  *   Lustre is distributed in the hope that it will be useful,
15  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *   GNU General Public License for more details.
18  *
19  *   You should have received a copy of the GNU General Public License
20  *   along with Lustre; if not, write to the Free Software
21  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  */
23
24 #define DEBUG_SUBSYSTEM S_LLITE
25
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/random.h>
29 #include <linux/version.h>
30 #include <linux/seq_file.h>
31
32 #include <linux/lustre_lite.h>
33 #include <linux/lustre_ha.h>
34 #include <linux/lustre_dlm.h>
35 #include <linux/lprocfs_status.h>
36 #include <linux/lustre_acl.h>
37 #include <linux/lustre_gs.h>
38 #include <linux/lustre_sec.h>
39 #include "llite_internal.h"
40
41 kmem_cache_t *ll_file_data_slab;
42 kmem_cache_t *ll_intent_slab;
43
44 extern struct address_space_operations ll_aops;
45 extern struct address_space_operations ll_dir_aops;
46
47 #ifndef log2
48 #define log2(n) ffz(~(n))
49 #endif
50
51 struct ll_sb_info *lustre_init_sbi(struct super_block *sb)
52 {
53         struct ll_sb_info *sbi = NULL;
54         class_uuid_t uuid;
55         ENTRY;
56
57         OBD_ALLOC(sbi, sizeof(*sbi));
58         if (!sbi)
59                 RETURN(NULL);
60
61         spin_lock_init(&sbi->ll_lock);
62         INIT_LIST_HEAD(&sbi->ll_pglist);
63         sbi->ll_pglist_gen = 0;
64         if (num_physpages < SBI_DEFAULT_RA_MAX / 4)
65                 sbi->ll_ra_info.ra_max_pages = num_physpages / 4;
66         else
67                 sbi->ll_ra_info.ra_max_pages = SBI_DEFAULT_RA_MAX;
68         INIT_LIST_HEAD(&sbi->ll_conn_chain);
69         INIT_HLIST_HEAD(&sbi->ll_orphan_dentry_list);
70         INIT_LIST_HEAD(&sbi->ll_mnt_list);
71         
72         sema_init(&sbi->ll_gns_sem, 1);
73         spin_lock_init(&sbi->ll_gns_lock);
74         INIT_LIST_HEAD(&sbi->ll_gns_sbi_head);
75         init_waitqueue_head(&sbi->ll_gns_waitq);
76         init_completion(&sbi->ll_gns_mount_finished);
77
78         /* this later may be reset via /proc/fs/... */
79         memcpy(sbi->ll_gns_oname, ".mntinfo", strlen(".mntinfo"));
80         sbi->ll_gns_oname[strlen(sbi->ll_gns_oname)] = '\0';
81         
82         /* this later may be reset via /proc/fs/... */
83         memcpy(sbi->ll_gns_upcall, "/usr/sbin/gns_upcall",
84                strlen("/usr/sbin/gns_upcall"));
85         sbi->ll_gns_upcall[strlen(sbi->ll_gns_upcall)] = '\0';
86
87         /* default values, may be changed via /proc/fs/... */
88         sbi->ll_gns_state = LL_GNS_IDLE;
89         sbi->ll_gns_pending_dentry = NULL;
90         atomic_set(&sbi->ll_gns_enabled, 1);
91         sbi->ll_gns_tick = GNS_TICK_TIMEOUT;
92         sbi->ll_gns_timeout = GNS_MOUNT_TIMEOUT;
93
94         sbi->ll_gns_timer.data = (unsigned long)sbi;
95         sbi->ll_gns_timer.function = ll_gns_timer_callback;
96         init_timer(&sbi->ll_gns_timer);
97
98         ll_set_sbi(sb, sbi);
99
100         generate_random_uuid(uuid);
101         class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
102         RETURN(sbi);
103 }
104
105 void lustre_free_sbi(struct super_block *sb)
106 {
107         struct ll_sb_info *sbi = ll_s2sbi(sb);
108         ENTRY;
109
110         if (sbi != NULL) {
111                 list_del(&sbi->ll_gns_sbi_head);
112                 del_timer(&sbi->ll_gns_timer);
113                 OBD_FREE(sbi, sizeof(*sbi));
114         }
115         ll_set_sbi(sb, NULL);
116         EXIT;
117 }
118
119 int lustre_init_dt_desc(struct ll_sb_info *sbi)
120 {
121         __u32 valsize;
122         int rc = 0;
123         ENTRY;
124         
125         valsize = sizeof(sbi->ll_dt_desc);
126         memset(&sbi->ll_dt_desc, 0, sizeof(sbi->ll_dt_desc));
127         rc = obd_get_info(sbi->ll_dt_exp, strlen("lovdesc") + 1,
128                           "lovdesc", &valsize, &sbi->ll_dt_desc);
129         RETURN(rc);
130 }
131
132 static int lustre_connect_mds(struct super_block *sb, char *lmv,
133                               struct obd_connect_data *data,
134                               char *mds_security, int async, int pag)
135 {
136         struct ll_sb_info *sbi = ll_s2sbi(sb);
137         struct lustre_handle md_conn = {0, };
138         struct obd_device *md_obd;
139         struct obd_statfs osfs;
140         unsigned long sec_flags;
141         __u32 valsize;
142         int    err = 0;
143         ENTRY;       
144  
145         md_obd = class_name2obd(lmv);
146         if (!md_obd) {
147                 CERROR("MDC %s: not setup or attached\n", lmv);
148                 RETURN(-EINVAL);
149         }
150
151         obd_set_info(md_obd->obd_self_export, strlen("async"), "async",
152                      sizeof(async), &async);
153
154         err = obd_set_info(md_obd->obd_self_export, strlen("sec"), "sec",
155                            strlen(mds_security), mds_security);
156         
157         if (err) {
158                 CERROR("LMV %s: failed to set security %s, err %d\n",
159                         lmv, mds_security, err);
160                 RETURN(err);
161         }
162
163         if (pag) {
164                 sec_flags = PTLRPC_SEC_FL_PAG;
165                 err = obd_set_info(md_obd->obd_self_export,
166                                    strlen("sec_flags"), "sec_flags",
167                                    sizeof(sec_flags), &sec_flags);
168                 if (err) {
169                         OBD_FREE(data, sizeof(*data));
170                         RETURN(err);
171                 }
172         }
173
174         err = obd_connect(&md_conn, md_obd, &sbi->ll_sb_uuid, data,
175                           OBD_OPT_REAL_CLIENT);
176         if (err == -EBUSY) {
177                 CERROR("An MDS (lmv %s) is performing recovery, of which this"
178                        " client is not a part.  Please wait for recovery to "
179                        "complete, abort, or time out.\n", lmv);
180                 GOTO(out, err);
181         } else if (err) {
182                 CERROR("cannot connect to %s: rc = %d\n", lmv, err);
183                 GOTO(out, err);
184         }
185
186         sbi->ll_md_exp = class_conn2export(&md_conn);
187        
188         err = obd_statfs(md_obd, &osfs, jiffies - HZ);
189         if (err)
190                 GOTO(out_disconnect, err);
191
192         if (!osfs.os_bsize) {
193                 CERROR("Invalid block size is detected.");
194                 GOTO(out_disconnect, err);
195         }
196
197         sb->s_magic = LL_SUPER_MAGIC;
198         sb->s_blocksize = osfs.os_bsize;
199         sb->s_blocksize_bits = log2(osfs.os_bsize);
200         sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
201
202         /* in 2.6.x FS is not allowed to form s_dev */
203 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
204         {
205                 kdev_t devno;
206                 
207                 devno = get_uuid2int((char *)sbi->ll_md_exp->exp_obd->obd_uuid.uuid, 
208                                      strlen((char *)sbi->ll_md_exp->exp_obd->obd_uuid.uuid));
209                 
210                 sb->s_dev = devno;
211         }
212 #endif
213
214         /* after statfs, we are supposed to have connected to MDSs,
215          * so it's ok to check remote flag returned.
216          */
217         valsize = sizeof(&sbi->ll_remote);
218         err = obd_get_info(sbi->ll_md_exp, strlen("remote_flag"), "remote_flag",
219                            &valsize, &sbi->ll_remote);
220         if (err) {
221                 CERROR("fail to obtain remote flag\n");
222                 GOTO(out_disconnect, err);
223         }
224
225 out_disconnect:
226         if (err)
227                 obd_disconnect(sbi->ll_md_exp, 0);
228 out:
229         RETURN(err);
230 }
231 static int lustre_connect_ost(struct super_block *sb, char *lov, 
232                               struct obd_connect_data *data, 
233                               char *oss_security, int async, int pag)
234 {
235         struct ll_sb_info *sbi = ll_s2sbi(sb);
236         struct lustre_handle dt_conn = {0, };
237         struct obd_device *obd = NULL;
238         unsigned long sec_flags;
239         int err, mdsize; 
240
241         obd = class_name2obd(lov);
242         if (!obd) {
243                 CERROR("OSC %s: not setup or attached\n", lov);
244                 GOTO(out, err = -EINVAL);
245         }
246         obd_set_info(obd->obd_self_export, strlen("async"), "async",
247                      sizeof(async), &async);
248
249        if (oss_security == NULL)
250                 oss_security = "null";
251
252         err = obd_set_info(obd->obd_self_export, strlen("sec"), "sec",
253                            strlen(oss_security), oss_security);
254         if (err) {
255                 CERROR("LOV %s: failed to set security %s, err %d\n",
256                         lov, oss_security, err);
257                 RETURN(err);
258         }
259
260         if (pag) {
261                 sec_flags = PTLRPC_SEC_FL_PAG;
262                 err = obd_set_info(obd->obd_self_export,
263                                    strlen("sec_flags"), "sec_flags",
264                                    sizeof(sec_flags), &sec_flags);
265                 if (err) {
266                         OBD_FREE(data, sizeof(*data));
267                         RETURN(err);
268                 }
269         }
270
271         err = obd_connect(&dt_conn, obd, &sbi->ll_sb_uuid, data, 0);
272         if (err == -EBUSY) {
273                 CERROR("An OST (lov %s) is performing recovery, of which this"
274                        " client is not a part.  Please wait for recovery to "
275                        "complete, abort, or time out.\n", lov);
276                 GOTO(out, err);
277         } else if (err) {
278                 CERROR("cannot connect to %s: rc = %d\n", lov, err);
279                 GOTO(out, err);
280         }
281         sbi->ll_dt_exp = class_conn2export(&dt_conn);
282
283         err = lustre_init_dt_desc(sbi);
284        
285         if (err) {
286                 CWARN("init dt_desc error %d \n", err);
287                 GOTO(out, err = 0);
288         }
289         mdsize = obd_size_diskmd(sbi->ll_dt_exp, NULL);
290         obd_init_ea_size(sbi->ll_md_exp, mdsize, sbi->ll_dt_desc.ld_tgt_count *
291                          sizeof(struct llog_cookie));
292 out:
293         RETURN(err);
294 }
295
296 extern struct dentry_operations ll_d_ops;
297
298 static int lustre_init_root_inode(struct super_block *sb)
299 {
300         struct ll_sb_info *sbi = ll_s2sbi(sb);
301         struct ptlrpc_request *request = NULL;
302         struct inode *root = NULL;
303         struct lustre_md md;
304         int err = 0;
305         ENTRY;
306
307         err = md_getstatus(sbi->ll_md_exp, &sbi->ll_rootid);
308         if (err) {
309                 CERROR("cannot mds_connect: rc = %d\n", err);
310                 GOTO(out, err);
311         }
312         CDEBUG(D_SUPER, "rootid "DLID4"\n", OLID4(&sbi->ll_rootid));
313
314         sb->s_op = &lustre_super_operations;
315
316         /* make root inode */
317         err = md_getattr(sbi->ll_md_exp, &sbi->ll_rootid,
318                          (OBD_MD_FLNOTOBD | OBD_MD_FLBLOCKS | OBD_MD_FID),
319                          NULL, NULL, 0, 0, &request);
320         if (err) {
321                 CERROR("md_getattr failed for root: rc = %d\n", err);
322                 GOTO(out, err);
323         }
324
325         err = mdc_req2lustre_md(sbi->ll_md_exp, request, 0, 
326                                 sbi->ll_dt_exp, &md);
327         if (err) {
328                 CERROR("failed to understand root inode md: rc = %d\n", err);
329                 ptlrpc_req_finished(request);
330                 GOTO(out, err);
331         }
332
333         LASSERT(id_ino(&sbi->ll_rootid) != 0);
334         root = ll_iget(sb, id_ino(&sbi->ll_rootid), &md);
335
336         ptlrpc_req_finished(request);
337
338         if (root == NULL || is_bad_inode(root)) {
339                 if (md.lsm != NULL)
340                     obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
341                 if (md.mea != NULL)
342                     obd_free_memmd(sbi->ll_md_exp,
343                                    (struct lov_stripe_md**)&md.mea);
344                 CERROR("lustre_lite: bad iget4 for root\n");
345                 GOTO(out_root, err = -EBADF);
346         }
347         sb->s_root = d_alloc_root(root);
348         sb->s_root->d_op = &ll_d_ops;
349 out_root:
350         if (err)
351                 iput(root);
352 out:
353         RETURN(err);
354 }
355
356 int lustre_common_fill_super(struct super_block *sb, char *lmv, char *lov,
357                              char *gkc, int async,  char *mds_security,  
358                              char *oss_security, __u32 *nllu, int pag, 
359                              __u64 *remote)
360 {
361         struct ll_sb_info *sbi = ll_s2sbi(sb);
362         struct obd_connect_data *data;
363         int err;
364         ENTRY;
365
366         /*process the connect flags*/
367         if ((*remote & (OBD_CONNECT_LOCAL | OBD_CONNECT_REMOTE)) ==
368                        (OBD_CONNECT_LOCAL | OBD_CONNECT_REMOTE)) {
369                 CERROR("wrong remote flag "LPX64"\n", *remote);
370                 RETURN(-EINVAL);
371         }
372
373         OBD_ALLOC(data, sizeof(*data));
374         if (!data)
375                 RETURN(-ENOMEM);
376
377         data->ocd_connect_flags |= *remote & (OBD_CONNECT_LOCAL |
378                                               OBD_CONNECT_REMOTE);
379         memcpy(data->ocd_nllu, nllu, sizeof(data->ocd_nllu));
380
381         if (proc_lustre_fs_root) {
382                 err = lprocfs_register_mountpoint(proc_lustre_fs_root, 
383                                                   sb, lov, lmv);
384                 if (err < 0)
385                         CERROR("could not register mount in /proc/lustre");
386         }
387
388         /*connect mds */ 
389         err = lustre_connect_mds(sb, lmv, data, mds_security, async, pag);
390         if (err)
391                 GOTO(out, err);
392
393         /*connect OST*/
394         err = lustre_connect_ost(sb, lov, data, oss_security, async, pag);
395         if (err)
396                 GOTO(out_lmv, err);
397
398         err = lustre_init_crypto(sb, gkc, data, async);
399         if (err) {
400                 CERROR("Could not connect to GSS err %d\n", err);
401                 err = 0;
402         }
403         /*connect GSS*/
404         err = lustre_init_root_inode(sb);
405         if (err)
406                 GOTO(out_gks, err);
407
408         err = ll_close_thread_start(&sbi->ll_lcq);
409         if (err) {
410                 CERROR("cannot start close thread: rc %d\n", err);
411                 GOTO(out_root, err);
412         }
413
414         ll_gns_add_timer(sbi);
415
416         /* making vm readahead 0 for 2.4.x. In the case of 2.6.x,
417            backing dev info assigned to inode mapping is used for
418            determining maximal readahead. */
419 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) && \
420     !defined(KERNEL_HAS_AS_MAX_READAHEAD)
421         /* bug 2805 - set VM readahead to zero */
422         vm_max_readahead = vm_min_readahead = 0;
423 #endif
424         sb->s_flags |= MS_POSIXACL;
425 #ifdef S_PDIROPS
426         CWARN("Enabling PDIROPS\n");
427         sb->s_flags |= S_PDIROPS;
428 #endif
429         if (data != NULL)
430                 OBD_FREE(data, sizeof(*data));
431         RETURN(err);
432 out_root:
433         if (sb->s_root)
434                 dput(sb->s_root);
435 out_gks:
436         lustre_destroy_crypto(sb);
437 out_lmv:
438         obd_disconnect(sbi->ll_md_exp, 0);
439 out:
440         if (data != NULL)
441                 OBD_FREE(data, sizeof(*data));
442         lprocfs_unregister_mountpoint(sbi);
443         RETURN(err);
444 }
445
446 void lustre_common_put_super(struct super_block *sb)
447 {
448         struct ll_sb_info *sbi = ll_s2sbi(sb);
449         struct hlist_node *tmp, *next;
450         ENTRY;
451
452         ll_gns_del_timer(sbi);
453         ll_close_thread_shutdown(sbi->ll_lcq);
454
455         lustre_destroy_crypto(sb);
456
457         list_del(&sbi->ll_conn_chain);
458         obd_disconnect(sbi->ll_dt_exp, 0);
459
460         lprocfs_unregister_mountpoint(sbi);
461         if (sbi->ll_proc_root) {
462                 lprocfs_remove(sbi->ll_proc_root);
463                 sbi->ll_proc_root = NULL;
464         }
465
466         obd_disconnect(sbi->ll_md_exp, 0);
467
468         // We do this to get rid of orphaned dentries. That is not really trw.
469         hlist_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
470                 struct dentry *dentry = hlist_entry(tmp, struct dentry, d_hash);
471                 CWARN("orphan dentry %.*s (%p->%p) at unmount\n",
472                       dentry->d_name.len, dentry->d_name.name, dentry, next);
473                 shrink_dcache_parent(dentry);
474         }
475         EXIT;
476 }
477
478 char *ll_read_opt(const char *opt, char *data)
479 {
480         char *value;
481         char *retval;
482         ENTRY;
483
484         CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
485         if (strncmp(opt, data, strlen(opt)))
486                 RETURN(NULL);
487         if ((value = strchr(data, '=')) == NULL)
488                 RETURN(NULL);
489
490         value++;
491         OBD_ALLOC(retval, strlen(value) + 1);
492         if (!retval) {
493                 CERROR("out of memory!\n");
494                 RETURN(NULL);
495         }
496
497         memcpy(retval, value, strlen(value)+1);
498         CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
499         RETURN(retval);
500 }
501
502 int ll_set_opt(const char *opt, char *data, int fl)
503 {
504         ENTRY;
505
506         CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
507         if (strncmp(opt, data, strlen(opt)))
508                 RETURN(0);
509         else
510                 RETURN(fl);
511 }
512
513 void ll_options(char *options, char **lov, char **lmv, char **gkc,
514                 char **mds_sec, char **oss_sec, int *async, int *flags)
515 {
516         char *this_char;
517 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
518         char *opt_ptr = options;
519 #endif
520         ENTRY;
521
522         if (!options) {
523                 EXIT;
524                 return;
525         }
526
527         *async = 0;
528 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
529         for (this_char = strtok (options, ",");
530              this_char != NULL;
531              this_char = strtok (NULL, ",")) {
532 #else
533         while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
534 #endif
535                 CDEBUG(D_SUPER, "this_char %s\n", this_char);
536                 if (!*lov && (*lov = ll_read_opt("osc", this_char)))
537                         continue;
538                 if (!*lmv && (*lmv = ll_read_opt("mdc", this_char)))
539                         continue;
540                 if (!*gkc && (*gkc = ll_read_opt("gkc", this_char)))
541                         continue;
542                 if (!strncmp(this_char, "lasync", strlen("lasync"))) {
543                         *async = 1;
544                         continue;
545                 }
546                 if (!*mds_sec && (*mds_sec = ll_read_opt("mds_sec", this_char)))
547                         continue;
548                 if (!*oss_sec && (*oss_sec = ll_read_opt("oss_sec", this_char)))
549                         continue;
550                 if (!(*flags & LL_SBI_NOLCK) &&
551                     ((*flags) = (*flags) |
552                                 ll_set_opt("nolock", this_char,
553                                            LL_SBI_NOLCK)))
554                         continue;
555         }
556         
557         EXIT;
558 }
559
560 void ll_lli_init(struct ll_inode_info *lli)
561 {
562         sema_init(&lli->lli_open_sem, 1);
563         sema_init(&lli->lli_size_sem, 1);
564         lli->lli_flags = 0;
565         lli->lli_size_pid = 0;
566         lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
567         spin_lock_init(&lli->lli_lock);
568         INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
569         INIT_LIST_HEAD(&lli->lli_close_item);
570         lli->lli_inode_magic = LLI_INODE_MAGIC;
571         memset(&lli->lli_id, 0, sizeof(lli->lli_id));
572         sema_init(&lli->lli_och_sem, 1);
573         lli->lli_mds_read_och = lli->lli_mds_write_och = NULL;
574         lli->lli_mds_exec_och = NULL;
575         lli->lli_open_fd_read_count = lli->lli_open_fd_write_count = 0;
576         lli->lli_open_fd_exec_count = 0;
577         lli->lli_key_info = NULL;
578 }
579
580 int ll_fill_super(struct super_block *sb, void *data, int silent)
581 {
582         struct ll_sb_info *sbi;
583         char *lov = NULL, *lmv = NULL, *gkc = NULL;
584         char *mds_sec = NULL;
585         char *oss_sec = NULL;
586         int async, err;
587         __u32 nllu[2] = { NOBODY_UID, NOBODY_GID };
588         __u64 remote_flag = 0;    
589         ENTRY;
590
591         CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
592
593         sbi = lustre_init_sbi(sb);
594         if (!sbi)
595                 RETURN(-ENOMEM);
596
597         sbi->ll_flags |= LL_SBI_READAHEAD;
598         ll_options(data, &lov, &lmv, &gkc, &mds_sec, &oss_sec,
599                    &async, &sbi->ll_flags);
600
601         if (!lov || !lmv) {
602                 CERROR("no osc %p or no mdc %p\n", lov, lmv);
603                 GOTO(out, err = -EINVAL);
604         }
605         
606         err = lustre_common_fill_super(sb, lmv, lov, gkc, async, mds_sec, 
607                                        oss_sec, nllu, 0, &remote_flag);
608         EXIT;
609 out:
610         if (err)
611                 lustre_free_sbi(sb);
612
613         if (lmv)
614                 OBD_FREE(lmv, strlen(lmv) + 1);
615         if (lov)
616                 OBD_FREE(lov, strlen(lov) + 1);
617         if (mds_sec)
618                 OBD_FREE(mds_sec, strlen(mds_sec) + 1);
619         if (oss_sec)
620                 OBD_FREE(oss_sec, strlen(oss_sec) + 1);
621
622         return err;
623 } /* ll_read_super */
624
625 static int lustre_process_log(struct lustre_mount_data *lmd, char *profile,
626                               struct config_llog_instance *cfg, int allow_recov)
627 {
628         struct lustre_cfg *lcfg = NULL;
629         struct lustre_cfg_bufs bufs;
630         struct portals_cfg pcfg;
631         char *peer = "MDS_PEER_UUID";
632         struct obd_device *obd;
633         struct lustre_handle md_conn = {0, };
634         struct obd_export *exp;
635         char *name = "mdc_dev";
636         class_uuid_t uuid;
637         struct obd_uuid lmv_uuid;
638         struct llog_ctxt *ctxt;
639         int rc = 0, err = 0;
640         ENTRY;
641
642         if (lmd_bad_magic(lmd))
643                 RETURN(-EINVAL);
644
645         generate_random_uuid(uuid);
646         class_uuid_unparse(uuid, &lmv_uuid);
647
648         if (lmd->lmd_local_nid) {
649                 PCFG_INIT(pcfg, NAL_CMD_REGISTER_MYNID);
650                 pcfg.pcfg_nal = lmd->lmd_nal;
651                 pcfg.pcfg_nid = lmd->lmd_local_nid;
652                 rc = libcfs_nal_cmd(&pcfg);
653                 if (rc < 0)
654                         GOTO(out, rc);
655         }
656
657         if (lmd->lmd_nal == SOCKNAL ||
658             lmd->lmd_nal == OPENIBNAL ||
659             lmd->lmd_nal == IIBNAL ||
660             lmd->lmd_nal == VIBNAL ||
661             lmd->lmd_nal == RANAL) {
662                 PCFG_INIT(pcfg, NAL_CMD_ADD_PEER);
663                 pcfg.pcfg_nal     = lmd->lmd_nal;
664                 pcfg.pcfg_nid     = lmd->lmd_server_nid;
665                 pcfg.pcfg_id      = lmd->lmd_server_ipaddr;
666                 pcfg.pcfg_misc    = lmd->lmd_port;
667                 rc = libcfs_nal_cmd(&pcfg);
668                 if (rc < 0)
669                         GOTO(out, rc);
670         }
671         lustre_cfg_bufs_reset(&bufs, name);
672         lustre_cfg_bufs_set_string(&bufs, 1, peer);
673
674         lcfg = lustre_cfg_new(LCFG_ADD_UUID, &bufs);
675         lcfg->lcfg_nal = lmd->lmd_nal;
676         lcfg->lcfg_nid = lmd->lmd_server_nid;
677         LASSERT(lcfg->lcfg_nal);
678         LASSERT(lcfg->lcfg_nid);
679         err = class_process_config(lcfg);
680         lustre_cfg_free(lcfg);
681         if (err < 0)
682                 GOTO(out_del_conn, err);
683
684         lustre_cfg_bufs_reset(&bufs, name);
685         lustre_cfg_bufs_set_string(&bufs, 1, OBD_MDC_DEVICENAME);
686         lustre_cfg_bufs_set_string(&bufs, 2, (char *)lmv_uuid.uuid);
687
688         lcfg = lustre_cfg_new(LCFG_ATTACH, &bufs);
689         err = class_process_config(lcfg);
690         lustre_cfg_free(lcfg);
691         if (err < 0)
692                 GOTO(out_del_uuid, err);
693
694         lustre_cfg_bufs_reset(&bufs, name);
695         lustre_cfg_bufs_set_string(&bufs, 1, lmd->lmd_mds);
696         lustre_cfg_bufs_set_string(&bufs, 2, peer);
697
698         lcfg = lustre_cfg_new(LCFG_SETUP, &bufs);
699         err = class_process_config(lcfg);
700         lustre_cfg_free(lcfg);
701         if (err < 0)
702                 GOTO(out_detach, err);
703
704         obd = class_name2obd(name);
705         if (obd == NULL)
706                 GOTO(out_cleanup, rc = -EINVAL);
707
708         rc = obd_set_info(obd->obd_self_export, strlen("sec"), "sec",
709                           strlen(lmd->lmd_mds_security), lmd->lmd_mds_security);
710         if (rc)
711                 GOTO(out_cleanup, rc);
712
713         if (lmd->lmd_pag) {
714                 unsigned long sec_flags = PTLRPC_SEC_FL_PAG;
715                 rc = obd_set_info(obd->obd_self_export,
716                                   strlen("sec_flags"), "sec_flags",
717                                   sizeof(sec_flags), &sec_flags);
718                 if (rc)
719                         GOTO(out_cleanup, rc);
720         }
721
722         /* Disable initial recovery on this import */
723         rc = obd_set_info(obd->obd_self_export,
724                           strlen("initial_recov"), "initial_recov",
725                           sizeof(allow_recov), &allow_recov);
726         if (rc)
727                 GOTO(out_cleanup, rc);
728
729         rc = obd_connect(&md_conn, obd, &lmv_uuid, NULL, 0);
730         if (rc) {
731                 CERROR("cannot connect to %s: rc = %d\n", lmd->lmd_mds, rc);
732                 GOTO(out_cleanup, rc);
733         }
734
735         exp = class_conn2export(&md_conn);
736
737         ctxt = llog_get_context(&exp->exp_obd->obd_llogs,LLOG_CONFIG_REPL_CTXT);
738         rc = class_config_process_llog(ctxt, profile, cfg);
739         if (rc)
740                 CERROR("class_config_process_llog failed: rc = %d\n", rc);
741
742         err = obd_disconnect(exp, 0);
743         
744         EXIT;
745 out_cleanup:
746         lustre_cfg_bufs_reset(&bufs, name);
747         lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
748         err = class_process_config(lcfg);
749         lustre_cfg_free(lcfg);
750         if (err < 0)
751                 GOTO(out, err);
752 out_detach:
753         lustre_cfg_bufs_reset(&bufs, name);
754         lcfg = lustre_cfg_new(LCFG_DETACH, &bufs);
755         err = class_process_config(lcfg);
756         lustre_cfg_free(lcfg);
757         if (err < 0)
758                 GOTO(out, err);
759
760 out_del_uuid:
761         lustre_cfg_bufs_reset(&bufs, name);
762         lustre_cfg_bufs_set_string(&bufs, 1, peer);
763         lcfg = lustre_cfg_new(LCFG_DEL_UUID, &bufs);
764         err = class_process_config(lcfg);
765         lustre_cfg_free(lcfg);
766
767 out_del_conn:
768         if (lmd->lmd_nal == SOCKNAL ||
769             lmd->lmd_nal == OPENIBNAL ||
770             lmd->lmd_nal == IIBNAL ||
771             lmd->lmd_nal == VIBNAL ||
772             lmd->lmd_nal == RANAL) {
773                 int err2;
774
775                 PCFG_INIT(pcfg, NAL_CMD_DEL_PEER);
776                 pcfg.pcfg_nal     = lmd->lmd_nal;
777                 pcfg.pcfg_nid     = lmd->lmd_server_nid;
778                 pcfg.pcfg_flags   = 1;          /* single_share */
779                 err2 = libcfs_nal_cmd(&pcfg);
780                 if (err2 && !err)
781                         err = err2;
782                 if (err < 0)
783                         GOTO(out, err);
784         }
785 out:
786         if (rc == 0)
787                 rc = err;
788
789         return rc;
790 }
791
792 static void lustre_manual_cleanup(struct ll_sb_info *sbi)
793 {
794         struct lustre_cfg *lcfg;
795         struct lustre_cfg_bufs bufs;
796         struct obd_device *obd;
797         int next = 0;
798
799         while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) != NULL) {
800                 int err;
801
802                 lustre_cfg_bufs_reset(&bufs, obd->obd_name);
803                 lcfg = lustre_cfg_new(LCFG_CLEANUP, &bufs);
804                 err = class_process_config(lcfg);
805                 if (err) {
806                         CERROR("cleanup failed: %s\n", obd->obd_name);
807                         //continue;
808                 }
809                 
810                 lcfg->lcfg_command = LCFG_DETACH;
811                 err = class_process_config(lcfg);
812                 lustre_cfg_free(lcfg);
813                 if (err) {
814                         CERROR("detach failed: %s\n", obd->obd_name);
815                         //continue;
816                 }
817         }
818
819         if (sbi->ll_lmd != NULL)
820                 class_del_profile(sbi->ll_lmd->lmd_profile);
821 }
822
823 static int lustre_process_profile(struct super_block *sb, 
824                                   struct lustre_mount_data *lmd,
825                                   char **lov, char **lmv, char **gkc)  
826 {
827         struct ll_sb_info *sbi = ll_s2sbi(sb);
828         struct lustre_profile *lprof;
829         struct config_llog_instance cfg;
830         int len, err = 0;
831         
832         ENTRY;
833
834         if (!lmd->lmd_profile)
835                 RETURN(0);
836  
837         if (lmd->lmd_mds[0] == '\0') {
838                 CERROR("no mds name\n");
839                 GOTO(out, err = -EINVAL);
840         }
841         lmd->lmd_mds_security[sizeof(lmd->lmd_mds_security) - 1] = 0;
842         lmd->lmd_oss_security[sizeof(lmd->lmd_oss_security) - 1] = 0;
843
844         OBD_ALLOC(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
845         if (sbi->ll_lmd == NULL)
846                 GOTO(out, err = -ENOMEM);
847         memcpy(sbi->ll_lmd, lmd, sizeof(*lmd));
848
849         /* generate a string unique to this super, let's try
850          the address of the super itself.*/
851         len = (sizeof(sb) * 2) + 1;
852         OBD_ALLOC(sbi->ll_instance, len);
853         if (sbi->ll_instance == NULL)
854                 GOTO(out, err = -ENOMEM);
855         sprintf(sbi->ll_instance, "%p", sb);
856
857         cfg.cfg_instance = sbi->ll_instance;
858         cfg.cfg_uuid = sbi->ll_sb_uuid;
859         cfg.cfg_local_nid = lmd->lmd_local_nid;
860         err = lustre_process_log(lmd, lmd->lmd_profile, &cfg, 0);
861         if (err < 0) {
862                 CERROR("Unable to process log: %s\n", lmd->lmd_profile);
863                 GOTO(out, err);
864         }
865
866         lprof = class_get_profile(lmd->lmd_profile);
867         if (lprof == NULL) {
868                 CERROR("No profile found: %s\n", lmd->lmd_profile);
869                 GOTO(out, err = -EINVAL);
870         }
871
872         OBD_ALLOC(*lov, strlen(lprof->lp_lov) +
873                   strlen(sbi->ll_instance) + 2);
874         sprintf(*lov, "%s-%s", lprof->lp_lov, sbi->ll_instance);
875
876         OBD_ALLOC(*lmv, strlen(lprof->lp_lmv) +
877                   strlen(sbi->ll_instance) + 2);
878         sprintf(*lmv, "%s-%s", lprof->lp_lmv, sbi->ll_instance);
879
880         if (lprof->lp_gkc) {
881                OBD_ALLOC(*gkc, strlen(lprof->lp_gkc) +
882                                strlen(sbi->ll_instance) + 2);
883                sprintf(*gkc, "%s-%s", lprof->lp_gkc, sbi->ll_instance); 
884         }
885 out: 
886         RETURN(err); 
887 }
888
889 static int lustre_clean_profile(struct ll_sb_info *sbi, int force_umount)
890 {
891         struct lustre_mount_data *lmd = sbi->ll_lmd;
892         struct config_llog_instance cfg;
893         char *cl_prof;
894         int len, err = 0;
895         ENTRY; 
896  
897         if (!lmd)
898                 RETURN(err);
899
900         len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean") + 1;
901         
902         if (force_umount) {
903                 CERROR("force umount, doing manual cleanup\n");
904                 lustre_manual_cleanup(sbi);
905                 GOTO(free_lmd, 0);
906                 
907         }
908         if (sbi->ll_instance != NULL) {
909                 cfg.cfg_instance = sbi->ll_instance;
910                 cfg.cfg_uuid = sbi->ll_sb_uuid;
911
912                 OBD_ALLOC(cl_prof, len);
913                 sprintf(cl_prof, "%s-clean", lmd->lmd_profile);
914                 err = lustre_process_log(lmd, cl_prof, &cfg, 0);
915                 if (err < 0) {
916                         CERROR("Unable to process log: %s\n", cl_prof);
917                         lustre_manual_cleanup(sbi);
918                 }
919                 OBD_FREE(cl_prof, len);
920         }
921 free_lmd:
922         if (sbi->ll_instance)
923                 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance) + 1);
924         OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
925         RETURN(err);
926 }
927
928 int lustre_fill_super(struct super_block *sb, void *data, int silent)
929 {
930         struct lustre_mount_data * lmd = data;
931         char *lov = NULL, *lmv = NULL, *gkc = NULL;
932         struct ll_sb_info *sbi;
933         int err;
934         ENTRY;
935
936         CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
937         if (lmd_bad_magic(lmd))
938                 RETURN(-EINVAL);
939
940         sbi = lustre_init_sbi(sb);
941         if (!sbi)
942                 RETURN(-ENOMEM);
943
944         sbi->ll_flags |= LL_SBI_READAHEAD;
945
946         err = lustre_process_profile(sb, lmd, &lov, &lmv, &gkc);
947         if (err) {
948                 CERROR("Can not process the profile err %d \n", err);
949                 GOTO(out_free, err);
950         }
951         if (!lov || !lmv) {
952                 CERROR("no osc %p or no mdc %p \n", lov, lmv);
953                 GOTO(out_free, err = -EINVAL);
954         }
955
956         err = lustre_common_fill_super(sb, lmv, lov, gkc, lmd->lmd_async,
957                                        lmd->lmd_mds_security,
958                                        lmd->lmd_oss_security,
959                                        &lmd->lmd_nllu, lmd->lmd_pag,
960                                        &lmd->lmd_remote_flag);
961
962         if (err)
963                 GOTO(out_free, err);
964         
965 out_dev:
966         if (lmv)
967                 OBD_FREE(lmv, strlen(lmv) + 1);
968         if (lov)
969                 OBD_FREE(lov, strlen(lov) + 1);
970         if (gkc)
971                 OBD_FREE(gkc, strlen(gkc) + 1);
972         
973         RETURN(err);
974 out_free:
975         lustre_clean_profile(sbi, 0);
976         lustre_free_sbi(sb);
977         GOTO(out_dev, err);
978
979 } /* lustre_fill_super */
980
981 void lustre_put_super(struct super_block *sb)
982 {
983         struct obd_device *obd;
984         struct ll_sb_info *sbi = ll_s2sbi(sb);
985         int force_umount = 0;
986         ENTRY;
987
988         CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
989         obd = class_exp2obd(sbi->ll_md_exp);
990         if (obd)
991                 force_umount = obd->obd_no_recov;
992         obd = NULL;
993
994         lustre_common_put_super(sb);
995         lustre_clean_profile(sbi, force_umount);
996         lustre_free_sbi(sb);
997
998         EXIT;
999 } /* lustre_put_super */
1000
1001 int ll_process_config_update(struct ll_sb_info *sbi, int clean)
1002 {
1003         struct lustre_mount_data *lmd = sbi->ll_lmd;
1004         char *profile = lmd->lmd_profile, *name = NULL;
1005         struct config_llog_instance cfg;
1006         int rc, namelen =  0, version;
1007         struct llog_ctxt *ctxt;
1008         ENTRY;
1009
1010         if (profile == NULL)
1011                 RETURN(0);
1012         if (lmd == NULL) {
1013                 CERROR("Client not mounted with zero-conf; cannot "
1014                        "process update log.\n");
1015                 RETURN(0);
1016         }
1017
1018         rc = obd_cancel_unused(sbi->ll_md_exp, NULL,
1019                                LDLM_FL_CONFIG_CHANGE, NULL);
1020         if (rc != 0)
1021                 CWARN("obd_cancel_unused(mdc): %d\n", rc);
1022
1023         rc = obd_cancel_unused(sbi->ll_dt_exp, NULL,
1024                                LDLM_FL_CONFIG_CHANGE, NULL);
1025         if (rc != 0)
1026                 CWARN("obd_cancel_unused(lov): %d\n", rc);
1027
1028         cfg.cfg_instance = sbi->ll_instance;
1029         cfg.cfg_uuid = sbi->ll_sb_uuid;
1030         cfg.cfg_local_nid = lmd->lmd_local_nid;
1031
1032         namelen = strlen(profile) + 20; /* -clean-######### */
1033         OBD_ALLOC(name, namelen);
1034         if (name == NULL)
1035                 RETURN(-ENOMEM);
1036
1037         if (clean) {
1038                 version = sbi->ll_config_version - 1;
1039                 sprintf(name, "%s-clean-%d", profile, version);
1040         } else {
1041                 version = sbi->ll_config_version + 1;
1042                 sprintf(name, "%s-%d", profile, version);
1043         }
1044
1045         CWARN("Applying configuration log %s\n", name);
1046
1047         ctxt = llog_get_context(&sbi->ll_md_exp->exp_obd->obd_llogs,
1048                                 LLOG_CONFIG_REPL_CTXT);
1049         rc = class_config_process_llog(ctxt, name, &cfg);
1050         if (rc == 0)
1051                 sbi->ll_config_version = version;
1052         CWARN("Finished applying configuration log %s: %d\n", name, rc);
1053
1054         if (rc == 0 && clean == 0) {
1055                 struct lov_desc desc;
1056                 __u32 valsize;
1057                 int rc = 0;
1058                 
1059                 valsize = sizeof(desc);
1060                 rc = obd_get_info(sbi->ll_dt_exp, strlen("lovdesc") + 1,
1061                                   "lovdesc", &valsize, &desc);
1062
1063                 rc = obd_init_ea_size(sbi->ll_md_exp,
1064                                       obd_size_diskmd(sbi->ll_dt_exp, NULL),
1065                                       (desc.ld_tgt_count *
1066                                        sizeof(struct llog_cookie)));
1067         }
1068         OBD_FREE(name, namelen);
1069         RETURN(rc);
1070 }
1071
1072 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
1073 {
1074         struct inode *inode = NULL;
1075
1076         /* NOTE: we depend on atomic igrab() -bzzz */
1077         lock_res_and_lock(lock);
1078         if (lock->l_ast_data) {
1079                 struct ll_inode_info *lli = ll_i2info(lock->l_ast_data);
1080                 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1081                         inode = igrab(lock->l_ast_data);
1082                 } else {
1083                         struct timeval now;
1084                         do_gettimeofday(&now);
1085                         inode = lock->l_ast_data;
1086                         LDLM_ERROR(lock, "granted at %lu.%lu, now %lu.%lu",
1087                                    lock->l_enqueued_time.tv_sec,
1088                                    lock->l_enqueued_time.tv_usec,
1089                                    now.tv_sec, now.tv_usec);
1090                         CDEBUG(inode->i_state & I_FREEING ? D_INFO : D_WARNING,
1091                                "l_ast_data %p is bogus: magic %0x8\n",
1092                                lock->l_ast_data, lli->lli_inode_magic);
1093                         CDEBUG(D_ERROR, "i_state = 0x%lx, l_ast_data %p is bogus: magic %0x8\n",
1094                                inode->i_state, lock->l_ast_data, lli->lli_inode_magic);
1095                         inode = NULL;
1096                         unlock_res_and_lock(lock);
1097                         LBUG();
1098                 }
1099         }
1100         unlock_res_and_lock(lock);
1101         return inode;
1102 }
1103
1104 int null_if_equal(struct ldlm_lock *lock, void *data)
1105 {
1106         if (data == lock->l_ast_data) {
1107                 lock->l_ast_data = NULL;
1108
1109                 if (lock->l_req_mode != lock->l_granted_mode)
1110                         LDLM_ERROR(lock,"clearing inode with ungranted lock\n");
1111         }
1112
1113         return LDLM_ITER_CONTINUE;
1114 }
1115
1116 static void remote_acl_free(struct remote_acl *racl);
1117
1118 void ll_clear_inode(struct inode *inode)
1119 {
1120         struct lustre_id id;
1121         struct ll_inode_info *lli = ll_i2info(inode);
1122         struct ll_sb_info *sbi = ll_i2sbi(inode);
1123         ENTRY;
1124
1125         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1126                inode->i_generation, inode);
1127
1128         ll_inode2id(&id, inode);
1129         
1130         clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
1131         md_change_cbdata(sbi->ll_md_exp, &id, null_if_equal, inode);
1132
1133         LASSERT(!lli->lli_open_fd_write_count);
1134         LASSERT(!lli->lli_open_fd_read_count);
1135         LASSERT(!lli->lli_open_fd_exec_count);
1136         if (lli->lli_mds_write_och)
1137                 ll_md_real_close(sbi->ll_md_exp, inode, FMODE_WRITE);
1138         if (lli->lli_mds_exec_och)
1139                 ll_md_real_close(sbi->ll_md_exp, inode, FMODE_EXEC);
1140         if (lli->lli_mds_read_och)
1141                 ll_md_real_close(sbi->ll_md_exp, inode, FMODE_READ);
1142         if (lli->lli_smd)
1143                 obd_change_cbdata(sbi->ll_dt_exp, lli->lli_smd,
1144                                   null_if_equal, inode);
1145
1146         if (lli->lli_smd) {
1147                 obd_free_memmd(sbi->ll_dt_exp, &lli->lli_smd);
1148                 lli->lli_smd = NULL;
1149         }
1150
1151         if (lli->lli_mea) {
1152                 obd_free_memmd(sbi->ll_md_exp,
1153                                (struct lov_stripe_md **) &lli->lli_mea);
1154                 lli->lli_mea = NULL;
1155         }
1156         ll_crypto_destroy_inode_key(inode);
1157         if (lli->lli_symlink_name) {
1158                 OBD_FREE(lli->lli_symlink_name,
1159                          strlen(lli->lli_symlink_name) + 1);
1160                 lli->lli_symlink_name = NULL;
1161         }
1162
1163         if (lli->lli_posix_acl) {
1164                 LASSERT(lli->lli_remote_acl == NULL);
1165                 posix_acl_release(lli->lli_posix_acl);
1166                 lli->lli_posix_acl = NULL;
1167         }
1168
1169         if (lli->lli_remote_acl) {
1170                 LASSERT(lli->lli_posix_acl == NULL);
1171                 remote_acl_free(lli->lli_remote_acl);
1172                 lli->lli_remote_acl = NULL;
1173         }
1174
1175         lli->lli_inode_magic = LLI_INODE_DEAD;
1176
1177         EXIT;
1178 }
1179
1180 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1181  * object(s) determine the file size and mtime.  Otherwise, the MDS will
1182  * keep these values until such a time that objects are allocated for it.
1183  * We do the MDS operations first, as it is checking permissions for us.
1184  * We don't to the MDS RPC if there is nothing that we want to store there,
1185  * otherwise there is no harm in updating mtime/atime on the MDS if we are
1186  * going to do an RPC anyways.
1187  *
1188  * If we are doing a truncate, we will send the mtime and ctime updates
1189  * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1190  * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1191  * at the same time.
1192  */
1193 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
1194 {
1195         struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1196         struct ll_inode_info *lli = ll_i2info(inode);
1197         struct ll_sb_info *sbi = ll_i2sbi(inode);
1198         struct ptlrpc_request *request = NULL;
1199         struct mdc_op_data *op_data;
1200         int ia_valid = attr->ia_valid;
1201         int err, rc = 0;
1202         ENTRY;
1203
1204         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
1205         lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
1206
1207         if (ia_valid & ATTR_SIZE) {
1208                 if (attr->ia_size > ll_file_maxbytes(inode)) {
1209                         CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
1210                                attr->ia_size, ll_file_maxbytes(inode));
1211                         RETURN(-EFBIG);
1212                 }
1213
1214                 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1215         }
1216
1217         /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1218         if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
1219                 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
1220                         RETURN(-EPERM);
1221         }
1222
1223         /* We mark all of the fields "set" so MDS/OST does not re-set them */
1224         if (attr->ia_valid & ATTR_CTIME) {
1225                 attr->ia_ctime = CURRENT_TIME;
1226                 attr->ia_valid |= ATTR_CTIME_SET;
1227         }
1228         if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
1229                 attr->ia_atime = CURRENT_TIME;
1230                 attr->ia_valid |= ATTR_ATIME_SET;
1231         }
1232         if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
1233                 attr->ia_mtime = CURRENT_TIME;
1234                 attr->ia_valid |= ATTR_MTIME_SET;
1235         }
1236
1237         if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1238                 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
1239                        LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1240                        LTIME_S(CURRENT_TIME));
1241
1242         if (lsm)
1243                 attr->ia_valid &= ~ATTR_SIZE;
1244
1245         /* If only OST attributes being set on objects, don't do MDS RPC.
1246          * In that case, we need to check permissions and update the local
1247          * inode ourselves so we can call obdo_from_inode() always. */
1248         if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN /*| ATTR_RAW*/) : ~0)) {
1249                 struct lustre_md md;
1250                 void *key = NULL;
1251                 int  key_size = 0; 
1252
1253                 OBD_ALLOC(op_data, sizeof(*op_data));
1254                 if (op_data == NULL)
1255                         RETURN(-ENOMEM);
1256                 ll_prepare_mdc_data(op_data, inode, NULL, NULL, 0, 0);
1257
1258                 if (ia_valid & (ATTR_UID | ATTR_GID)) {
1259                         rc = ll_crypto_get_mac(inode, attr, NULL, 0, &key, 
1260                                                &key_size);
1261                 }
1262                 rc = md_setattr(sbi->ll_md_exp, op_data,
1263                                 attr, key, key_size, NULL, 0, NULL, 
1264                                 0, &request);
1265                 OBD_FREE(op_data, sizeof(*op_data));
1266                 
1267                 if (key && key_size) 
1268                         OBD_FREE(key, key_size);
1269                 if (rc) {
1270                         ptlrpc_req_finished(request);
1271                         if (rc != -EPERM && rc != -EACCES)
1272                                 CERROR("md_setattr fails: rc = %d\n", rc);
1273                         RETURN(rc);
1274                 }
1275                 rc = mdc_req2lustre_md(sbi->ll_md_exp, request, 0, 
1276                                        sbi->ll_dt_exp, &md);
1277                 if (rc) {
1278                         ptlrpc_req_finished(request);
1279                         RETURN(rc);
1280                 }
1281
1282                 /* We call inode_setattr to adjust timestamps, but we first
1283                  * clear ATTR_SIZE to avoid invoking vmtruncate.
1284                  *
1285                  * NB: ATTR_SIZE will only be set at this point if the size
1286                  * resides on the MDS, ie, this file has no objects. */
1287                 attr->ia_valid &= ~ATTR_SIZE;
1288
1289                 /* 
1290                  * assigning inode_setattr() to @err to disable warning that
1291                  * function's result should be checked by by caller. error is
1292                  * impossible here, as vmtruncate() control path is disabled.
1293                  */
1294                 err = inode_setattr(inode, attr);
1295                 ll_update_inode(inode, &md);
1296                 ptlrpc_req_finished(request);
1297
1298                 if (!lsm || !S_ISREG(inode->i_mode)) {
1299                         CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
1300                         RETURN(0);
1301                 }
1302         } else {
1303                 /* The OST doesn't check permissions, but the alternative is
1304                  * a gratuitous RPC to the MDS.  We already rely on the client
1305                  * to do read/write/truncate permission checks, so is mtime OK?
1306                  */
1307                 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
1308                         /* from sys_utime() */
1309                         if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
1310                                 if (current->fsuid != inode->i_uid &&
1311                                     (rc = ll_permission(inode, MAY_WRITE, NULL)) != 0)
1312                                         RETURN(rc);
1313                         } else {
1314                                 /* from inode_change_ok() */
1315                                 if (current->fsuid != inode->i_uid &&
1316                                     !capable(CAP_FOWNER))
1317                                         RETURN(-EPERM);
1318                         }
1319                 }
1320
1321                 /* won't invoke vmtruncate, as we already cleared ATTR_SIZE */
1322                 err = inode_setattr(inode, attr);
1323                 /* 
1324                  * assigning inode_setattr() to @err to disable warning that
1325                  * function's result should be checked by by caller. error is
1326                  * impossible here, as vmtruncate() control path is disabled.
1327                  */
1328         }
1329
1330         /* We really need to get our PW lock before we change inode->i_size.
1331          * If we don't we can race with other i_size updaters on our node, like
1332          * ll_file_read.  We can also race with i_size propogation to other
1333          * nodes through dirtying and writeback of final cached pages.  This
1334          * last one is especially bad for racing o_append users on other
1335          * nodes. */
1336         if (ia_valid & ATTR_SIZE) {
1337                 ldlm_policy_data_t policy = { .l_extent = {attr->ia_size,
1338                                                            OBD_OBJECT_EOF } };
1339                 struct lustre_handle lockh = { 0 };
1340                 int err, ast_flags = 0;
1341                 /* XXX when we fix the AST intents to pass the discard-range
1342                  * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
1343                  * XXX here. */
1344                 if (attr->ia_size == 0)
1345                         ast_flags = LDLM_AST_DISCARD_DATA;
1346
1347                 rc = ll_extent_lock(NULL, inode, lsm, LCK_PW, &policy, &lockh,
1348                                     ast_flags, &ll_i2sbi(inode)->ll_seek_stime);
1349
1350                 if (rc != 0)
1351                         RETURN(rc);
1352
1353                 down(&lli->lli_size_sem);
1354                 lli->lli_size_pid = current->pid;
1355                 rc = vmtruncate(inode, attr->ia_size);
1356                 if (rc != 0) {
1357                         LASSERT(atomic_read(&lli->lli_size_sem.count) <= 0);
1358                         lli->lli_size_pid = 0;
1359                         up(&lli->lli_size_sem);
1360                 }
1361
1362                 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
1363                 if (err) {
1364                         CERROR("ll_extent_unlock failed: %d\n", err);
1365                         if (!rc)
1366                                 rc = err;
1367                 }
1368         } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET | ATTR_UID | ATTR_GID)) {
1369                 struct obdo *oa = NULL;
1370
1371                 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
1372                        inode->i_ino, LTIME_S(attr->ia_mtime));
1373
1374                 oa = obdo_alloc();
1375                 if (oa == NULL)
1376                         RETURN(-ENOMEM);
1377
1378                 oa->o_id = lsm->lsm_object_id;
1379                 oa->o_gr = lsm->lsm_object_gr;
1380                 oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP;
1381
1382                 /* adding uid and gid, needed for quota */
1383                 if (ia_valid & ATTR_UID) {
1384                         oa->o_uid = inode->i_uid;
1385                         oa->o_valid |= OBD_MD_FLUID;
1386                 }
1387
1388                 if (ia_valid & ATTR_GID) {
1389                         oa->o_gid = inode->i_gid;
1390                         oa->o_valid |= OBD_MD_FLGID;
1391                 }
1392
1393                 *(obdo_id(oa)) = lli->lli_id;
1394                 oa->o_valid |= OBD_MD_FLIFID;
1395
1396                 obdo_from_inode(oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
1397                                 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
1398                 rc = obd_setattr(sbi->ll_dt_exp, oa, lsm, NULL);
1399                 obdo_free(oa);
1400                 if (rc)
1401                         CERROR("obd_setattr fails: rc = %d\n", rc);
1402         }
1403
1404         RETURN(rc);
1405 }
1406
1407 int ll_setattr(struct dentry *de, struct iattr *attr)
1408 {
1409         LASSERT(de->d_inode);
1410         return ll_setattr_raw(de->d_inode, attr);
1411 }
1412
1413 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1414                        unsigned long max_age)
1415 {
1416         struct ll_sb_info *sbi = ll_s2sbi(sb);
1417         struct obd_statfs obd_osfs;
1418         int rc;
1419         ENTRY;
1420
1421         rc = obd_statfs(class_exp2obd(sbi->ll_md_exp), osfs, max_age);
1422         if (rc) {
1423                 CERROR("obd_statfs fails: rc = %d\n", rc);
1424                 RETURN(rc);
1425         }
1426
1427         osfs->os_type = sb->s_magic;
1428
1429         CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1430                osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1431
1432         rc = obd_statfs(class_exp2obd(sbi->ll_dt_exp), &obd_osfs, max_age);
1433         if (rc) {
1434                 CERROR("obd_statfs fails: rc = %d\n", rc);
1435                 RETURN(rc);
1436         }
1437
1438         CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
1439                obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1440                obd_osfs.os_files);
1441
1442         osfs->os_blocks = obd_osfs.os_blocks;
1443         osfs->os_bfree = obd_osfs.os_bfree;
1444         osfs->os_bavail = obd_osfs.os_bavail;
1445
1446         /* If we don't have as many objects free on the OST as inodes
1447          * on the MDS, we reduce the total number of inodes to
1448          * compensate, so that the "inodes in use" number is correct.
1449          */
1450         if (obd_osfs.os_ffree < osfs->os_ffree) {
1451                 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1452                         obd_osfs.os_ffree;
1453                 osfs->os_ffree = obd_osfs.os_ffree;
1454         }
1455
1456         RETURN(rc);
1457 }
1458
1459 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
1460 {
1461         struct obd_statfs osfs;
1462         int rc;
1463
1464         CDEBUG(D_VFSTRACE, "VFS Op: superblock %p\n", sb);
1465         lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
1466
1467         /* For now we will always get up-to-date statfs values, but in the
1468          * future we may allow some amount of caching on the client (e.g.
1469          * from QOS or lprocfs updates). */
1470         rc = ll_statfs_internal(sb, &osfs, jiffies - 1);
1471         if (rc)
1472                 return rc;
1473
1474         statfs_unpack(sfs, &osfs);
1475
1476         if (sizeof(sfs->f_blocks) == 4) {
1477                 while (osfs.os_blocks > ~0UL) {
1478                         sfs->f_bsize <<= 1;
1479
1480                         osfs.os_blocks >>= 1;
1481                         osfs.os_bfree >>= 1;
1482                         osfs.os_bavail >>= 1;
1483                 }
1484         }
1485
1486         sfs->f_blocks = osfs.os_blocks;
1487         sfs->f_bfree = osfs.os_bfree;
1488         sfs->f_bavail = osfs.os_bavail;
1489
1490         return 0;
1491 }
1492
1493
1494 /********************************
1495  * remote acl                   *
1496  ********************************/
1497
1498 static struct remote_acl *remote_acl_alloc(void)
1499 {
1500         struct remote_acl *racl;
1501         int i;
1502
1503         OBD_ALLOC(racl, sizeof(*racl));
1504         if (!racl)
1505                 return NULL;
1506
1507         spin_lock_init(&racl->ra_lock);
1508         init_MUTEX(&racl->ra_update_sem);
1509
1510         for (i = 0; i < REMOTE_ACL_HASHSIZE; i++)
1511                 INIT_LIST_HEAD(&racl->ra_perm_cache[i]);
1512
1513         return racl;
1514 }
1515
1516 /*
1517  * caller should guarantee no race here.
1518  */
1519 static void remote_perm_flush_xperms(struct lustre_remote_perm *perm)
1520 {
1521         struct remote_perm_setxid *xperm;
1522
1523         while (!list_empty(&perm->lrp_setxid_perms)) {
1524                 xperm = list_entry(perm->lrp_setxid_perms.next,
1525                                    struct remote_perm_setxid,
1526                                    list);
1527                 list_del(&xperm->list);
1528                 OBD_FREE(xperm, sizeof(*xperm));
1529         }
1530 }
1531
1532 /*
1533  * caller should guarantee no race here.
1534  */
1535 static void remote_acl_flush(struct remote_acl *racl)
1536 {
1537         struct list_head *head;
1538         struct lustre_remote_perm *perm, *tmp;
1539         int i;
1540
1541         for (i = 0; i < REMOTE_ACL_HASHSIZE; i++) {
1542                 head = &racl->ra_perm_cache[i];
1543
1544                 list_for_each_entry_safe(perm, tmp, head, lrp_list) {
1545                         remote_perm_flush_xperms(perm);
1546                         list_del(&perm->lrp_list);
1547                         OBD_FREE(perm, sizeof(*perm));
1548                 }
1549         }
1550 }
1551
1552 static void remote_acl_free(struct remote_acl *racl)
1553 {
1554         if (!racl)
1555                 return;
1556
1557         down(&racl->ra_update_sem);
1558         spin_lock(&racl->ra_lock);
1559         remote_acl_flush(racl);
1560         spin_unlock(&racl->ra_lock);
1561         up(&racl->ra_update_sem);
1562
1563         OBD_FREE(racl, sizeof(*racl));
1564 }
1565
1566 static inline int remote_acl_hashfunc(__u32 id)
1567 {
1568         return (id & (REMOTE_ACL_HASHSIZE - 1));
1569 }
1570
1571 static
1572 int __remote_acl_check(struct remote_acl *racl, unsigned int *perm)
1573 {
1574         struct list_head *head;
1575         struct lustre_remote_perm *lperm;
1576         struct remote_perm_setxid *xperm;
1577         int found = 0, rc = -ENOENT;
1578
1579         LASSERT(racl);
1580         head = &racl->ra_perm_cache[remote_acl_hashfunc(current->uid)];
1581         spin_lock(&racl->ra_lock);
1582
1583         list_for_each_entry(lperm, head, lrp_list) {
1584                 if (lperm->lrp_auth_uid == current->uid) {
1585                         found = 1;
1586                         break;
1587                 }
1588         }
1589
1590         if (!found)
1591                 goto out;
1592
1593         if (lperm->lrp_auth_uid == current->fsuid &&
1594             lperm->lrp_auth_gid == current->fsgid) {
1595                 if (lperm->lrp_valid) {
1596                         *perm = lperm->lrp_perm;
1597                         rc = 0;
1598                 }
1599                 goto out;
1600         } else if ((!lperm->lrp_setuid &&
1601                     lperm->lrp_auth_uid != current->fsuid) ||
1602                    (!lperm->lrp_setgid &&
1603                     lperm->lrp_auth_gid != current->fsgid))  {
1604                 *perm = 0;
1605                 rc = 0;
1606                 goto out;
1607         }
1608
1609         list_for_each_entry(xperm, &lperm->lrp_setxid_perms, list) {
1610                 if (xperm->uid == current->fsuid &&
1611                     xperm->gid == current->fsgid) {
1612                         *perm = xperm->perm;
1613                         rc = 0;
1614                         goto out;
1615                 }
1616         }
1617
1618 out:
1619         spin_unlock(&racl->ra_lock);
1620         return rc;
1621 }
1622
1623 static
1624 int __remote_acl_update(struct remote_acl *racl,
1625                         struct mds_remote_perm *mperm,
1626                         struct lustre_remote_perm *lperm,
1627                         struct remote_perm_setxid *xperm)
1628 {
1629         struct list_head *head;
1630         struct lustre_remote_perm *lp;
1631         struct remote_perm_setxid *xp;
1632         int found = 0, setuid = 0, setgid = 0;
1633
1634         LASSERT(racl);
1635         LASSERT(mperm);
1636         LASSERT(lperm);
1637         LASSERT(current->uid == mperm->mrp_auth_uid);
1638
1639         if (current->fsuid != mperm->mrp_auth_uid)
1640                 setuid = 1;
1641         if (current->fsgid != mperm->mrp_auth_gid)
1642                 setgid = 1;
1643
1644         head = &racl->ra_perm_cache[remote_acl_hashfunc(current->uid)];
1645         spin_lock(&racl->ra_lock);
1646
1647         list_for_each_entry(lp, head, lrp_list) {
1648                 if (lp->lrp_auth_uid == current->uid) {
1649                         found = 1;
1650                         break;
1651                 }
1652         }
1653
1654         if (found) {
1655                 OBD_FREE(lperm, sizeof(*lperm));
1656
1657                 if (!lp->lrp_valid && !setuid && !setgid) {
1658                         lp->lrp_perm = mperm->mrp_perm;
1659                         lp->lrp_valid = 1;
1660                 }
1661
1662                 /* sanity check for changes of setxid rules */
1663                 if ((lp->lrp_setuid != 0) != (mperm->mrp_allow_setuid != 0)) {
1664                         CWARN("setuid changes: %d => %d\n",
1665                               (lp->lrp_setuid != 0),
1666                               (mperm->mrp_allow_setuid != 0));
1667                         lp->lrp_setuid = (mperm->mrp_allow_setuid != 0);
1668                 }
1669
1670                 if ((lp->lrp_setgid != 0) != (mperm->mrp_allow_setgid != 0)) {
1671                         CWARN("setgid changes: %d => %d\n",
1672                               (lp->lrp_setgid != 0),
1673                               (mperm->mrp_allow_setgid != 0));
1674                         lp->lrp_setgid = (mperm->mrp_allow_setgid != 0);
1675                 }
1676
1677                 if (!lp->lrp_setuid && !lp->lrp_setgid &&
1678                     !list_empty(&lp->lrp_setxid_perms)) {
1679                         remote_perm_flush_xperms(lp);
1680                 }
1681         } else {
1682                 /* initialize lperm and linked into hashtable
1683                  */
1684                 INIT_LIST_HEAD(&lperm->lrp_setxid_perms);
1685                 lperm->lrp_auth_uid = mperm->mrp_auth_uid;
1686                 lperm->lrp_auth_gid = mperm->mrp_auth_gid;
1687                 lperm->lrp_setuid = (mperm->mrp_allow_setuid != 0);
1688                 lperm->lrp_setgid = (mperm->mrp_allow_setgid != 0);
1689                 list_add(&lperm->lrp_list, head);
1690
1691                 if (!setuid && !setgid) {
1692                         /* in this case, i'm the authenticated user,
1693                          * and mrp_perm is for me.
1694                          */
1695                         lperm->lrp_perm = mperm->mrp_perm;
1696                         lperm->lrp_valid = 1;
1697                         spin_unlock(&racl->ra_lock);
1698
1699                         if (xperm)
1700                                 OBD_FREE(xperm, sizeof(*xperm));
1701                         return 0;
1702                 }
1703
1704                 lp = lperm;
1705                 /* fall through */
1706         }
1707
1708         LASSERT(lp->lrp_setuid || lp->lrp_setgid ||
1709                 list_empty(&lp->lrp_setxid_perms));
1710
1711         /* if no xperm supplied, we are all done here */
1712         if (!xperm) {
1713                 spin_unlock(&racl->ra_lock);
1714                 return 0;
1715         }
1716
1717         /* whether we allow setuid/setgid */
1718         if ((!lp->lrp_setuid && setuid) || (!lp->lrp_setgid && setgid)) {
1719                 OBD_FREE(xperm, sizeof(*xperm));
1720                 spin_unlock(&racl->ra_lock);
1721                 return 0;
1722         }
1723
1724         /* traverse xperm list */
1725         list_for_each_entry(xp, &lp->lrp_setxid_perms, list) {
1726                 if (xp->uid == current->fsuid &&
1727                     xp->gid == current->fsgid) {
1728                         if (xp->perm != mperm->mrp_perm) {
1729                                 /* actually this should not happen */
1730                                 CWARN("perm changed: %o => %o\n",
1731                                       xp->perm, mperm->mrp_perm);
1732                                 xp->perm = mperm->mrp_perm;
1733                         }
1734                         OBD_FREE(xperm, sizeof(*xperm));
1735                         spin_unlock(&racl->ra_lock);
1736                         return 0;
1737                 }
1738         }
1739
1740         /* finally insert this xperm */
1741         xperm->uid = current->fsuid;
1742         xperm->gid = current->fsgid;
1743         xperm->perm = mperm->mrp_perm;
1744         list_add(&xperm->list, &lp->lrp_setxid_perms);
1745
1746         spin_unlock(&racl->ra_lock);
1747         return 0;
1748 }
1749
1750 /*
1751  * remote_acl semaphore must be held by caller
1752  */
1753 static
1754 int remote_acl_update_locked(struct remote_acl *racl,
1755                              struct mds_remote_perm *mperm)
1756 {
1757         struct lustre_remote_perm *lperm;
1758         struct remote_perm_setxid *xperm;
1759         int setuid = 0, setgid = 0;
1760
1761         might_sleep();
1762
1763         if (current->uid != mperm->mrp_auth_uid) {
1764                 CERROR("current uid %u while authenticated as %u\n",
1765                        current->uid, mperm->mrp_auth_uid);
1766                 return -EINVAL;
1767         }
1768
1769         if (current->fsuid != mperm->mrp_auth_uid)
1770                 setuid = 1;
1771         if (current->fsgid == mperm->mrp_auth_gid)
1772                 setgid = 1;
1773
1774         OBD_ALLOC(lperm, sizeof(*lperm));
1775         if (!lperm)
1776                 return -ENOMEM;
1777
1778         if ((setuid || setgid) &&
1779             !(setuid && !mperm->mrp_allow_setuid) &&
1780             !(setgid && !mperm->mrp_allow_setgid)) {
1781                 OBD_ALLOC(xperm, sizeof(*xperm));
1782                 if (!xperm) {
1783                         OBD_FREE(lperm, sizeof(*lperm));
1784                         return -ENOMEM;
1785                 }
1786         } else
1787                 xperm = NULL;
1788
1789         return __remote_acl_update(racl, mperm, lperm, xperm);
1790 }
1791
1792 /*
1793  * return -EACCES at any error cases
1794  */
1795 int ll_remote_acl_permission(struct inode *inode, int mode)
1796 {
1797         struct ll_sb_info *sbi = ll_i2sbi(inode);
1798         struct remote_acl *racl = ll_i2info(inode)->lli_remote_acl;
1799         struct ptlrpc_request *req = NULL;
1800         struct lustre_id id;
1801         struct mds_remote_perm *mperm;
1802         int rc = -EACCES, perm;
1803
1804         if (!racl)
1805                 return -EACCES;
1806
1807         if (__remote_acl_check(racl, &perm) == 0) {
1808                 return ((perm & mode) == mode ? 0 : -EACCES);
1809         }
1810
1811         might_sleep();
1812
1813         /* doing update
1814          */
1815         down(&racl->ra_update_sem);
1816
1817         /* we might lose the race when obtain semaphore,
1818          * so check again.
1819          */
1820         if (__remote_acl_check(racl, &perm) == 0) {
1821                 if ((perm & mode) == mode)
1822                         rc = 0;
1823                 goto out;
1824         }
1825
1826         /* really fetch from mds
1827          */
1828         ll_inode2id(&id, inode);
1829         if (md_access_check(sbi->ll_md_exp, &id, &req))
1830                 goto out;
1831
1832         /* status non-zero indicate there's more apparent error
1833          * detected by mds, e.g. didn't allow this user at all.
1834          * we simply ignore and didn't cache it.
1835          */
1836         if (req->rq_repmsg->status)
1837                 goto out;
1838
1839         mperm = lustre_swab_repbuf(req, 1, sizeof(*mperm),
1840                                    lustre_swab_remote_perm);
1841         LASSERT(mperm);
1842         LASSERT_REPSWABBED(req, 1);
1843
1844         if ((mperm->mrp_perm & mode) == mode)
1845                 rc = 0;
1846
1847         remote_acl_update_locked(racl, mperm);
1848 out:
1849         if (req)
1850                 ptlrpc_req_finished(req);
1851
1852         up(&racl->ra_update_sem);
1853         return rc;
1854 }
1855
1856 int ll_remote_acl_update(struct inode *inode, struct mds_remote_perm *perm)
1857 {
1858         struct remote_acl *racl = ll_i2info(inode)->lli_remote_acl;
1859         int rc;
1860
1861         LASSERT(perm);
1862
1863         if (!racl)
1864                 return -EACCES;
1865
1866         down(&racl->ra_update_sem);
1867         rc = remote_acl_update_locked(racl, perm);
1868         up(&racl->ra_update_sem);
1869
1870         return rc;
1871 }
1872
1873 void ll_inode_invalidate_acl(struct inode *inode)
1874 {
1875         struct ll_sb_info *sbi = ll_i2sbi(inode);
1876         struct ll_inode_info *lli = ll_i2info(inode);
1877
1878         if (sbi->ll_remote) {
1879                 struct remote_acl *racl = lli->lli_remote_acl;
1880
1881                 LASSERT(!lli->lli_posix_acl);
1882                 if (racl) {
1883                         down(&racl->ra_update_sem);
1884                         spin_lock(&racl->ra_lock);
1885                         remote_acl_flush(lli->lli_remote_acl);
1886                         spin_unlock(&racl->ra_lock);
1887                         up(&racl->ra_update_sem);
1888                 }
1889         } else {
1890                 LASSERT(!lli->lli_remote_acl);
1891                 spin_lock(&lli->lli_lock);
1892                 posix_acl_release(lli->lli_posix_acl);
1893                 lli->lli_posix_acl = NULL;
1894                 spin_unlock(&lli->lli_lock);
1895         }
1896 }
1897
1898 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1899 {
1900         struct ll_inode_info *lli = ll_i2info(inode);
1901         struct lov_stripe_md *lsm = md->lsm;
1902         struct mds_body *body = md->body;
1903         struct mea *mea = md->mea;
1904         struct posix_acl *posix_acl = md->posix_acl;
1905         struct ll_sb_info *sbi = ll_i2sbi(inode);
1906         struct lustre_key *mkey = md->key;
1907         ENTRY;
1908
1909         LASSERT((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1910
1911         if (md->lsm && md->lsm->lsm_magic != LOV_MAGIC) {
1912                 /* check for default striping info for dir. */
1913                 LASSERT((mea != NULL) == ((body->valid & OBD_MD_FLDIREA) != 0));
1914         }
1915         
1916         if (lsm != NULL) {
1917                 LASSERT(lsm->lsm_object_gr > 0);
1918                 if (lli->lli_smd == NULL) {
1919                         lli->lli_smd = lsm;
1920                         lli->lli_maxbytes = lsm->lsm_maxbytes;
1921                         if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
1922                                 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
1923                 } else {
1924                         int i;
1925                         if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
1926                                 CERROR("lsm mismatch for inode %ld\n",
1927                                        inode->i_ino);
1928                                 CERROR("lli_smd:\n");
1929                                 dump_lsm(D_ERROR, lli->lli_smd);
1930                                 CERROR("lsm:\n");
1931                                 dump_lsm(D_ERROR, lsm);
1932                                 LBUG();
1933                         }
1934                         /* XXX FIXME -- We should decide on a safer (atomic) and
1935                          * more elegant way to update the lsm */
1936                         for (i = 0; i < lsm->lsm_stripe_count; i++) {
1937                                 lli->lli_smd->lsm_oinfo[i].loi_id =
1938                                         lsm->lsm_oinfo[i].loi_id;
1939                                 lli->lli_smd->lsm_oinfo[i].loi_gr =
1940                                         lsm->lsm_oinfo[i].loi_gr;
1941                                 lli->lli_smd->lsm_oinfo[i].loi_ost_idx =
1942                                         lsm->lsm_oinfo[i].loi_ost_idx;
1943                                 lli->lli_smd->lsm_oinfo[i].loi_ost_gen =
1944                                         lsm->lsm_oinfo[i].loi_ost_gen;
1945                         }
1946                 }
1947                 /* bug 2844 - limit i_blksize for broken user-space apps */
1948                 LASSERTF(lsm->lsm_xfersize != 0, "%lu\n", lsm->lsm_xfersize);
1949                 inode->i_blksize = min(lsm->lsm_xfersize, LL_MAX_BLKSIZE);
1950                 if (lli->lli_smd != lsm)
1951                         obd_free_memmd(ll_i2dtexp(inode), &lsm);
1952         }
1953
1954         if (mea != NULL) {
1955                 if (lli->lli_mea == NULL) {
1956                         lli->lli_mea = mea;
1957                 } else {
1958                         if (memcmp(lli->lli_mea, mea, body->eadatasize)) {
1959                                 CERROR("mea mismatch for inode %lu\n",
1960                                         inode->i_ino);
1961                                 LBUG();
1962                         }
1963                 }
1964                 if (lli->lli_mea != mea)
1965                         obd_free_memmd(ll_i2mdexp(inode),
1966                                        (struct lov_stripe_md **) &mea);
1967         }
1968
1969         if (body->valid & OBD_MD_FID)
1970                 id_assign_fid(&lli->lli_id, &body->id1);
1971         
1972         if (body->valid & OBD_MD_FLID)
1973                 id_ino(&lli->lli_id) = id_ino(&body->id1);
1974
1975         if (body->valid & OBD_MD_FLGENER)
1976                 id_gen(&lli->lli_id) = id_gen(&body->id1);
1977
1978         /* local/remote ACL */
1979         if (sbi->ll_remote) {
1980                 LASSERT(md->posix_acl == NULL);
1981                 if (md->remote_perm) {
1982                         ll_remote_acl_update(inode, md->remote_perm);
1983                         OBD_FREE(md->remote_perm, sizeof(*md->remote_perm));
1984                         md->remote_perm = NULL;
1985                 }
1986         } else {
1987                 LASSERT(md->remote_perm == NULL);
1988                 spin_lock(&lli->lli_lock);
1989                 if (posix_acl != NULL) {
1990                         if (lli->lli_posix_acl != NULL)
1991                                 posix_acl_release(lli->lli_posix_acl);
1992                         lli->lli_posix_acl = posix_acl;
1993                 }
1994                 spin_unlock(&lli->lli_lock);
1995         }
1996
1997         if (body->valid & OBD_MD_FLID)
1998                 inode->i_ino = id_ino(&body->id1);
1999         if (body->valid & OBD_MD_FLGENER)
2000                 inode->i_generation = id_gen(&body->id1);
2001         if (body->valid & OBD_MD_FLATIME)
2002                 LTIME_S(inode->i_atime) = body->atime;
2003         if (body->valid & OBD_MD_FLMTIME &&
2004             body->mtime > LTIME_S(inode->i_mtime)) {
2005                 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %u\n",
2006                        inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
2007                 LTIME_S(inode->i_mtime) = body->mtime;
2008         }
2009         if (body->valid & OBD_MD_FLCTIME &&
2010             body->ctime > LTIME_S(inode->i_ctime))
2011                 LTIME_S(inode->i_ctime) = body->ctime;
2012         if (body->valid & OBD_MD_FLMODE) {
2013                 inode->i_mode = (inode->i_mode & S_IFMT) |
2014                         (body->mode & ~S_IFMT);
2015         }
2016         if (body->valid & OBD_MD_FLTYPE) {
2017                 inode->i_mode = (inode->i_mode & ~S_IFMT) |
2018                         (body->mode & S_IFMT);
2019         }
2020         if (body->valid & OBD_MD_FLUID)
2021                 inode->i_uid = body->uid;
2022         if (body->valid & OBD_MD_FLGID)
2023                 inode->i_gid = body->gid;
2024         if (body->valid & OBD_MD_FLFLAGS)
2025                 inode->i_flags = body->flags;
2026         if (body->valid & OBD_MD_FLNLINK)
2027                 inode->i_nlink = body->nlink;
2028         if (body->valid & OBD_MD_FLRDEV)
2029 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2030                 inode->i_rdev = body->rdev;
2031 #else
2032                 inode->i_rdev = old_decode_dev(body->rdev);
2033 #endif
2034         if (body->valid & OBD_MD_FLSIZE)
2035                 inode->i_size = body->size;
2036         if (body->valid & OBD_MD_FLBLOCKS)
2037                 inode->i_blocks = body->blocks;
2038
2039         if (body->valid & OBD_MD_FLSIZE)
2040                 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
2041
2042         if (mkey != NULL) {
2043                 LASSERT(body->valid & OBD_MD_FLKEY);
2044                 ll_crypto_init_inode_key(inode, mkey);  
2045         }
2046
2047 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
2048         inode->i_dev = (kdev_t)id_group(&lli->lli_id);
2049 #endif
2050         LASSERT(id_fid(&lli->lli_id) != 0);
2051 }
2052
2053 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
2054 static struct backing_dev_info ll_backing_dev_info = {
2055         .ra_pages       = 0,    /* No readahead */
2056         .memory_backed  = 0,    /* Does contribute to dirty memory */
2057 };
2058 #endif
2059
2060 void ll_read_inode2(struct inode *inode, void *opaque)
2061 {
2062         struct lustre_md *md = opaque;
2063         struct ll_inode_info *lli = ll_i2info(inode);
2064         ENTRY;
2065
2066         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
2067                inode->i_generation, inode);
2068
2069         ll_lli_init(lli);
2070
2071         LASSERT(!lli->lli_smd);
2072
2073         if (ll_i2sbi(inode)->ll_remote) {
2074                 lli->lli_remote_acl = remote_acl_alloc();
2075                 /* if failed alloc, nobody will be able to access this inode */
2076         }
2077
2078         /* Core attributes from the MDS first.  This is a new inode, and
2079          * the VFS doesn't zero times in the core inode so we have to do
2080          * it ourselves.  They will be overwritten by either MDS or OST
2081          * attributes - we just need to make sure they aren't newer. */
2082         LTIME_S(inode->i_mtime) = 0;
2083         LTIME_S(inode->i_atime) = 0;
2084         LTIME_S(inode->i_ctime) = 0;
2085
2086         inode->i_rdev = 0;
2087         ll_update_inode(inode, md);
2088
2089         /* OIDEBUG(inode); */
2090
2091         if (S_ISREG(inode->i_mode)) {
2092                 inode->i_op = &ll_file_inode_operations;
2093                 inode->i_fop = &ll_file_operations;
2094                 inode->i_mapping->a_ops = &ll_aops;
2095                 EXIT;
2096         } else if (S_ISDIR(inode->i_mode)) {
2097                 inode->i_op = &ll_dir_inode_operations;
2098                 inode->i_fop = &ll_dir_operations;
2099                 inode->i_mapping->a_ops = &ll_dir_aops;
2100                 EXIT;
2101         } else if (S_ISLNK(inode->i_mode)) {
2102                 inode->i_op = &ll_fast_symlink_inode_operations;
2103                 EXIT;
2104         } else {
2105                 inode->i_op = &ll_special_inode_operations;
2106
2107 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
2108                 init_special_inode(inode, inode->i_mode,
2109                                    kdev_t_to_nr(inode->i_rdev));
2110
2111                 /* initializing backing dev info. */
2112                 inode->i_mapping->backing_dev_info = &ll_backing_dev_info;
2113 #else
2114                 init_special_inode(inode, inode->i_mode, inode->i_rdev);
2115 #endif
2116                 lli->ll_save_ifop = inode->i_fop;
2117
2118                 if (S_ISCHR(inode->i_mode))
2119                         inode->i_fop = &ll_special_chr_inode_fops;
2120                 else if (S_ISBLK(inode->i_mode))
2121                         inode->i_fop = &ll_special_blk_inode_fops;
2122                 else if (S_ISFIFO(inode->i_mode))
2123                         inode->i_fop = &ll_special_fifo_inode_fops;
2124                 else if (S_ISSOCK(inode->i_mode))
2125                         inode->i_fop = &ll_special_sock_inode_fops;
2126
2127                 CWARN("saved %p, replaced with %p\n", lli->ll_save_ifop,
2128                       inode->i_fop);
2129
2130                 if (lli->ll_save_ifop->owner) {
2131                         CWARN("%p has owner %p\n", lli->ll_save_ifop,
2132                               lli->ll_save_ifop->owner);
2133                 }
2134                 EXIT;
2135         }
2136 }
2137
2138 void ll_delete_inode(struct inode *inode)
2139 {
2140         struct ll_sb_info *sbi = ll_i2sbi(inode);
2141         struct lustre_id id;
2142         int rc;
2143         ENTRY;
2144
2145         ll_inode2id(&id, inode);
2146
2147         rc = md_delete_inode(sbi->ll_md_exp, &id);
2148         if (rc) {
2149                 CERROR("md_delete_inode() failed, error %d\n", 
2150                        rc);
2151         }
2152
2153         clear_inode(inode);
2154         EXIT;
2155 }
2156
2157 int ll_iocontrol(struct inode *inode, struct file *file,
2158                  unsigned int cmd, unsigned long arg)
2159 {
2160         struct ll_sb_info *sbi = ll_i2sbi(inode);
2161         struct ptlrpc_request *req = NULL;
2162         int rc, flags = 0;
2163         ENTRY;
2164
2165         switch(cmd) {
2166         case EXT3_IOC_GETFLAGS: {
2167                 struct lustre_id id;
2168                 __u64 valid = OBD_MD_FLFLAGS;
2169                 struct mds_body *body;
2170
2171                 ll_inode2id(&id, inode);
2172                 rc = md_getattr(sbi->ll_md_exp, &id, valid, NULL, NULL, 0, 0,
2173                                 &req);
2174                 if (rc) {
2175                         CERROR("failure %d inode %lu\n", rc, inode->i_ino);
2176                         RETURN(-abs(rc));
2177                 }
2178
2179                 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
2180
2181                 if (body->flags & S_APPEND)
2182                         flags |= EXT3_APPEND_FL;
2183                 if (body->flags & S_IMMUTABLE)
2184                         flags |= EXT3_IMMUTABLE_FL;
2185                 if (body->flags & S_NOATIME)
2186                         flags |= EXT3_NOATIME_FL;
2187
2188                 ptlrpc_req_finished (req);
2189
2190                 RETURN(put_user(flags, (int *)arg));
2191         }
2192         case EXT3_IOC_SETFLAGS: {
2193                 struct mdc_op_data *op_data;
2194                 struct iattr attr;
2195                 struct obdo *oa;
2196                 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
2197
2198                 if (get_user(flags, (int *)arg))
2199                         RETURN(-EFAULT);
2200
2201                 oa = obdo_alloc();
2202                 if (!oa)
2203                         RETURN(-ENOMEM);
2204
2205                 OBD_ALLOC(op_data, sizeof(*op_data));
2206                 if (op_data == NULL) {
2207                         obdo_free(oa);
2208                         RETURN(-ENOMEM);
2209                 }
2210                 ll_prepare_mdc_data(op_data, inode, NULL, NULL, 0, 0);
2211
2212                 memset(&attr, 0x0, sizeof(attr));
2213                 attr.ia_attr_flags = flags;
2214                 attr.ia_valid |= ATTR_ATTR_FLAG;
2215
2216                 rc = md_setattr(sbi->ll_md_exp, op_data,
2217                                 &attr, NULL, 0, NULL, 0, NULL, 0, &req);
2218                 OBD_FREE(op_data, sizeof(*op_data));
2219                 if (rc) {
2220                         ptlrpc_req_finished(req);
2221                         if (rc != -EPERM && rc != -EACCES)
2222                                 CERROR("md_setattr fails: rc = %d\n", rc);
2223                         obdo_free(oa);
2224                         RETURN(rc);
2225                 }
2226                 ptlrpc_req_finished(req);
2227
2228                 oa->o_id = lsm->lsm_object_id;
2229                 oa->o_gr = lsm->lsm_object_gr;
2230                 oa->o_flags = flags;
2231                 *(obdo_id(oa)) = ll_i2info(inode)->lli_id;
2232                 oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS | OBD_MD_FLGROUP 
2233                               | OBD_MD_FLIFID;
2234
2235                 rc = obd_setattr(sbi->ll_dt_exp, oa, lsm, NULL);
2236                 obdo_free(oa);
2237                 if (rc) {
2238                         if (rc != -EPERM && rc != -EACCES)
2239                                 CERROR("md_setattr fails: rc = %d\n", rc);
2240                         RETURN(rc);
2241                 }
2242
2243                 if (flags & EXT3_APPEND_FL)
2244                         inode->i_flags |= S_APPEND;
2245                 else
2246                         inode->i_flags &= ~S_APPEND;
2247                 if (flags & EXT3_IMMUTABLE_FL)
2248                         inode->i_flags |= S_IMMUTABLE;
2249                 else
2250                         inode->i_flags &= ~S_IMMUTABLE;
2251                 if (flags & EXT3_NOATIME_FL)
2252                         inode->i_flags |= S_NOATIME;
2253                 else
2254                         inode->i_flags &= ~S_NOATIME;
2255
2256                 RETURN(0);
2257         }
2258         default:
2259                 RETURN(-ENOSYS);
2260         }
2261
2262         RETURN(0);
2263 }
2264
2265 /* this is only called in the case of forced umount. */
2266 void ll_umount_begin(struct super_block *sb)
2267 {
2268         struct ll_sb_info *sbi = ll_s2sbi(sb);
2269         struct obd_ioctl_data ioc_data = { 0 };
2270         struct obd_device *obd;
2271         ENTRY;
2272      
2273         CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2274                sb->s_count, atomic_read(&sb->s_active));
2275         
2276         obd = class_exp2obd(sbi->ll_md_exp);
2277         if (obd == NULL) {
2278                 CERROR("Invalid MDC connection handle "LPX64"\n",
2279                        sbi->ll_md_exp->exp_handle.h_cookie);
2280                 EXIT;
2281                 return;
2282         }
2283         obd->obd_no_recov = 1;
2284         obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2285                       sizeof(ioc_data), &ioc_data, NULL);
2286
2287         obd = class_exp2obd(sbi->ll_dt_exp);
2288         if (obd == NULL) {
2289                 CERROR("Invalid LOV connection handle "LPX64"\n",
2290                        sbi->ll_dt_exp->exp_handle.h_cookie);
2291                 EXIT;
2292                 return;
2293         }
2294
2295         obd->obd_no_recov = 1;
2296         obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2297                       sizeof(ioc_data), &ioc_data, NULL);
2298
2299         /*
2300          * really, we'd like to wait until there are no requests outstanding,
2301          * and then continue.  For now, we just invalidate the requests,
2302          * schedule, and hope.
2303          */
2304         schedule();
2305
2306         EXIT;
2307 }
2308
2309 int ll_prep_inode(struct obd_export *dt_exp, struct obd_export *md_exp,
2310                   struct inode **inode, struct ptlrpc_request *req,
2311                   int offset, struct super_block *sb)
2312 {
2313         struct lustre_md md;
2314         int rc = 0;
2315
2316         rc = mdc_req2lustre_md(md_exp, req, offset, dt_exp, &md);
2317         if (rc)
2318                 RETURN(rc);
2319
2320         if (*inode) {
2321                 ll_update_inode(*inode, &md);
2322         } else {
2323                 LASSERT(sb);
2324                 *inode = ll_iget(sb, id_ino(&md.body->id1), &md);
2325                 if (*inode == NULL || is_bad_inode(*inode)) {
2326                         /* free the lsm if we allocated one above */
2327                         if (md.lsm != NULL)
2328                                 obd_free_memmd(dt_exp, &md.lsm);
2329                         if (md.mea != NULL)
2330                                 obd_free_memmd(md_exp,
2331                                                (struct lov_stripe_md**)&md.mea);
2332                         rc = -ENOMEM;
2333                         CERROR("new_inode -fatal: rc %d\n", rc);
2334                 }
2335         }
2336
2337         RETURN(rc);
2338 }
2339
2340 int ll_show_options(struct seq_file *m, struct vfsmount *mnt)
2341 {
2342         struct ll_sb_info *sbi = ll_s2sbi(mnt->mnt_sb);
2343         struct lustre_mount_data *lmd = sbi->ll_lmd;
2344
2345         if (lmd) {
2346                 seq_printf(m, ",mds_sec=%s,oss_sec=%s",
2347                            lmd->lmd_mds_security, lmd->lmd_oss_security);
2348         }
2349         seq_printf(m, ",%s", sbi->ll_remote ? "remote" : "local");
2350         if (sbi->ll_remote && lmd)
2351                 seq_printf(m, ",nllu=%u:%u", lmd->lmd_nllu, lmd->lmd_nllg);
2352
2353         if (lmd && lmd->lmd_pag)
2354                 seq_printf(m, ",pag");
2355
2356         return 0;
2357 }
2358
2359 int ll_get_fid(struct obd_export *exp, struct lustre_id *idp,
2360                char *filename, struct lustre_id *ret)
2361 {
2362         struct ptlrpc_request *request = NULL;
2363         struct mds_body *body;
2364         int rc;
2365
2366         rc = md_getattr_lock(exp, idp, filename, strlen(filename) + 1,
2367                              OBD_MD_FID, 0, &request);
2368         if (rc < 0) {
2369                 CDEBUG(D_INFO, "md_getattr_lock failed on %s: rc %d\n",
2370                        filename, rc);
2371                 return rc;
2372         }
2373
2374         body = lustre_msg_buf(request->rq_repmsg, 0, sizeof(*body));
2375         LASSERT(body != NULL);
2376         LASSERT_REPSWABBED(request, 0);
2377
2378         *ret = body->id1;
2379         ptlrpc_req_finished(request);
2380
2381         return rc;
2382 }
2383 int ll_flush_cred(struct inode *inode)
2384 {
2385         struct ll_sb_info *sbi = ll_i2sbi(inode);
2386         int rc = 0;
2387
2388         /* XXX to avoid adding api, we simply use set_info() interface
2389          * to notify underlying obds. set_info() is more like a ioctl() now...
2390          */
2391         if (sbi->ll_md_exp) {
2392                 rc = obd_set_info(sbi->ll_md_exp,
2393                                   strlen("flush_cred"), "flush_cred",
2394                                   0, NULL);
2395                 if (rc)
2396                         return rc;
2397         }
2398
2399         if (sbi->ll_dt_exp) {
2400                 rc = obd_set_info(sbi->ll_dt_exp,
2401                                   strlen("flush_cred"), "flush_cred",
2402                                   0, NULL);
2403                 if (rc)
2404                         return rc;
2405         }
2406
2407         return rc;
2408 }