Whamcloud - gitweb
LU-11304 misc: update all url links to whamcloud
[fs/lustre-release.git] / lustre / llite / llite_lib.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2016, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * lustre/llite/llite_lib.c
33  *
34  * Lustre Light Super operations
35  */
36
37 #define DEBUG_SUBSYSTEM S_LLITE
38
39 #include <linux/module.h>
40 #include <linux/statfs.h>
41 #include <linux/time.h>
42 #include <linux/types.h>
43 #include <linux/version.h>
44 #include <linux/mm.h>
45 #include <linux/user_namespace.h>
46 #ifdef HAVE_UIDGID_HEADER
47 # include <linux/uidgid.h>
48 #endif
49 #include <linux/security.h>
50
51 #include <uapi/linux/lustre_ioctl.h>
52 #include <lustre_ha.h>
53 #include <lustre_dlm.h>
54 #include <lprocfs_status.h>
55 #include <lustre_disk.h>
56 #include <uapi/linux/lustre_param.h>
57 #include <lustre_log.h>
58 #include <cl_object.h>
59 #include <obd_cksum.h>
60 #include "llite_internal.h"
61
62 struct kmem_cache *ll_file_data_slab;
63
64 #ifndef log2
65 #define log2(n) ffz(~(n))
66 #endif
67
68 static struct ll_sb_info *ll_init_sbi(void)
69 {
70         struct ll_sb_info *sbi = NULL;
71         unsigned long pages;
72         unsigned long lru_page_max;
73         struct sysinfo si;
74         class_uuid_t uuid;
75         int i;
76         ENTRY;
77
78         OBD_ALLOC_PTR(sbi);
79         if (sbi == NULL)
80                 RETURN(NULL);
81
82         spin_lock_init(&sbi->ll_lock);
83         mutex_init(&sbi->ll_lco.lco_lock);
84         spin_lock_init(&sbi->ll_pp_extent_lock);
85         spin_lock_init(&sbi->ll_process_lock);
86         sbi->ll_rw_stats_on = 0;
87
88         si_meminfo(&si);
89         pages = si.totalram - si.totalhigh;
90         lru_page_max = pages / 2;
91
92         /* initialize ll_cache data */
93         sbi->ll_cache = cl_cache_init(lru_page_max);
94         if (sbi->ll_cache == NULL) {
95                 OBD_FREE(sbi, sizeof(*sbi));
96                 RETURN(NULL);
97         }
98
99         sbi->ll_ra_info.ra_max_pages_per_file = min(pages / 32,
100                                            SBI_DEFAULT_READAHEAD_MAX);
101         sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file;
102         sbi->ll_ra_info.ra_max_read_ahead_whole_pages = -1;
103
104         ll_generate_random_uuid(uuid);
105         class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
106         CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
107
108         sbi->ll_flags |= LL_SBI_VERBOSE;
109 #ifdef ENABLE_CHECKSUM
110         sbi->ll_flags |= LL_SBI_CHECKSUM;
111 #endif
112
113 #ifdef HAVE_LRU_RESIZE_SUPPORT
114         sbi->ll_flags |= LL_SBI_LRU_RESIZE;
115 #endif
116         sbi->ll_flags |= LL_SBI_LAZYSTATFS;
117
118         for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
119                 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
120                                pp_r_hist.oh_lock);
121                 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
122                                pp_w_hist.oh_lock);
123         }
124
125         /* metadata statahead is enabled by default */
126         sbi->ll_sa_running_max = LL_SA_RUNNING_DEF;
127         sbi->ll_sa_max = LL_SA_RPC_DEF;
128         atomic_set(&sbi->ll_sa_total, 0);
129         atomic_set(&sbi->ll_sa_wrong, 0);
130         atomic_set(&sbi->ll_sa_running, 0);
131         atomic_set(&sbi->ll_agl_total, 0);
132         sbi->ll_flags |= LL_SBI_AGL_ENABLED;
133         sbi->ll_flags |= LL_SBI_FAST_READ;
134
135         /* root squash */
136         sbi->ll_squash.rsi_uid = 0;
137         sbi->ll_squash.rsi_gid = 0;
138         INIT_LIST_HEAD(&sbi->ll_squash.rsi_nosquash_nids);
139         init_rwsem(&sbi->ll_squash.rsi_sem);
140
141         RETURN(sbi);
142 }
143
144 static void ll_free_sbi(struct super_block *sb)
145 {
146         struct ll_sb_info *sbi = ll_s2sbi(sb);
147         ENTRY;
148
149         if (sbi != NULL) {
150                 if (!list_empty(&sbi->ll_squash.rsi_nosquash_nids))
151                         cfs_free_nidlist(&sbi->ll_squash.rsi_nosquash_nids);
152                 if (sbi->ll_cache != NULL) {
153                         cl_cache_decref(sbi->ll_cache);
154                         sbi->ll_cache = NULL;
155                 }
156                 OBD_FREE(sbi, sizeof(*sbi));
157         }
158         EXIT;
159 }
160
161 static inline int obd_connect_has_secctx(struct obd_connect_data *data)
162 {
163         return data->ocd_connect_flags & OBD_CONNECT_FLAGS2 &&
164                data->ocd_connect_flags2 & OBD_CONNECT2_FILE_SECCTX;
165 }
166
167 static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
168                                     struct vfsmount *mnt)
169 {
170         struct inode *root = NULL;
171         struct ll_sb_info *sbi = ll_s2sbi(sb);
172         struct obd_device *obd;
173         struct obd_statfs *osfs = NULL;
174         struct ptlrpc_request *request = NULL;
175         struct obd_connect_data *data = NULL;
176         struct obd_uuid *uuid;
177         struct md_op_data *op_data;
178         struct lustre_md lmd;
179         u64 valid;
180         int size, err, checksum;
181         ENTRY;
182
183         obd = class_name2obd(md);
184         if (!obd) {
185                 CERROR("MD %s: not setup or attached\n", md);
186                 RETURN(-EINVAL);
187         }
188
189         OBD_ALLOC_PTR(data);
190         if (data == NULL)
191                 RETURN(-ENOMEM);
192
193         OBD_ALLOC_PTR(osfs);
194         if (osfs == NULL) {
195                 OBD_FREE_PTR(data);
196                 RETURN(-ENOMEM);
197         }
198
199         /* indicate the features supported by this client */
200         data->ocd_connect_flags = OBD_CONNECT_IBITS    | OBD_CONNECT_NODEVOH  |
201                                   OBD_CONNECT_ATTRFID  |
202                                   OBD_CONNECT_VERSION  | OBD_CONNECT_BRW_SIZE |
203                                   OBD_CONNECT_MDS_CAPA | OBD_CONNECT_OSS_CAPA |
204                                   OBD_CONNECT_CANCELSET | OBD_CONNECT_FID     |
205                                   OBD_CONNECT_AT       | OBD_CONNECT_LOV_V3   |
206                                   OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
207                                   OBD_CONNECT_64BITHASH |
208                                   OBD_CONNECT_EINPROGRESS |
209                                   OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
210                                   OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS|
211                                   OBD_CONNECT_MAX_EASIZE |
212                                   OBD_CONNECT_FLOCK_DEAD |
213                                   OBD_CONNECT_DISP_STRIPE | OBD_CONNECT_LFSCK |
214                                   OBD_CONNECT_OPEN_BY_FID |
215                                   OBD_CONNECT_DIR_STRIPE |
216                                   OBD_CONNECT_BULK_MBITS |
217                                   OBD_CONNECT_SUBTREE |
218                                   OBD_CONNECT_FLAGS2 | OBD_CONNECT_MULTIMODRPCS;
219
220         data->ocd_connect_flags2 = 0;
221
222 #ifdef HAVE_LRU_RESIZE_SUPPORT
223         if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
224                 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
225 #endif
226 #ifdef CONFIG_FS_POSIX_ACL
227         data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_UMASK |
228                                    OBD_CONNECT_LARGE_ACL;
229 #endif
230
231         if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
232                 /* flag mdc connection as lightweight, only used for test
233                  * purpose, use with care */
234                 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
235
236         data->ocd_ibits_known = MDS_INODELOCK_FULL;
237         data->ocd_version = LUSTRE_VERSION_CODE;
238
239         if (sb->s_flags & MS_RDONLY)
240                 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
241         if (sbi->ll_flags & LL_SBI_USER_XATTR)
242                 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
243
244 #ifdef MS_NOSEC
245         /* Setting this indicates we correctly support S_NOSEC (See kernel
246          * commit 9e1f1de02c2275d7172e18dc4e7c2065777611bf)
247          */
248         sb->s_flags |= MS_NOSEC;
249 #endif
250
251         if (sbi->ll_flags & LL_SBI_FLOCK)
252                 sbi->ll_fop = &ll_file_operations_flock;
253         else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
254                 sbi->ll_fop = &ll_file_operations;
255         else
256                 sbi->ll_fop = &ll_file_operations_noflock;
257
258         /* always ping even if server suppress_pings */
259         if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
260                 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
261
262 #if defined(HAVE_SECURITY_DENTRY_INIT_SECURITY) && defined(CONFIG_SECURITY)
263         data->ocd_connect_flags2 |= OBD_CONNECT2_FILE_SECCTX;
264 #endif /* HAVE_SECURITY_DENTRY_INIT_SECURITY */
265
266         data->ocd_brw_size = MD_MAX_BRW_SIZE;
267
268         err = obd_connect(NULL, &sbi->ll_md_exp, obd, &sbi->ll_sb_uuid, data, NULL);
269         if (err == -EBUSY) {
270                 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing "
271                                    "recovery, of which this client is not a "
272                                    "part. Please wait for recovery to complete,"
273                                    " abort, or time out.\n", md);
274                 GOTO(out, err);
275         } else if (err) {
276                 CERROR("cannot connect to %s: rc = %d\n", md, err);
277                 GOTO(out, err);
278         }
279
280         sbi->ll_md_exp->exp_connect_data = *data;
281
282         err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
283                            LUSTRE_SEQ_METADATA);
284         if (err) {
285                 CERROR("%s: Can't init metadata layer FID infrastructure, "
286                        "rc = %d\n", sbi->ll_md_exp->exp_obd->obd_name, err);
287                 GOTO(out_md, err);
288         }
289
290         /* For mount, we only need fs info from MDT0, and also in DNE, it
291          * can make sure the client can be mounted as long as MDT0 is
292          * avaible */
293         err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
294                         cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
295                         OBD_STATFS_FOR_MDT0);
296         if (err)
297                 GOTO(out_md_fid, err);
298
299         /* This needs to be after statfs to ensure connect has finished.
300          * Note that "data" does NOT contain the valid connect reply.
301          * If connecting to a 1.8 server there will be no LMV device, so
302          * we can access the MDC export directly and exp_connect_flags will
303          * be non-zero, but if accessing an upgraded 2.1 server it will
304          * have the correct flags filled in.
305          * XXX: fill in the LMV exp_connect_flags from MDC(s). */
306         valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
307         if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
308             valid != CLIENT_CONNECT_MDT_REQD) {
309                 char *buf;
310
311                 OBD_ALLOC_WAIT(buf, PAGE_SIZE);
312                 obd_connect_flags2str(buf, PAGE_SIZE,
313                                       valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
314                 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
315                                    "feature(s) needed for correct operation "
316                                    "of this client (%s). Please upgrade "
317                                    "server or downgrade client.\n",
318                                    sbi->ll_md_exp->exp_obd->obd_name, buf);
319                 OBD_FREE(buf, PAGE_SIZE);
320                 GOTO(out_md_fid, err = -EPROTO);
321         }
322
323         size = sizeof(*data);
324         err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
325                            KEY_CONN_DATA,  &size, data);
326         if (err) {
327                 CERROR("%s: Get connect data failed: rc = %d\n",
328                        sbi->ll_md_exp->exp_obd->obd_name, err);
329                 GOTO(out_md_fid, err);
330         }
331
332         LASSERT(osfs->os_bsize);
333         sb->s_blocksize = osfs->os_bsize;
334         sb->s_blocksize_bits = log2(osfs->os_bsize);
335         sb->s_magic = LL_SUPER_MAGIC;
336         sb->s_maxbytes = MAX_LFS_FILESIZE;
337         sbi->ll_namelen = osfs->os_namelen;
338         sbi->ll_mnt.mnt = current->fs->root.mnt;
339
340         if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
341             !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
342                 LCONSOLE_INFO("Disabling user_xattr feature because "
343                               "it is not supported on the server\n");
344                 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
345         }
346
347         if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
348 #ifdef MS_POSIXACL
349                 sb->s_flags |= MS_POSIXACL;
350 #endif
351                 sbi->ll_flags |= LL_SBI_ACL;
352         } else {
353                 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
354 #ifdef MS_POSIXACL
355                 sb->s_flags &= ~MS_POSIXACL;
356 #endif
357                 sbi->ll_flags &= ~LL_SBI_ACL;
358         }
359
360         if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
361                 sbi->ll_flags |= LL_SBI_64BIT_HASH;
362
363         if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
364                 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
365
366         if (obd_connect_has_secctx(data))
367                 sbi->ll_flags |= LL_SBI_FILE_SECCTX;
368
369         if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
370                 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
371                         LCONSOLE_INFO("%s: disabling xattr cache due to "
372                                       "unknown maximum xattr size.\n", dt);
373                 } else if (!sbi->ll_xattr_cache_set) {
374                         /* If xattr_cache is already set (no matter 0 or 1)
375                          * during processing llog, it won't be enabled here. */
376                         sbi->ll_flags |= LL_SBI_XATTR_CACHE;
377                         sbi->ll_xattr_cache_enabled = 1;
378                 }
379         }
380
381         obd = class_name2obd(dt);
382         if (!obd) {
383                 CERROR("DT %s: not setup or attached\n", dt);
384                 GOTO(out_md_fid, err = -ENODEV);
385         }
386
387         /* pass client page size via ocd_grant_blkbits, the server should report
388          * back its backend blocksize for grant calculation purpose */
389         data->ocd_grant_blkbits = PAGE_SHIFT;
390
391         data->ocd_connect_flags = OBD_CONNECT_GRANT | OBD_CONNECT_VERSION |
392                                   OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
393                                   OBD_CONNECT_CANCELSET | OBD_CONNECT_FID |
394                                   OBD_CONNECT_SRVLOCK | OBD_CONNECT_TRUNCLOCK|
395                                   OBD_CONNECT_AT | OBD_CONNECT_OSS_CAPA |
396                                   OBD_CONNECT_VBR | OBD_CONNECT_FULL20 |
397                                   OBD_CONNECT_64BITHASH | OBD_CONNECT_MAXBYTES |
398                                   OBD_CONNECT_EINPROGRESS |
399                                   OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
400                                   OBD_CONNECT_LAYOUTLOCK |
401                                   OBD_CONNECT_PINGLESS | OBD_CONNECT_LFSCK |
402                                   OBD_CONNECT_BULK_MBITS;
403
404         data->ocd_connect_flags2 = 0;
405
406         if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_GRANT_PARAM))
407                 data->ocd_connect_flags |= OBD_CONNECT_GRANT_PARAM;
408
409         /* OBD_CONNECT_CKSUM should always be set, even if checksums are
410          * disabled by default, because it can still be enabled on the
411          * fly via /proc. As a consequence, we still need to come to an
412          * agreement on the supported algorithms at connect time */
413         data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
414
415         if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
416                 data->ocd_cksum_types = OBD_CKSUM_ADLER;
417         else
418                 data->ocd_cksum_types = cksum_types_supported_client();
419
420 #ifdef HAVE_LRU_RESIZE_SUPPORT
421         data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
422 #endif
423         /* always ping even if server suppress_pings */
424         if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
425                 data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
426
427         CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
428                "ocd_grant: %d\n", data->ocd_connect_flags,
429                data->ocd_version, data->ocd_grant);
430
431         obd->obd_upcall.onu_owner = &sbi->ll_lco;
432         obd->obd_upcall.onu_upcall = cl_ocd_update;
433
434         data->ocd_brw_size = DT_MAX_BRW_SIZE;
435
436         err = obd_connect(NULL, &sbi->ll_dt_exp, obd, &sbi->ll_sb_uuid, data,
437                           NULL);
438         if (err == -EBUSY) {
439                 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing "
440                                    "recovery, of which this client is not a "
441                                    "part.  Please wait for recovery to "
442                                    "complete, abort, or time out.\n", dt);
443                 GOTO(out_md, err);
444         } else if (err) {
445                 CERROR("%s: Cannot connect to %s: rc = %d\n",
446                        sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
447                 GOTO(out_md, err);
448         }
449
450         sbi->ll_dt_exp->exp_connect_data = *data;
451
452         /* Don't change value if it was specified in the config log */
453         if (sbi->ll_ra_info.ra_max_read_ahead_whole_pages == -1)
454                 sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
455                         max_t(unsigned long, SBI_DEFAULT_READAHEAD_WHOLE_MAX,
456                               (data->ocd_brw_size >> PAGE_SHIFT));
457
458         err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
459                            LUSTRE_SEQ_METADATA);
460         if (err) {
461                 CERROR("%s: Can't init data layer FID infrastructure, "
462                        "rc = %d\n", sbi->ll_dt_exp->exp_obd->obd_name, err);
463                 GOTO(out_dt, err);
464         }
465
466         mutex_lock(&sbi->ll_lco.lco_lock);
467         sbi->ll_lco.lco_flags = data->ocd_connect_flags;
468         sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
469         sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
470         mutex_unlock(&sbi->ll_lco.lco_lock);
471
472         fid_zero(&sbi->ll_root_fid);
473         err = md_get_root(sbi->ll_md_exp, get_mount_fileset(sb),
474                            &sbi->ll_root_fid);
475         if (err) {
476                 CERROR("cannot mds_connect: rc = %d\n", err);
477                 GOTO(out_lock_cn_cb, err);
478         }
479         if (!fid_is_sane(&sbi->ll_root_fid)) {
480                 CERROR("%s: Invalid root fid "DFID" during mount\n",
481                        sbi->ll_md_exp->exp_obd->obd_name,
482                        PFID(&sbi->ll_root_fid));
483                 GOTO(out_lock_cn_cb, err = -EINVAL);
484         }
485         CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
486
487         sb->s_op = &lustre_super_operations;
488 #ifdef HAVE_XATTR_HANDLER_FLAGS
489         sb->s_xattr = ll_xattr_handlers;
490 #endif
491 #if THREAD_SIZE >= 8192 /*b=17630*/
492         sb->s_export_op = &lustre_export_operations;
493 #endif
494
495         /* make root inode
496          * XXX: move this to after cbd setup? */
497         valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS | OBD_MD_FLMODEASIZE;
498         if (sbi->ll_flags & LL_SBI_ACL)
499                 valid |= OBD_MD_FLACL;
500
501         OBD_ALLOC_PTR(op_data);
502         if (op_data == NULL)
503                 GOTO(out_lock_cn_cb, err = -ENOMEM);
504
505         op_data->op_fid1 = sbi->ll_root_fid;
506         op_data->op_mode = 0;
507         op_data->op_valid = valid;
508
509         err = md_getattr(sbi->ll_md_exp, op_data, &request);
510
511         OBD_FREE_PTR(op_data);
512         if (err) {
513                 CERROR("%s: md_getattr failed for root: rc = %d\n",
514                        sbi->ll_md_exp->exp_obd->obd_name, err);
515                 GOTO(out_lock_cn_cb, err);
516         }
517
518         err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
519                                sbi->ll_md_exp, &lmd);
520         if (err) {
521                 CERROR("failed to understand root inode md: rc = %d\n", err);
522                 ptlrpc_req_finished(request);
523                 GOTO(out_lock_cn_cb, err);
524         }
525
526         LASSERT(fid_is_sane(&sbi->ll_root_fid));
527         root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
528                                             sbi->ll_flags & LL_SBI_32BIT_API),
529                        &lmd);
530         md_free_lustre_md(sbi->ll_md_exp, &lmd);
531         ptlrpc_req_finished(request);
532
533         if (IS_ERR(root)) {
534 #ifdef CONFIG_FS_POSIX_ACL
535                 if (lmd.posix_acl) {
536                         posix_acl_release(lmd.posix_acl);
537                         lmd.posix_acl = NULL;
538                 }
539 #endif
540                 err = IS_ERR(root) ? PTR_ERR(root) : -EBADF;
541                 root = NULL;
542                 CERROR("lustre_lite: bad iget4 for root\n");
543                 GOTO(out_root, err);
544         }
545
546         checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
547         err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
548                                  KEY_CHECKSUM, sizeof(checksum), &checksum,
549                                  NULL);
550         if (err) {
551                 CERROR("%s: Set checksum failed: rc = %d\n",
552                        sbi->ll_dt_exp->exp_obd->obd_name, err);
553                 GOTO(out_root, err);
554         }
555         cl_sb_init(sb);
556
557         err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CACHE_SET),
558                                  KEY_CACHE_SET, sizeof(*sbi->ll_cache),
559                                  sbi->ll_cache, NULL);
560         if (err) {
561                 CERROR("%s: Set cache_set failed: rc = %d\n",
562                        sbi->ll_dt_exp->exp_obd->obd_name, err);
563                 GOTO(out_root, err);
564         }
565
566         sb->s_root = d_make_root(root);
567         if (sb->s_root == NULL) {
568                 CERROR("%s: can't make root dentry\n",
569                         ll_get_fsname(sb, NULL, 0));
570                 GOTO(out_root, err = -ENOMEM);
571         }
572 #ifdef HAVE_DCACHE_LOCK
573         sb->s_root->d_op = &ll_d_ops;
574 #endif
575
576         sbi->ll_sdev_orig = sb->s_dev;
577
578         /* We set sb->s_dev equal on all lustre clients in order to support
579          * NFS export clustering.  NFSD requires that the FSID be the same
580          * on all clients. */
581         /* s_dev is also used in lt_compare() to compare two fs, but that is
582          * only a node-local comparison. */
583         uuid = obd_get_uuid(sbi->ll_md_exp);
584         if (uuid != NULL)
585                 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
586
587         if (data != NULL)
588                 OBD_FREE_PTR(data);
589         if (osfs != NULL)
590                 OBD_FREE_PTR(osfs);
591
592         if (sbi->ll_proc_root != NULL) {
593                 err = lprocfs_ll_register_obd(sb, dt);
594                 if (err < 0) {
595                         CERROR("%s: could not register %s in llite: rc = %d\n",
596                                dt, ll_get_fsname(sb, NULL, 0), err);
597                         err = 0;
598                 }
599                 err = lprocfs_ll_register_obd(sb, md);
600                 if (err < 0) {
601                         CERROR("%s: could not register %s in llite: rc = %d\n",
602                                md, ll_get_fsname(sb, NULL, 0), err);
603                         err = 0;
604                 }
605         }
606
607         RETURN(err);
608 out_root:
609         if (root)
610                 iput(root);
611 out_lock_cn_cb:
612         obd_fid_fini(sbi->ll_dt_exp->exp_obd);
613 out_dt:
614         obd_disconnect(sbi->ll_dt_exp);
615         sbi->ll_dt_exp = NULL;
616 out_md_fid:
617         obd_fid_fini(sbi->ll_md_exp->exp_obd);
618 out_md:
619         obd_disconnect(sbi->ll_md_exp);
620         sbi->ll_md_exp = NULL;
621 out:
622         if (data != NULL)
623                 OBD_FREE_PTR(data);
624         if (osfs != NULL)
625                 OBD_FREE_PTR(osfs);
626         return err;
627 }
628
629 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
630 {
631         int size, rc;
632
633         size = sizeof(*lmmsize);
634         rc = obd_get_info(NULL, sbi->ll_dt_exp, sizeof(KEY_MAX_EASIZE),
635                           KEY_MAX_EASIZE, &size, lmmsize);
636         if (rc != 0) {
637                 CERROR("%s: cannot get max LOV EA size: rc = %d\n",
638                        sbi->ll_dt_exp->exp_obd->obd_name, rc);
639                 RETURN(rc);
640         }
641
642         size = sizeof(int);
643         rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
644                           KEY_MAX_EASIZE, &size, lmmsize);
645         if (rc)
646                 CERROR("Get max mdsize error rc %d\n", rc);
647
648         RETURN(rc);
649 }
650
651 /**
652  * Get the value of the default_easize parameter.
653  *
654  * \see client_obd::cl_default_mds_easize
655  *
656  * \param[in] sbi       superblock info for this filesystem
657  * \param[out] lmmsize  pointer to storage location for value
658  *
659  * \retval 0            on success
660  * \retval negative     negated errno on failure
661  */
662 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
663 {
664         int size, rc;
665
666         size = sizeof(int);
667         rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
668                          KEY_DEFAULT_EASIZE, &size, lmmsize);
669         if (rc)
670                 CERROR("Get default mdsize error rc %d\n", rc);
671
672         RETURN(rc);
673 }
674
675 /**
676  * Set the default_easize parameter to the given value.
677  *
678  * \see client_obd::cl_default_mds_easize
679  *
680  * \param[in] sbi       superblock info for this filesystem
681  * \param[in] lmmsize   the size to set
682  *
683  * \retval 0            on success
684  * \retval negative     negated errno on failure
685  */
686 int ll_set_default_mdsize(struct ll_sb_info *sbi, int lmmsize)
687 {
688         int rc;
689
690         if (lmmsize < sizeof(struct lov_mds_md) ||
691             lmmsize > OBD_MAX_DEFAULT_EA_SIZE)
692                 return -EINVAL;
693
694         rc = obd_set_info_async(NULL, sbi->ll_md_exp,
695                                 sizeof(KEY_DEFAULT_EASIZE), KEY_DEFAULT_EASIZE,
696                                 sizeof(int), &lmmsize, NULL);
697
698         RETURN(rc);
699 }
700
701 static void client_common_put_super(struct super_block *sb)
702 {
703         struct ll_sb_info *sbi = ll_s2sbi(sb);
704         ENTRY;
705
706         cl_sb_fini(sb);
707
708         obd_fid_fini(sbi->ll_dt_exp->exp_obd);
709         obd_disconnect(sbi->ll_dt_exp);
710         sbi->ll_dt_exp = NULL;
711
712         lprocfs_ll_unregister_mountpoint(sbi);
713
714         obd_fid_fini(sbi->ll_md_exp->exp_obd);
715         obd_disconnect(sbi->ll_md_exp);
716         sbi->ll_md_exp = NULL;
717
718         EXIT;
719 }
720
721 void ll_kill_super(struct super_block *sb)
722 {
723         struct ll_sb_info *sbi;
724         ENTRY;
725
726         /* not init sb ?*/
727         if (!(sb->s_flags & MS_ACTIVE))
728                 return;
729
730         sbi = ll_s2sbi(sb);
731         /* we need restore s_dev from changed for clustred NFS before put_super
732          * because new kernels have cached s_dev and change sb->s_dev in
733          * put_super not affected real removing devices */
734         if (sbi) {
735                 sb->s_dev = sbi->ll_sdev_orig;
736                 sbi->ll_umounting = 1;
737
738                 /* wait running statahead threads to quit */
739                 while (atomic_read(&sbi->ll_sa_running) > 0) {
740                         set_current_state(TASK_UNINTERRUPTIBLE);
741                         schedule_timeout(msecs_to_jiffies(MSEC_PER_SEC >> 3));
742                 }
743         }
744
745         EXIT;
746 }
747
748 static inline int ll_set_opt(const char *opt, char *data, int fl)
749 {
750         if (strncmp(opt, data, strlen(opt)) != 0)
751                 return(0);
752         else
753                 return(fl);
754 }
755
756 /* non-client-specific mount options are parsed in lmd_parse */
757 static int ll_options(char *options, int *flags)
758 {
759         int tmp;
760         char *s1 = options, *s2;
761         ENTRY;
762
763         if (!options)
764                 RETURN(0);
765
766         CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
767
768         while (*s1) {
769                 CDEBUG(D_SUPER, "next opt=%s\n", s1);
770                 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
771                 if (tmp) {
772                         *flags |= tmp;
773                         goto next;
774                 }
775                 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
776                 if (tmp) {
777                         *flags |= tmp;
778                         goto next;
779                 }
780                 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
781                 if (tmp) {
782                         *flags |= tmp;
783                         goto next;
784                 }
785                 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
786                 if (tmp) {
787                         *flags &= ~tmp;
788                         goto next;
789                 }
790                 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
791                 if (tmp) {
792                         *flags |= tmp;
793                         goto next;
794                 }
795                 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
796                 if (tmp) {
797                         *flags &= ~tmp;
798                         goto next;
799                 }
800                 tmp = ll_set_opt("context", s1, 1);
801                 if (tmp)
802                         goto next;
803                 tmp = ll_set_opt("fscontext", s1, 1);
804                 if (tmp)
805                         goto next;
806                 tmp = ll_set_opt("defcontext", s1, 1);
807                 if (tmp)
808                         goto next;
809                 tmp = ll_set_opt("rootcontext", s1, 1);
810                 if (tmp)
811                         goto next;
812                 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
813                 if (tmp) {
814                         *flags |= tmp;
815                         goto next;
816                 }
817                 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
818                 if (tmp) {
819                         *flags &= ~tmp;
820                         goto next;
821                 }
822
823                 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
824                 if (tmp) {
825                         *flags |= tmp;
826                         goto next;
827                 }
828                 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
829                 if (tmp) {
830                         *flags &= ~tmp;
831                         goto next;
832                 }
833                 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
834                 if (tmp) {
835                         *flags |= tmp;
836                         goto next;
837                 }
838                 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
839                 if (tmp) {
840                         *flags &= ~tmp;
841                         goto next;
842                 }
843                 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
844                 if (tmp) {
845                         *flags |= tmp;
846                         goto next;
847                 }
848                 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
849                 if (tmp) {
850                         *flags &= ~tmp;
851                         goto next;
852                 }
853                 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
854                 if (tmp) {
855                         *flags |= tmp;
856                         goto next;
857                 }
858                 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
859                 if (tmp) {
860                         *flags |= tmp;
861                         goto next;
862                 }
863                 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
864                 if (tmp) {
865                         *flags &= ~tmp;
866                         goto next;
867                 }
868                 tmp = ll_set_opt("always_ping", s1, LL_SBI_ALWAYS_PING);
869                 if (tmp) {
870                         *flags |= tmp;
871                         goto next;
872                 }
873                 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
874                                    s1);
875                 RETURN(-EINVAL);
876
877 next:
878                 /* Find next opt */
879                 s2 = strchr(s1, ',');
880                 if (s2 == NULL)
881                         break;
882                 s1 = s2 + 1;
883         }
884         RETURN(0);
885 }
886
887 void ll_lli_init(struct ll_inode_info *lli)
888 {
889         lli->lli_inode_magic = LLI_INODE_MAGIC;
890         lli->lli_flags = 0;
891         spin_lock_init(&lli->lli_lock);
892         lli->lli_posix_acl = NULL;
893         /* Do not set lli_fid, it has been initialized already. */
894         fid_zero(&lli->lli_pfid);
895         lli->lli_mds_read_och = NULL;
896         lli->lli_mds_write_och = NULL;
897         lli->lli_mds_exec_och = NULL;
898         lli->lli_open_fd_read_count = 0;
899         lli->lli_open_fd_write_count = 0;
900         lli->lli_open_fd_exec_count = 0;
901         mutex_init(&lli->lli_och_mutex);
902         spin_lock_init(&lli->lli_agl_lock);
903         spin_lock_init(&lli->lli_layout_lock);
904         ll_layout_version_set(lli, CL_LAYOUT_GEN_NONE);
905         lli->lli_clob = NULL;
906
907         init_rwsem(&lli->lli_xattrs_list_rwsem);
908         mutex_init(&lli->lli_xattrs_enq_lock);
909
910         LASSERT(lli->lli_vfs_inode.i_mode != 0);
911         if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
912                 mutex_init(&lli->lli_readdir_mutex);
913                 lli->lli_opendir_key = NULL;
914                 lli->lli_sai = NULL;
915                 spin_lock_init(&lli->lli_sa_lock);
916                 lli->lli_opendir_pid = 0;
917                 lli->lli_sa_enabled = 0;
918                 lli->lli_def_stripe_offset = -1;
919         } else {
920                 mutex_init(&lli->lli_size_mutex);
921                 lli->lli_symlink_name = NULL;
922                 init_rwsem(&lli->lli_trunc_sem);
923                 range_lock_tree_init(&lli->lli_write_tree);
924                 init_rwsem(&lli->lli_glimpse_sem);
925                 lli->lli_glimpse_time = 0;
926                 INIT_LIST_HEAD(&lli->lli_agl_list);
927                 lli->lli_agl_index = 0;
928                 lli->lli_async_rc = 0;
929         }
930         mutex_init(&lli->lli_layout_mutex);
931         memset(lli->lli_jobid, 0, LUSTRE_JOBID_SIZE);
932 }
933
934 #ifndef HAVE_SUPER_SETUP_BDI_NAME
935
936 #define LSI_BDI_INITIALIZED     0x00400000
937
938 #ifndef HAVE_BDI_CAP_MAP_COPY
939 # define BDI_CAP_MAP_COPY       0
940 #endif
941
942 #define MAX_STRING_SIZE 128
943
944 static int super_setup_bdi_name(struct super_block *sb, char *fmt, ...)
945 {
946         struct  lustre_sb_info *lsi = s2lsi(sb);
947         char buf[MAX_STRING_SIZE];
948         va_list args;
949         int err;
950
951         err = bdi_init(&lsi->lsi_bdi);
952         if (err)
953                 return err;
954
955         lsi->lsi_flags |= LSI_BDI_INITIALIZED;
956         lsi->lsi_bdi.capabilities = BDI_CAP_MAP_COPY;
957         lsi->lsi_bdi.name = "lustre";
958         va_start(args, fmt);
959         vsnprintf(buf, MAX_STRING_SIZE, fmt, args);
960         va_end(args);
961         err = bdi_register(&lsi->lsi_bdi, NULL, "%s", buf);
962         va_end(args);
963         if (!err)
964                 sb->s_bdi = &lsi->lsi_bdi;
965
966         return err;
967 }
968 #endif /* !HAVE_SUPER_SETUP_BDI_NAME */
969
970 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
971 {
972         struct  lustre_profile *lprof = NULL;
973         struct  lustre_sb_info *lsi = s2lsi(sb);
974         struct  ll_sb_info *sbi;
975         char    *dt = NULL, *md = NULL;
976         char    *profilenm = get_profile_name(sb);
977         struct config_llog_instance *cfg;
978         /* %p for void* in printf needs 16+2 characters: 0xffffffffffffffff */
979         const int instlen = sizeof(cfg->cfg_instance) * 2 + 2;
980         int     md_len = 0;
981         int     dt_len = 0;
982         int     err;
983         ENTRY;
984
985         CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
986
987         OBD_ALLOC_PTR(cfg);
988         if (cfg == NULL)
989                 RETURN(-ENOMEM);
990
991         try_module_get(THIS_MODULE);
992
993         /* client additional sb info */
994         lsi->lsi_llsbi = sbi = ll_init_sbi();
995         if (!sbi) {
996                 module_put(THIS_MODULE);
997                 OBD_FREE_PTR(cfg);
998                 RETURN(-ENOMEM);
999         }
1000
1001         err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
1002         if (err)
1003                 GOTO(out_free, err);
1004
1005         err = super_setup_bdi_name(sb, "lustre-%p", sb);
1006         if (err)
1007                 GOTO(out_free, err);
1008
1009 #ifndef HAVE_DCACHE_LOCK
1010         /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
1011         sb->s_d_op = &ll_d_ops;
1012 #endif
1013
1014         /* Call lprocfs_ll_register_mountpoint() before lustre_process_log()
1015          * so that "llite.*.*" params can be processed correctly. */
1016         if (proc_lustre_fs_root != NULL) {
1017                 err = lprocfs_ll_register_mountpoint(proc_lustre_fs_root, sb);
1018                 if (err < 0) {
1019                         CERROR("%s: could not register mountpoint in llite: "
1020                                "rc = %d\n", ll_get_fsname(sb, NULL, 0), err);
1021                         err = 0;
1022                 }
1023         }
1024
1025         /* Generate a string unique to this super, in case some joker tries
1026            to mount the same fs at two mount points.
1027            Use the address of the super itself.*/
1028         cfg->cfg_instance = sb;
1029         cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
1030         cfg->cfg_callback = class_config_llog_handler;
1031         cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
1032         /* set up client obds */
1033         err = lustre_process_log(sb, profilenm, cfg);
1034         if (err < 0)
1035                 GOTO(out_proc, err);
1036
1037         /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
1038         lprof = class_get_profile(profilenm);
1039         if (lprof == NULL) {
1040                 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be"
1041                                    " read from the MGS.  Does that filesystem "
1042                                    "exist?\n", profilenm);
1043                 GOTO(out_proc, err = -EINVAL);
1044         }
1045         CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
1046                lprof->lp_md, lprof->lp_dt);
1047
1048         dt_len = strlen(lprof->lp_dt) + instlen + 2;
1049         OBD_ALLOC(dt, dt_len);
1050         if (!dt)
1051                 GOTO(out_proc, err = -ENOMEM);
1052         snprintf(dt, dt_len - 1, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
1053
1054         md_len = strlen(lprof->lp_md) + instlen + 2;
1055         OBD_ALLOC(md, md_len);
1056         if (!md)
1057                 GOTO(out_proc, err = -ENOMEM);
1058         snprintf(md, md_len - 1, "%s-%p", lprof->lp_md, cfg->cfg_instance);
1059
1060         /* connections, registrations, sb setup */
1061         err = client_common_fill_super(sb, md, dt, mnt);
1062         if (err < 0)
1063                 GOTO(out_proc, err);
1064
1065         sbi->ll_client_common_fill_super_succeeded = 1;
1066
1067 out_proc:
1068         if (err < 0)
1069                 lprocfs_ll_unregister_mountpoint(sbi);
1070 out_free:
1071         if (md)
1072                 OBD_FREE(md, md_len);
1073         if (dt)
1074                 OBD_FREE(dt, dt_len);
1075         if (lprof != NULL)
1076                 class_put_profile(lprof);
1077         if (err)
1078                 ll_put_super(sb);
1079         else if (sbi->ll_flags & LL_SBI_VERBOSE)
1080                 LCONSOLE_WARN("Mounted %s\n", profilenm);
1081
1082         OBD_FREE_PTR(cfg);
1083         RETURN(err);
1084 } /* ll_fill_super */
1085
1086 void ll_put_super(struct super_block *sb)
1087 {
1088         struct config_llog_instance cfg, params_cfg;
1089         struct obd_device *obd;
1090         struct lustre_sb_info *lsi = s2lsi(sb);
1091         struct ll_sb_info *sbi = ll_s2sbi(sb);
1092         char *profilenm = get_profile_name(sb);
1093         long ccc_count;
1094         int next, force = 1, rc = 0;
1095         ENTRY;
1096
1097         CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
1098
1099         cfg.cfg_instance = sb;
1100         lustre_end_log(sb, profilenm, &cfg);
1101
1102         params_cfg.cfg_instance = sb;
1103         lustre_end_log(sb, PARAMS_FILENAME, &params_cfg);
1104
1105         if (sbi->ll_md_exp) {
1106                 obd = class_exp2obd(sbi->ll_md_exp);
1107                 if (obd)
1108                         force = obd->obd_force;
1109         }
1110
1111         /* Wait for unstable pages to be committed to stable storage */
1112         if (force == 0) {
1113                 struct l_wait_info lwi = LWI_INTR(LWI_ON_SIGNAL_NOOP, NULL);
1114                 rc = l_wait_event(sbi->ll_cache->ccc_unstable_waitq,
1115                         atomic_long_read(&sbi->ll_cache->ccc_unstable_nr) == 0,
1116                         &lwi);
1117         }
1118
1119         ccc_count = atomic_long_read(&sbi->ll_cache->ccc_unstable_nr);
1120         if (force == 0 && rc != -EINTR)
1121                 LASSERTF(ccc_count == 0, "count: %li\n", ccc_count);
1122
1123
1124         /* We need to set force before the lov_disconnect in
1125            lustre_common_put_super, since l_d cleans up osc's as well. */
1126         if (force) {
1127                 next = 0;
1128                 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
1129                                                      &next)) != NULL) {
1130                         obd->obd_force = force;
1131                 }
1132         }
1133
1134         if (sbi->ll_client_common_fill_super_succeeded) {
1135                 /* Only if client_common_fill_super succeeded */
1136                 client_common_put_super(sb);
1137         }
1138
1139         next = 0;
1140         while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)) !=NULL) {
1141                 class_manual_cleanup(obd);
1142         }
1143
1144         if (sbi->ll_flags & LL_SBI_VERBOSE)
1145                 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
1146
1147         if (profilenm)
1148                 class_del_profile(profilenm);
1149
1150 #ifndef HAVE_SUPER_SETUP_BDI_NAME
1151         if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
1152                 bdi_destroy(&lsi->lsi_bdi);
1153                 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
1154         }
1155 #endif
1156
1157         ll_free_sbi(sb);
1158         lsi->lsi_llsbi = NULL;
1159
1160         lustre_common_put_super(sb);
1161
1162         cl_env_cache_purge(~0);
1163
1164         module_put(THIS_MODULE);
1165
1166         EXIT;
1167 } /* client_put_super */
1168
1169 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1170 {
1171         struct inode *inode = NULL;
1172
1173         /* NOTE: we depend on atomic igrab() -bzzz */
1174         lock_res_and_lock(lock);
1175         if (lock->l_resource->lr_lvb_inode) {
1176                 struct ll_inode_info * lli;
1177                 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1178                 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1179                         inode = igrab(lock->l_resource->lr_lvb_inode);
1180                 } else {
1181                         inode = lock->l_resource->lr_lvb_inode;
1182                         LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ?  D_INFO :
1183                                          D_WARNING, lock, "lr_lvb_inode %p is "
1184                                          "bogus: magic %08x",
1185                                          lock->l_resource->lr_lvb_inode,
1186                                          lli->lli_inode_magic);
1187                         inode = NULL;
1188                 }
1189         }
1190         unlock_res_and_lock(lock);
1191         return inode;
1192 }
1193
1194 void ll_dir_clear_lsm_md(struct inode *inode)
1195 {
1196         struct ll_inode_info *lli = ll_i2info(inode);
1197
1198         LASSERT(S_ISDIR(inode->i_mode));
1199
1200         if (lli->lli_lsm_md != NULL) {
1201                 lmv_free_memmd(lli->lli_lsm_md);
1202                 lli->lli_lsm_md = NULL;
1203         }
1204 }
1205
1206 static struct inode *ll_iget_anon_dir(struct super_block *sb,
1207                                       const struct lu_fid *fid,
1208                                       struct lustre_md *md)
1209 {
1210         struct ll_sb_info       *sbi = ll_s2sbi(sb);
1211         struct mdt_body         *body = md->body;
1212         struct inode            *inode;
1213         ino_t                   ino;
1214         ENTRY;
1215
1216         ino = cl_fid_build_ino(fid, sbi->ll_flags & LL_SBI_32BIT_API);
1217         inode = iget_locked(sb, ino);
1218         if (inode == NULL) {
1219                 CERROR("%s: failed get simple inode "DFID": rc = -ENOENT\n",
1220                        ll_get_fsname(sb, NULL, 0), PFID(fid));
1221                 RETURN(ERR_PTR(-ENOENT));
1222         }
1223
1224         if (inode->i_state & I_NEW) {
1225                 struct ll_inode_info *lli = ll_i2info(inode);
1226                 struct lmv_stripe_md *lsm = md->lmv;
1227
1228                 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1229                                 (body->mbo_mode & S_IFMT);
1230                 LASSERTF(S_ISDIR(inode->i_mode), "Not slave inode "DFID"\n",
1231                          PFID(fid));
1232
1233                 LTIME_S(inode->i_mtime) = 0;
1234                 LTIME_S(inode->i_atime) = 0;
1235                 LTIME_S(inode->i_ctime) = 0;
1236                 inode->i_rdev = 0;
1237
1238 #ifdef HAVE_BACKING_DEV_INFO
1239                 /* initializing backing dev info. */
1240                 inode->i_mapping->backing_dev_info =
1241                                                 &s2lsi(inode->i_sb)->lsi_bdi;
1242 #endif
1243                 inode->i_op = &ll_dir_inode_operations;
1244                 inode->i_fop = &ll_dir_operations;
1245                 lli->lli_fid = *fid;
1246                 ll_lli_init(lli);
1247
1248                 LASSERT(lsm != NULL);
1249                 /* master object FID */
1250                 lli->lli_pfid = body->mbo_fid1;
1251                 CDEBUG(D_INODE, "lli %p slave "DFID" master "DFID"\n",
1252                        lli, PFID(fid), PFID(&lli->lli_pfid));
1253                 unlock_new_inode(inode);
1254         }
1255
1256         RETURN(inode);
1257 }
1258
1259 static int ll_init_lsm_md(struct inode *inode, struct lustre_md *md)
1260 {
1261         struct lu_fid *fid;
1262         struct lmv_stripe_md *lsm = md->lmv;
1263         int i;
1264
1265         LASSERT(lsm != NULL);
1266         /* XXX sigh, this lsm_root initialization should be in
1267          * LMV layer, but it needs ll_iget right now, so we
1268          * put this here right now. */
1269         for (i = 0; i < lsm->lsm_md_stripe_count; i++) {
1270                 fid = &lsm->lsm_md_oinfo[i].lmo_fid;
1271                 LASSERT(lsm->lsm_md_oinfo[i].lmo_root == NULL);
1272                 /* Unfortunately ll_iget will call ll_update_inode,
1273                  * where the initialization of slave inode is slightly
1274                  * different, so it reset lsm_md to NULL to avoid
1275                  * initializing lsm for slave inode. */
1276                 /* For migrating inode, master stripe and master object will
1277                  * be same, so we only need assign this inode */
1278                 if (lsm->lsm_md_hash_type & LMV_HASH_FLAG_MIGRATION && i == 0)
1279                         lsm->lsm_md_oinfo[i].lmo_root = inode;
1280                 else
1281                         lsm->lsm_md_oinfo[i].lmo_root =
1282                                 ll_iget_anon_dir(inode->i_sb, fid, md);
1283
1284                 if (IS_ERR(lsm->lsm_md_oinfo[i].lmo_root)) {
1285                         int rc = PTR_ERR(lsm->lsm_md_oinfo[i].lmo_root);
1286
1287                         lsm->lsm_md_oinfo[i].lmo_root = NULL;
1288                         return rc;
1289                 }
1290         }
1291
1292         return 0;
1293 }
1294
1295 static inline int lli_lsm_md_eq(const struct lmv_stripe_md *lsm_md1,
1296                                 const struct lmv_stripe_md *lsm_md2)
1297 {
1298         return lsm_md1->lsm_md_magic == lsm_md2->lsm_md_magic &&
1299                lsm_md1->lsm_md_stripe_count == lsm_md2->lsm_md_stripe_count &&
1300                lsm_md1->lsm_md_master_mdt_index ==
1301                                         lsm_md2->lsm_md_master_mdt_index &&
1302                lsm_md1->lsm_md_hash_type == lsm_md2->lsm_md_hash_type &&
1303                lsm_md1->lsm_md_layout_version ==
1304                                         lsm_md2->lsm_md_layout_version &&
1305                strcmp(lsm_md1->lsm_md_pool_name,
1306                       lsm_md2->lsm_md_pool_name) == 0;
1307 }
1308
1309 static int ll_update_lsm_md(struct inode *inode, struct lustre_md *md)
1310 {
1311         struct ll_inode_info *lli = ll_i2info(inode);
1312         struct lmv_stripe_md *lsm = md->lmv;
1313         int     rc;
1314         ENTRY;
1315
1316         LASSERT(S_ISDIR(inode->i_mode));
1317         CDEBUG(D_INODE, "update lsm %p of "DFID"\n", lli->lli_lsm_md,
1318                PFID(ll_inode2fid(inode)));
1319
1320         /* no striped information from request. */
1321         if (lsm == NULL) {
1322                 if (lli->lli_lsm_md == NULL) {
1323                         RETURN(0);
1324                 } else if (lli->lli_lsm_md->lsm_md_hash_type &
1325                                                 LMV_HASH_FLAG_MIGRATION) {
1326                         /* migration is done, the temporay MIGRATE layout has
1327                          * been removed */
1328                         CDEBUG(D_INODE, DFID" finish migration.\n",
1329                                PFID(ll_inode2fid(inode)));
1330                         lmv_free_memmd(lli->lli_lsm_md);
1331                         lli->lli_lsm_md = NULL;
1332                         RETURN(0);
1333                 } else {
1334                         /* The lustre_md from req does not include stripeEA,
1335                          * see ll_md_setattr */
1336                         RETURN(0);
1337                 }
1338         }
1339
1340         /* set the directory layout */
1341         if (lli->lli_lsm_md == NULL) {
1342                 struct cl_attr  *attr;
1343
1344                 rc = ll_init_lsm_md(inode, md);
1345                 if (rc != 0)
1346                         RETURN(rc);
1347
1348                 /* set md->lmv to NULL, so the following free lustre_md
1349                  * will not free this lsm */
1350                 md->lmv = NULL;
1351                 lli->lli_lsm_md = lsm;
1352
1353                 OBD_ALLOC_PTR(attr);
1354                 if (attr == NULL)
1355                         RETURN(-ENOMEM);
1356
1357                 /* validate the lsm */
1358                 rc = md_merge_attr(ll_i2mdexp(inode), lsm, attr,
1359                                    ll_md_blocking_ast);
1360                 if (rc != 0) {
1361                         OBD_FREE_PTR(attr);
1362                         RETURN(rc);
1363                 }
1364
1365                 if (md->body->mbo_valid & OBD_MD_FLNLINK)
1366                         md->body->mbo_nlink = attr->cat_nlink;
1367                 if (md->body->mbo_valid & OBD_MD_FLSIZE)
1368                         md->body->mbo_size = attr->cat_size;
1369                 if (md->body->mbo_valid & OBD_MD_FLATIME)
1370                         md->body->mbo_atime = attr->cat_atime;
1371                 if (md->body->mbo_valid & OBD_MD_FLCTIME)
1372                         md->body->mbo_ctime = attr->cat_ctime;
1373                 if (md->body->mbo_valid & OBD_MD_FLMTIME)
1374                         md->body->mbo_mtime = attr->cat_mtime;
1375
1376                 OBD_FREE_PTR(attr);
1377
1378                 CDEBUG(D_INODE, "Set lsm %p magic %x to "DFID"\n", lsm,
1379                        lsm->lsm_md_magic, PFID(ll_inode2fid(inode)));
1380                 RETURN(0);
1381         }
1382
1383         /* Compare the old and new stripe information */
1384         if (!lsm_md_eq(lli->lli_lsm_md, lsm)) {
1385                 struct lmv_stripe_md    *old_lsm = lli->lli_lsm_md;
1386                 int                     idx;
1387
1388                 CERROR("%s: inode "DFID"(%p)'s lmv layout mismatch (%p)/(%p)"
1389                        "magic:0x%x/0x%x stripe count: %d/%d master_mdt: %d/%d"
1390                        "hash_type:0x%x/0x%x layout: 0x%x/0x%x pool:%s/%s\n",
1391                        ll_get_fsname(inode->i_sb, NULL, 0), PFID(&lli->lli_fid),
1392                        inode, lsm, old_lsm,
1393                        lsm->lsm_md_magic, old_lsm->lsm_md_magic,
1394                        lsm->lsm_md_stripe_count,
1395                        old_lsm->lsm_md_stripe_count,
1396                        lsm->lsm_md_master_mdt_index,
1397                        old_lsm->lsm_md_master_mdt_index,
1398                        lsm->lsm_md_hash_type, old_lsm->lsm_md_hash_type,
1399                        lsm->lsm_md_layout_version,
1400                        old_lsm->lsm_md_layout_version,
1401                        lsm->lsm_md_pool_name,
1402                        old_lsm->lsm_md_pool_name);
1403
1404                 for (idx = 0; idx < old_lsm->lsm_md_stripe_count; idx++) {
1405                         CERROR("%s: sub FIDs in old lsm idx %d, old: "DFID"\n",
1406                                ll_get_fsname(inode->i_sb, NULL, 0), idx,
1407                                PFID(&old_lsm->lsm_md_oinfo[idx].lmo_fid));
1408                 }
1409
1410                 for (idx = 0; idx < lsm->lsm_md_stripe_count; idx++) {
1411                         CERROR("%s: sub FIDs in new lsm idx %d, new: "DFID"\n",
1412                                ll_get_fsname(inode->i_sb, NULL, 0), idx,
1413                                PFID(&lsm->lsm_md_oinfo[idx].lmo_fid));
1414                 }
1415
1416                 RETURN(-EIO);
1417         }
1418
1419         RETURN(0);
1420 }
1421
1422 void ll_clear_inode(struct inode *inode)
1423 {
1424         struct ll_inode_info *lli = ll_i2info(inode);
1425         struct ll_sb_info *sbi = ll_i2sbi(inode);
1426         ENTRY;
1427
1428         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1429                PFID(ll_inode2fid(inode)), inode);
1430
1431         if (S_ISDIR(inode->i_mode)) {
1432                 /* these should have been cleared in ll_file_release */
1433                 LASSERT(lli->lli_opendir_key == NULL);
1434                 LASSERT(lli->lli_sai == NULL);
1435                 LASSERT(lli->lli_opendir_pid == 0);
1436         }
1437
1438         md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1439
1440         LASSERT(!lli->lli_open_fd_write_count);
1441         LASSERT(!lli->lli_open_fd_read_count);
1442         LASSERT(!lli->lli_open_fd_exec_count);
1443
1444         if (lli->lli_mds_write_och)
1445                 ll_md_real_close(inode, FMODE_WRITE);
1446         if (lli->lli_mds_exec_och)
1447                 ll_md_real_close(inode, FMODE_EXEC);
1448         if (lli->lli_mds_read_och)
1449                 ll_md_real_close(inode, FMODE_READ);
1450
1451         if (S_ISLNK(inode->i_mode) && lli->lli_symlink_name) {
1452                 OBD_FREE(lli->lli_symlink_name,
1453                          strlen(lli->lli_symlink_name) + 1);
1454                 lli->lli_symlink_name = NULL;
1455         }
1456
1457         ll_xattr_cache_destroy(inode);
1458
1459 #ifdef CONFIG_FS_POSIX_ACL
1460         forget_all_cached_acls(inode);
1461         if (lli->lli_posix_acl) {
1462                 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1463                 posix_acl_release(lli->lli_posix_acl);
1464                 lli->lli_posix_acl = NULL;
1465         }
1466 #endif
1467         lli->lli_inode_magic = LLI_INODE_DEAD;
1468
1469         if (S_ISDIR(inode->i_mode))
1470                 ll_dir_clear_lsm_md(inode);
1471         else if (S_ISREG(inode->i_mode) && !is_bad_inode(inode))
1472                 LASSERT(list_empty(&lli->lli_agl_list));
1473
1474         /*
1475          * XXX This has to be done before lsm is freed below, because
1476          * cl_object still uses inode lsm.
1477          */
1478         cl_inode_fini(inode);
1479
1480         EXIT;
1481 }
1482
1483 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
1484 {
1485         struct lustre_md md;
1486         struct inode *inode = dentry->d_inode;
1487         struct ll_sb_info *sbi = ll_i2sbi(inode);
1488         struct ptlrpc_request *request = NULL;
1489         int rc, ia_valid;
1490         ENTRY;
1491
1492         op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1493                                      LUSTRE_OPC_ANY, NULL);
1494         if (IS_ERR(op_data))
1495                 RETURN(PTR_ERR(op_data));
1496
1497         rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &request);
1498         if (rc) {
1499                 ptlrpc_req_finished(request);
1500                 if (rc == -ENOENT) {
1501                         clear_nlink(inode);
1502                         /* Unlinked special device node? Or just a race?
1503                          * Pretend we done everything. */
1504                         if (!S_ISREG(inode->i_mode) &&
1505                             !S_ISDIR(inode->i_mode)) {
1506                                 ia_valid = op_data->op_attr.ia_valid;
1507                                 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1508                                 rc = simple_setattr(dentry, &op_data->op_attr);
1509                                 op_data->op_attr.ia_valid = ia_valid;
1510                         }
1511                 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1512                         CERROR("md_setattr fails: rc = %d\n", rc);
1513                 }
1514                 RETURN(rc);
1515         }
1516
1517         rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1518                               sbi->ll_md_exp, &md);
1519         if (rc) {
1520                 ptlrpc_req_finished(request);
1521                 RETURN(rc);
1522         }
1523
1524         ia_valid = op_data->op_attr.ia_valid;
1525         /* inode size will be in ll_setattr_ost, can't do it now since dirty
1526          * cache is not cleared yet. */
1527         op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1528         if (S_ISREG(inode->i_mode))
1529                 inode_lock(inode);
1530         rc = simple_setattr(dentry, &op_data->op_attr);
1531         if (S_ISREG(inode->i_mode))
1532                 inode_unlock(inode);
1533         op_data->op_attr.ia_valid = ia_valid;
1534
1535         rc = ll_update_inode(inode, &md);
1536         ptlrpc_req_finished(request);
1537
1538         RETURN(rc);
1539 }
1540
1541 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1542  * object(s) determine the file size and mtime.  Otherwise, the MDS will
1543  * keep these values until such a time that objects are allocated for it.
1544  * We do the MDS operations first, as it is checking permissions for us.
1545  * We don't to the MDS RPC if there is nothing that we want to store there,
1546  * otherwise there is no harm in updating mtime/atime on the MDS if we are
1547  * going to do an RPC anyways.
1548  *
1549  * If we are doing a truncate, we will send the mtime and ctime updates
1550  * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1551  * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1552  * at the same time.
1553  *
1554  * In case of HSMimport, we only set attr on MDS.
1555  */
1556 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
1557 {
1558         struct inode *inode = dentry->d_inode;
1559         struct ll_inode_info *lli = ll_i2info(inode);
1560         struct md_op_data *op_data = NULL;
1561         int rc = 0;
1562         ENTRY;
1563
1564         CDEBUG(D_VFSTRACE, "%s: setattr inode "DFID"(%p) from %llu to %llu, "
1565                "valid %x, hsm_import %d\n",
1566                ll_get_fsname(inode->i_sb, NULL, 0), PFID(&lli->lli_fid),
1567                inode, i_size_read(inode), attr->ia_size, attr->ia_valid,
1568                hsm_import);
1569
1570         if (attr->ia_valid & ATTR_SIZE) {
1571                 /* Check new size against VFS/VM file size limit and rlimit */
1572                 rc = inode_newsize_ok(inode, attr->ia_size);
1573                 if (rc)
1574                         RETURN(rc);
1575
1576                 /* The maximum Lustre file size is variable, based on the
1577                  * OST maximum object size and number of stripes.  This
1578                  * needs another check in addition to the VFS check above. */
1579                 if (attr->ia_size > ll_file_maxbytes(inode)) {
1580                         CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
1581                                PFID(&lli->lli_fid), attr->ia_size,
1582                                ll_file_maxbytes(inode));
1583                         RETURN(-EFBIG);
1584                 }
1585
1586                 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1587         }
1588
1589         /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1590         if (attr->ia_valid & TIMES_SET_FLAGS) {
1591                 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
1592                     !cfs_capable(CFS_CAP_FOWNER))
1593                         RETURN(-EPERM);
1594         }
1595
1596         /* We mark all of the fields "set" so MDS/OST does not re-set them */
1597         if (!(attr->ia_valid & ATTR_CTIME_SET) &&
1598             (attr->ia_valid & ATTR_CTIME)) {
1599                 attr->ia_ctime = current_time(inode);
1600                 attr->ia_valid |= ATTR_CTIME_SET;
1601         }
1602         if (!(attr->ia_valid & ATTR_ATIME_SET) &&
1603             (attr->ia_valid & ATTR_ATIME)) {
1604                 attr->ia_atime = current_time(inode);
1605                 attr->ia_valid |= ATTR_ATIME_SET;
1606         }
1607         if (!(attr->ia_valid & ATTR_MTIME_SET) &&
1608             (attr->ia_valid & ATTR_MTIME)) {
1609                 attr->ia_mtime = current_time(inode);
1610                 attr->ia_valid |= ATTR_MTIME_SET;
1611         }
1612
1613         if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1614                 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %llu\n",
1615                        LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1616                        (s64)ktime_get_real_seconds());
1617
1618         if (S_ISREG(inode->i_mode)) {
1619                 if (attr->ia_valid & ATTR_SIZE)
1620                         inode_dio_write_done(inode);
1621                 inode_unlock(inode);
1622         }
1623
1624         /* We always do an MDS RPC, even if we're only changing the size;
1625          * only the MDS knows whether truncate() should fail with -ETXTBUSY */
1626
1627         OBD_ALLOC_PTR(op_data);
1628         if (op_data == NULL)
1629                 GOTO(out, rc = -ENOMEM);
1630
1631         if (!hsm_import && attr->ia_valid & ATTR_SIZE) {
1632                 /* If we are changing file size, file content is
1633                  * modified, flag it. */
1634                 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1635                 op_data->op_bias |= MDS_DATA_MODIFIED;
1636                 ll_file_clear_flag(lli, LLIF_DATA_MODIFIED);
1637         }
1638
1639         op_data->op_attr = *attr;
1640
1641         rc = ll_md_setattr(dentry, op_data);
1642         if (rc)
1643                 GOTO(out, rc);
1644
1645         if (!S_ISREG(inode->i_mode) || hsm_import)
1646                 GOTO(out, rc = 0);
1647
1648         if (attr->ia_valid & (ATTR_SIZE |
1649                               ATTR_ATIME | ATTR_ATIME_SET |
1650                               ATTR_MTIME | ATTR_MTIME_SET |
1651                               ATTR_CTIME | ATTR_CTIME_SET)) {
1652                 /* For truncate and utimes sending attributes to OSTs, setting
1653                  * mtime/atime to the past will be performed under PW [0:EOF]
1654                  * extent lock (new_size:EOF for truncate).  It may seem
1655                  * excessive to send mtime/atime updates to OSTs when not
1656                  * setting times to past, but it is necessary due to possible
1657                  * time de-synchronization between MDT inode and OST objects */
1658                 rc = cl_setattr_ost(lli->lli_clob, attr, 0);
1659         }
1660
1661         /* If the file was restored, it needs to set dirty flag.
1662          *
1663          * We've already sent MDS_DATA_MODIFIED flag in
1664          * ll_md_setattr() for truncate. However, the MDT refuses to
1665          * set the HS_DIRTY flag on released files, so we have to set
1666          * it again if the file has been restored. Please check how
1667          * LLIF_DATA_MODIFIED is set in vvp_io_setattr_fini().
1668          *
1669          * Please notice that if the file is not released, the previous
1670          * MDS_DATA_MODIFIED has taken effect and usually
1671          * LLIF_DATA_MODIFIED is not set(see vvp_io_setattr_fini()).
1672          * This way we can save an RPC for common open + trunc
1673          * operation. */
1674         if (ll_file_test_and_clear_flag(lli, LLIF_DATA_MODIFIED)) {
1675                 struct hsm_state_set hss = {
1676                         .hss_valid = HSS_SETMASK,
1677                         .hss_setmask = HS_DIRTY,
1678                 };
1679                 int rc2;
1680
1681                 rc2 = ll_hsm_state_set(inode, &hss);
1682                 /* truncate and write can happen at the same time, so that
1683                  * the file can be set modified even though the file is not
1684                  * restored from released state, and ll_hsm_state_set() is
1685                  * not applicable for the file, and rc2 < 0 is normal in this
1686                  * case. */
1687                 if (rc2 < 0)
1688                         CDEBUG(D_INFO, DFID "HSM set dirty failed: rc2 = %d\n",
1689                                PFID(ll_inode2fid(inode)), rc2);
1690         }
1691
1692         EXIT;
1693 out:
1694         if (op_data != NULL)
1695                 ll_finish_md_op_data(op_data);
1696
1697         if (S_ISREG(inode->i_mode)) {
1698                 inode_lock(inode);
1699                 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1700                         inode_dio_wait(inode);
1701                 /* Once we've got the i_mutex, it's safe to set the S_NOSEC
1702                  * flag.  ll_update_inode (called from ll_md_setattr), clears
1703                  * inode flags, so there is a gap where S_NOSEC is not set.
1704                  * This can cause a writer to take the i_mutex unnecessarily,
1705                  * but this is safe to do and should be rare. */
1706                 inode_has_no_xattr(inode);
1707         }
1708
1709         ll_stats_ops_tally(ll_i2sbi(inode), (attr->ia_valid & ATTR_SIZE) ?
1710                         LPROC_LL_TRUNC : LPROC_LL_SETATTR, 1);
1711
1712         return rc;
1713 }
1714
1715 int ll_setattr(struct dentry *de, struct iattr *attr)
1716 {
1717         int mode = de->d_inode->i_mode;
1718
1719         if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1720                               (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1721                 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1722
1723         if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
1724                                (ATTR_SIZE|ATTR_MODE)) &&
1725             (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
1726              (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1727               !(attr->ia_mode & S_ISGID))))
1728                 attr->ia_valid |= ATTR_FORCE;
1729
1730         if ((attr->ia_valid & ATTR_MODE) &&
1731             (mode & S_ISUID) &&
1732             !(attr->ia_mode & S_ISUID) &&
1733             !(attr->ia_valid & ATTR_KILL_SUID))
1734                 attr->ia_valid |= ATTR_KILL_SUID;
1735
1736         if ((attr->ia_valid & ATTR_MODE) &&
1737             ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1738             !(attr->ia_mode & S_ISGID) &&
1739             !(attr->ia_valid & ATTR_KILL_SGID))
1740                 attr->ia_valid |= ATTR_KILL_SGID;
1741
1742         /* avoid polluted from ATTR_TIMES_SET,
1743          * projid is not expected to be set here */
1744         attr->ia_valid &= ~MDS_ATTR_PROJID;
1745
1746         return ll_setattr_raw(de, attr, false);
1747 }
1748
1749 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1750                        __u64 max_age, __u32 flags)
1751 {
1752         struct ll_sb_info *sbi = ll_s2sbi(sb);
1753         struct obd_statfs obd_osfs;
1754         int rc;
1755         ENTRY;
1756
1757         rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
1758         if (rc) {
1759                 CERROR("md_statfs fails: rc = %d\n", rc);
1760                 RETURN(rc);
1761         }
1762
1763         osfs->os_type = sb->s_magic;
1764
1765         CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
1766                osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
1767
1768         if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
1769                 flags |= OBD_STATFS_NODELAY;
1770
1771         rc = obd_statfs_rqset(sbi->ll_dt_exp, &obd_osfs, max_age, flags);
1772         if (rc) {
1773                 CERROR("obd_statfs fails: rc = %d\n", rc);
1774                 RETURN(rc);
1775         }
1776
1777         CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
1778                obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1779                obd_osfs.os_files);
1780
1781         osfs->os_bsize = obd_osfs.os_bsize;
1782         osfs->os_blocks = obd_osfs.os_blocks;
1783         osfs->os_bfree = obd_osfs.os_bfree;
1784         osfs->os_bavail = obd_osfs.os_bavail;
1785
1786         /* If we don't have as many objects free on the OST as inodes
1787          * on the MDS, we reduce the total number of inodes to
1788          * compensate, so that the "inodes in use" number is correct.
1789          */
1790         if (obd_osfs.os_ffree < osfs->os_ffree) {
1791                 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1792                         obd_osfs.os_ffree;
1793                 osfs->os_ffree = obd_osfs.os_ffree;
1794         }
1795
1796         RETURN(rc);
1797 }
1798 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1799 {
1800         struct super_block *sb = de->d_sb;
1801         struct obd_statfs osfs;
1802         __u64 fsid = huge_encode_dev(sb->s_dev);
1803         int rc;
1804
1805         CDEBUG(D_VFSTRACE, "VFS Op: at %llu jiffies\n", get_jiffies_64());
1806         ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1807
1808         /* Some amount of caching on the client is allowed */
1809         rc = ll_statfs_internal(sb, &osfs,
1810                                 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1811                                 0);
1812         if (rc)
1813                 return rc;
1814
1815         statfs_unpack(sfs, &osfs);
1816
1817         /* We need to downshift for all 32-bit kernels, because we can't
1818          * tell if the kernel is being called via sys_statfs64() or not.
1819          * Stop before overflowing f_bsize - in which case it is better
1820          * to just risk EOVERFLOW if caller is using old sys_statfs(). */
1821         if (sizeof(long) < 8) {
1822                 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1823                         sfs->f_bsize <<= 1;
1824
1825                         osfs.os_blocks >>= 1;
1826                         osfs.os_bfree >>= 1;
1827                         osfs.os_bavail >>= 1;
1828                 }
1829         }
1830
1831         sfs->f_blocks = osfs.os_blocks;
1832         sfs->f_bfree = osfs.os_bfree;
1833         sfs->f_bavail = osfs.os_bavail;
1834         sfs->f_fsid.val[0] = (__u32)fsid;
1835         sfs->f_fsid.val[1] = (__u32)(fsid >> 32);
1836         return 0;
1837 }
1838
1839 void ll_inode_size_lock(struct inode *inode)
1840 {
1841         struct ll_inode_info *lli;
1842
1843         LASSERT(!S_ISDIR(inode->i_mode));
1844
1845         lli = ll_i2info(inode);
1846         mutex_lock(&lli->lli_size_mutex);
1847 }
1848
1849 void ll_inode_size_unlock(struct inode *inode)
1850 {
1851         struct ll_inode_info *lli;
1852
1853         lli = ll_i2info(inode);
1854         mutex_unlock(&lli->lli_size_mutex);
1855 }
1856
1857 int ll_update_inode(struct inode *inode, struct lustre_md *md)
1858 {
1859         struct ll_inode_info *lli = ll_i2info(inode);
1860         struct mdt_body *body = md->body;
1861         struct ll_sb_info *sbi = ll_i2sbi(inode);
1862         int rc = 0;
1863
1864         if (body->mbo_valid & OBD_MD_FLEASIZE) {
1865                 rc = cl_file_inode_init(inode, md);
1866                 if (rc)
1867                         return rc;
1868         }
1869
1870         if (S_ISDIR(inode->i_mode)) {
1871                 rc = ll_update_lsm_md(inode, md);
1872                 if (rc != 0)
1873                         return rc;
1874         }
1875
1876 #ifdef CONFIG_FS_POSIX_ACL
1877         if (body->mbo_valid & OBD_MD_FLACL) {
1878                 spin_lock(&lli->lli_lock);
1879                 if (lli->lli_posix_acl)
1880                         posix_acl_release(lli->lli_posix_acl);
1881                 lli->lli_posix_acl = md->posix_acl;
1882                 spin_unlock(&lli->lli_lock);
1883         }
1884 #endif
1885         inode->i_ino = cl_fid_build_ino(&body->mbo_fid1,
1886                                         sbi->ll_flags & LL_SBI_32BIT_API);
1887         inode->i_generation = cl_fid_build_gen(&body->mbo_fid1);
1888
1889         if (body->mbo_valid & OBD_MD_FLATIME) {
1890                 if (body->mbo_atime > LTIME_S(inode->i_atime))
1891                         LTIME_S(inode->i_atime) = body->mbo_atime;
1892                 lli->lli_atime = body->mbo_atime;
1893         }
1894
1895         if (body->mbo_valid & OBD_MD_FLMTIME) {
1896                 if (body->mbo_mtime > LTIME_S(inode->i_mtime)) {
1897                         CDEBUG(D_INODE, "setting ino %lu mtime from %lu "
1898                                "to %llu\n", inode->i_ino,
1899                                LTIME_S(inode->i_mtime), body->mbo_mtime);
1900                         LTIME_S(inode->i_mtime) = body->mbo_mtime;
1901                 }
1902                 lli->lli_mtime = body->mbo_mtime;
1903         }
1904
1905         if (body->mbo_valid & OBD_MD_FLCTIME) {
1906                 if (body->mbo_ctime > LTIME_S(inode->i_ctime))
1907                         LTIME_S(inode->i_ctime) = body->mbo_ctime;
1908                 lli->lli_ctime = body->mbo_ctime;
1909         }
1910
1911         /* Clear i_flags to remove S_NOSEC before permissions are updated */
1912         if (body->mbo_valid & OBD_MD_FLFLAGS)
1913                 inode->i_flags = ll_ext_to_inode_flags(body->mbo_flags);
1914         if (body->mbo_valid & OBD_MD_FLMODE)
1915                 inode->i_mode = (inode->i_mode & S_IFMT) |
1916                                 (body->mbo_mode & ~S_IFMT);
1917
1918         if (body->mbo_valid & OBD_MD_FLTYPE)
1919                 inode->i_mode = (inode->i_mode & ~S_IFMT) |
1920                                 (body->mbo_mode & S_IFMT);
1921
1922         LASSERT(inode->i_mode != 0);
1923         if (S_ISREG(inode->i_mode))
1924                 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS + 1,
1925                                        LL_MAX_BLKSIZE_BITS);
1926         else
1927                 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1928
1929         if (body->mbo_valid & OBD_MD_FLUID)
1930                 inode->i_uid = make_kuid(&init_user_ns, body->mbo_uid);
1931         if (body->mbo_valid & OBD_MD_FLGID)
1932                 inode->i_gid = make_kgid(&init_user_ns, body->mbo_gid);
1933         if (body->mbo_valid & OBD_MD_FLPROJID)
1934                 lli->lli_projid = body->mbo_projid;
1935         if (body->mbo_valid & OBD_MD_FLNLINK)
1936                 set_nlink(inode, body->mbo_nlink);
1937         if (body->mbo_valid & OBD_MD_FLRDEV)
1938                 inode->i_rdev = old_decode_dev(body->mbo_rdev);
1939
1940         if (body->mbo_valid & OBD_MD_FLID) {
1941                 /* FID shouldn't be changed! */
1942                 if (fid_is_sane(&lli->lli_fid)) {
1943                         LASSERTF(lu_fid_eq(&lli->lli_fid, &body->mbo_fid1),
1944                                  "Trying to change FID "DFID
1945                                  " to the "DFID", inode "DFID"(%p)\n",
1946                                  PFID(&lli->lli_fid), PFID(&body->mbo_fid1),
1947                                  PFID(ll_inode2fid(inode)), inode);
1948                 } else {
1949                         lli->lli_fid = body->mbo_fid1;
1950                 }
1951         }
1952
1953         LASSERT(fid_seq(&lli->lli_fid) != 0);
1954
1955         if (body->mbo_valid & OBD_MD_FLSIZE) {
1956                 i_size_write(inode, body->mbo_size);
1957
1958                 CDEBUG(D_VFSTRACE, "inode="DFID", updating i_size %llu\n",
1959                        PFID(ll_inode2fid(inode)),
1960                        (unsigned long long)body->mbo_size);
1961
1962                 if (body->mbo_valid & OBD_MD_FLBLOCKS)
1963                         inode->i_blocks = body->mbo_blocks;
1964         }
1965
1966         if (body->mbo_valid & OBD_MD_TSTATE) {
1967                 /* Set LLIF_FILE_RESTORING if restore ongoing and
1968                  * clear it when done to ensure to start again
1969                  * glimpsing updated attrs
1970                  */
1971                 if (body->mbo_t_state & MS_RESTORE)
1972                         ll_file_set_flag(lli, LLIF_FILE_RESTORING);
1973                 else
1974                         ll_file_clear_flag(lli, LLIF_FILE_RESTORING);
1975         }
1976
1977         return 0;
1978 }
1979
1980 int ll_read_inode2(struct inode *inode, void *opaque)
1981 {
1982         struct lustre_md *md = opaque;
1983         struct ll_inode_info *lli = ll_i2info(inode);
1984         int     rc;
1985         ENTRY;
1986
1987         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1988                PFID(&lli->lli_fid), inode);
1989
1990         /* Core attributes from the MDS first.  This is a new inode, and
1991          * the VFS doesn't zero times in the core inode so we have to do
1992          * it ourselves.  They will be overwritten by either MDS or OST
1993          * attributes - we just need to make sure they aren't newer. */
1994         LTIME_S(inode->i_mtime) = 0;
1995         LTIME_S(inode->i_atime) = 0;
1996         LTIME_S(inode->i_ctime) = 0;
1997         inode->i_rdev = 0;
1998         rc = ll_update_inode(inode, md);
1999         if (rc != 0)
2000                 RETURN(rc);
2001
2002         /* OIDEBUG(inode); */
2003
2004 #ifdef HAVE_BACKING_DEV_INFO
2005         /* initializing backing dev info. */
2006         inode->i_mapping->backing_dev_info = &s2lsi(inode->i_sb)->lsi_bdi;
2007 #endif
2008         if (S_ISREG(inode->i_mode)) {
2009                 struct ll_sb_info *sbi = ll_i2sbi(inode);
2010                 inode->i_op = &ll_file_inode_operations;
2011                 inode->i_fop = sbi->ll_fop;
2012                 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
2013                 EXIT;
2014         } else if (S_ISDIR(inode->i_mode)) {
2015                 inode->i_op = &ll_dir_inode_operations;
2016                 inode->i_fop = &ll_dir_operations;
2017                 EXIT;
2018         } else if (S_ISLNK(inode->i_mode)) {
2019                 inode->i_op = &ll_fast_symlink_inode_operations;
2020                 EXIT;
2021         } else {
2022                 inode->i_op = &ll_special_inode_operations;
2023
2024                 init_special_inode(inode, inode->i_mode,
2025                                    inode->i_rdev);
2026
2027                 EXIT;
2028         }
2029
2030         return 0;
2031 }
2032
2033 void ll_delete_inode(struct inode *inode)
2034 {
2035         struct ll_inode_info *lli = ll_i2info(inode);
2036         ENTRY;
2037
2038         if (S_ISREG(inode->i_mode) && lli->lli_clob != NULL)
2039                 /* It is last chance to write out dirty pages,
2040                  * otherwise we may lose data while umount */
2041                 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF, CL_FSYNC_LOCAL, 1);
2042
2043         truncate_inode_pages_final(&inode->i_data);
2044
2045         LASSERTF(inode->i_data.nrpages == 0, "inode="DFID"(%p) nrpages=%lu, "
2046                  "see https://jira.whamcloud.com/browse/LU-118\n",
2047                  PFID(ll_inode2fid(inode)), inode, inode->i_data.nrpages);
2048
2049 #ifdef HAVE_SBOPS_EVICT_INODE
2050         ll_clear_inode(inode);
2051 #endif
2052         clear_inode(inode);
2053
2054         EXIT;
2055 }
2056
2057 int ll_iocontrol(struct inode *inode, struct file *file,
2058                  unsigned int cmd, unsigned long arg)
2059 {
2060         struct ll_sb_info *sbi = ll_i2sbi(inode);
2061         struct ptlrpc_request *req = NULL;
2062         int rc, flags = 0;
2063         ENTRY;
2064
2065         switch(cmd) {
2066         case FSFILT_IOC_GETFLAGS: {
2067                 struct mdt_body *body;
2068                 struct md_op_data *op_data;
2069
2070                 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
2071                                              0, 0, LUSTRE_OPC_ANY,
2072                                              NULL);
2073                 if (IS_ERR(op_data))
2074                         RETURN(PTR_ERR(op_data));
2075
2076                 op_data->op_valid = OBD_MD_FLFLAGS;
2077                 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
2078                 ll_finish_md_op_data(op_data);
2079                 if (rc) {
2080                         CERROR("%s: failure inode "DFID": rc = %d\n",
2081                                sbi->ll_md_exp->exp_obd->obd_name,
2082                                PFID(ll_inode2fid(inode)), rc);
2083                         RETURN(-abs(rc));
2084                 }
2085
2086                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2087
2088                 flags = body->mbo_flags;
2089
2090                 ptlrpc_req_finished(req);
2091
2092                 RETURN(put_user(flags, (int __user *)arg));
2093         }
2094         case FSFILT_IOC_SETFLAGS: {
2095                 struct iattr *attr;
2096                 struct md_op_data *op_data;
2097                 struct cl_object *obj;
2098
2099                 if (get_user(flags, (int __user *)arg))
2100                         RETURN(-EFAULT);
2101
2102                 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
2103                                              LUSTRE_OPC_ANY, NULL);
2104                 if (IS_ERR(op_data))
2105                         RETURN(PTR_ERR(op_data));
2106
2107                 op_data->op_attr_flags = flags;
2108                 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
2109                 rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, &req);
2110                 ll_finish_md_op_data(op_data);
2111                 ptlrpc_req_finished(req);
2112                 if (rc)
2113                         RETURN(rc);
2114
2115                 inode->i_flags = ll_ext_to_inode_flags(flags);
2116
2117                 obj = ll_i2info(inode)->lli_clob;
2118                 if (obj == NULL)
2119                         RETURN(0);
2120
2121                 OBD_ALLOC_PTR(attr);
2122                 if (attr == NULL)
2123                         RETURN(-ENOMEM);
2124
2125                 attr->ia_valid = ATTR_ATTR_FLAG;
2126                 rc = cl_setattr_ost(obj, attr, flags);
2127
2128                 OBD_FREE_PTR(attr);
2129                 RETURN(rc);
2130         }
2131         default:
2132                 RETURN(-ENOSYS);
2133         }
2134
2135         RETURN(0);
2136 }
2137
2138 int ll_flush_ctx(struct inode *inode)
2139 {
2140         struct ll_sb_info  *sbi = ll_i2sbi(inode);
2141
2142         CDEBUG(D_SEC, "flush context for user %d\n",
2143                from_kuid(&init_user_ns, current_uid()));
2144
2145         obd_set_info_async(NULL, sbi->ll_md_exp,
2146                            sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2147                            0, NULL, NULL);
2148         obd_set_info_async(NULL, sbi->ll_dt_exp,
2149                            sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
2150                            0, NULL, NULL);
2151         return 0;
2152 }
2153
2154 /* umount -f client means force down, don't save state */
2155 void ll_umount_begin(struct super_block *sb)
2156 {
2157         struct ll_sb_info *sbi = ll_s2sbi(sb);
2158         struct obd_device *obd;
2159         struct obd_ioctl_data *ioc_data;
2160         struct l_wait_info lwi;
2161         wait_queue_head_t waitq;
2162         ENTRY;
2163
2164         CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
2165                sb->s_count, atomic_read(&sb->s_active));
2166
2167         obd = class_exp2obd(sbi->ll_md_exp);
2168         if (obd == NULL) {
2169                 CERROR("Invalid MDC connection handle %#llx\n",
2170                        sbi->ll_md_exp->exp_handle.h_cookie);
2171                 EXIT;
2172                 return;
2173         }
2174         obd->obd_force = 1;
2175
2176         obd = class_exp2obd(sbi->ll_dt_exp);
2177         if (obd == NULL) {
2178                 CERROR("Invalid LOV connection handle %#llx\n",
2179                        sbi->ll_dt_exp->exp_handle.h_cookie);
2180                 EXIT;
2181                 return;
2182         }
2183         obd->obd_force = 1;
2184
2185         OBD_ALLOC_PTR(ioc_data);
2186         if (ioc_data) {
2187                 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
2188                               sizeof *ioc_data, ioc_data, NULL);
2189
2190                 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
2191                               sizeof *ioc_data, ioc_data, NULL);
2192
2193                 OBD_FREE_PTR(ioc_data);
2194         }
2195
2196         /* Really, we'd like to wait until there are no requests outstanding,
2197          * and then continue.  For now, we just periodically checking for vfs
2198          * to decrement mnt_cnt and hope to finish it within 10sec.
2199          */
2200         init_waitqueue_head(&waitq);
2201         lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(10),
2202                                    cfs_time_seconds(1), NULL, NULL);
2203         l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi);
2204
2205         EXIT;
2206 }
2207
2208 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
2209 {
2210         struct ll_sb_info *sbi = ll_s2sbi(sb);
2211         char *profilenm = get_profile_name(sb);
2212         int err;
2213         __u32 read_only;
2214
2215         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
2216                 read_only = *flags & MS_RDONLY;
2217                 err = obd_set_info_async(NULL, sbi->ll_md_exp,
2218                                          sizeof(KEY_READ_ONLY),
2219                                          KEY_READ_ONLY, sizeof(read_only),
2220                                          &read_only, NULL);
2221                 if (err) {
2222                         LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
2223                                       profilenm, read_only ?
2224                                       "read-only" : "read-write", err);
2225                         return err;
2226                 }
2227
2228                 if (read_only)
2229                         sb->s_flags |= MS_RDONLY;
2230                 else
2231                         sb->s_flags &= ~MS_RDONLY;
2232
2233                 if (sbi->ll_flags & LL_SBI_VERBOSE)
2234                         LCONSOLE_WARN("Remounted %s %s\n", profilenm,
2235                                       read_only ?  "read-only" : "read-write");
2236         }
2237         return 0;
2238 }
2239
2240 /**
2241  * Cleanup the open handle that is cached on MDT-side.
2242  *
2243  * For open case, the client side open handling thread may hit error
2244  * after the MDT grant the open. Under such case, the client should
2245  * send close RPC to the MDT as cleanup; otherwise, the open handle
2246  * on the MDT will be leaked there until the client umount or evicted.
2247  *
2248  * In further, if someone unlinked the file, because the open handle
2249  * holds the reference on such file/object, then it will block the
2250  * subsequent threads that want to locate such object via FID.
2251  *
2252  * \param[in] sb        super block for this file-system
2253  * \param[in] open_req  pointer to the original open request
2254  */
2255 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
2256 {
2257         struct mdt_body                 *body;
2258         struct md_op_data               *op_data;
2259         struct ptlrpc_request           *close_req = NULL;
2260         struct obd_export               *exp       = ll_s2sbi(sb)->ll_md_exp;
2261         ENTRY;
2262
2263         body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
2264         OBD_ALLOC_PTR(op_data);
2265         if (op_data == NULL) {
2266                 CWARN("%s: cannot allocate op_data to release open handle for "
2267                       DFID"\n",
2268                       ll_get_fsname(sb, NULL, 0), PFID(&body->mbo_fid1));
2269
2270                 RETURN_EXIT;
2271         }
2272
2273         op_data->op_fid1 = body->mbo_fid1;
2274         op_data->op_handle = body->mbo_handle;
2275         op_data->op_mod_time = ktime_get_real_seconds();
2276         md_close(exp, op_data, NULL, &close_req);
2277         ptlrpc_req_finished(close_req);
2278         ll_finish_md_op_data(op_data);
2279
2280         EXIT;
2281 }
2282
2283 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
2284                   struct super_block *sb, struct lookup_intent *it)
2285 {
2286         struct ll_sb_info *sbi = NULL;
2287         struct lustre_md md = { NULL };
2288         int rc;
2289         ENTRY;
2290
2291         LASSERT(*inode || sb);
2292         sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
2293         rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
2294                               sbi->ll_md_exp, &md);
2295         if (rc != 0)
2296                 GOTO(cleanup, rc);
2297
2298         if (*inode) {
2299                 rc = ll_update_inode(*inode, &md);
2300                 if (rc != 0)
2301                         GOTO(out, rc);
2302         } else {
2303                 LASSERT(sb != NULL);
2304
2305                 /*
2306                  * At this point server returns to client's same fid as client
2307                  * generated for creating. So using ->fid1 is okay here.
2308                  */
2309                 if (!fid_is_sane(&md.body->mbo_fid1)) {
2310                         CERROR("%s: Fid is insane "DFID"\n",
2311                                 ll_get_fsname(sb, NULL, 0),
2312                                 PFID(&md.body->mbo_fid1));
2313                         GOTO(out, rc = -EINVAL);
2314                 }
2315
2316                 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->mbo_fid1,
2317                                              sbi->ll_flags & LL_SBI_32BIT_API),
2318                                  &md);
2319                 if (IS_ERR(*inode)) {
2320 #ifdef CONFIG_FS_POSIX_ACL
2321                         if (md.posix_acl) {
2322                                 posix_acl_release(md.posix_acl);
2323                                 md.posix_acl = NULL;
2324                         }
2325 #endif
2326                         rc = IS_ERR(*inode) ? PTR_ERR(*inode) : -ENOMEM;
2327                         *inode = NULL;
2328                         CERROR("new_inode -fatal: rc %d\n", rc);
2329                         GOTO(out, rc);
2330                 }
2331         }
2332
2333         /* Handling piggyback layout lock.
2334          * Layout lock can be piggybacked by getattr and open request.
2335          * The lsm can be applied to inode only if it comes with a layout lock
2336          * otherwise correct layout may be overwritten, for example:
2337          * 1. proc1: mdt returns a lsm but not granting layout
2338          * 2. layout was changed by another client
2339          * 3. proc2: refresh layout and layout lock granted
2340          * 4. proc1: to apply a stale layout */
2341         if (it != NULL && it->it_lock_mode != 0) {
2342                 struct lustre_handle lockh;
2343                 struct ldlm_lock *lock;
2344
2345                 lockh.cookie = it->it_lock_handle;
2346                 lock = ldlm_handle2lock(&lockh);
2347                 LASSERT(lock != NULL);
2348                 if (ldlm_has_layout(lock)) {
2349                         struct cl_object_conf conf;
2350
2351                         memset(&conf, 0, sizeof(conf));
2352                         conf.coc_opc = OBJECT_CONF_SET;
2353                         conf.coc_inode = *inode;
2354                         conf.coc_lock = lock;
2355                         conf.u.coc_layout = md.layout;
2356                         (void)ll_layout_conf(*inode, &conf);
2357                 }
2358                 LDLM_LOCK_PUT(lock);
2359         }
2360
2361         GOTO(out, rc = 0);
2362
2363 out:
2364         md_free_lustre_md(sbi->ll_md_exp, &md);
2365
2366 cleanup:
2367         if (rc != 0 && it != NULL && it->it_op & IT_OPEN)
2368                 ll_open_cleanup(sb != NULL ? sb : (*inode)->i_sb, req);
2369
2370         return rc;
2371 }
2372
2373 int ll_obd_statfs(struct inode *inode, void __user *arg)
2374 {
2375         struct ll_sb_info *sbi = NULL;
2376         struct obd_export *exp;
2377         char *buf = NULL;
2378         struct obd_ioctl_data *data = NULL;
2379         __u32 type;
2380         int len = 0, rc;
2381
2382         if (!inode || !(sbi = ll_i2sbi(inode)))
2383                 GOTO(out_statfs, rc = -EINVAL);
2384
2385         rc = obd_ioctl_getdata(&buf, &len, arg);
2386         if (rc)
2387                 GOTO(out_statfs, rc);
2388
2389         data = (void*)buf;
2390         if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2391             !data->ioc_pbuf1 || !data->ioc_pbuf2)
2392                 GOTO(out_statfs, rc = -EINVAL);
2393
2394         if (data->ioc_inllen1 != sizeof(__u32) ||
2395             data->ioc_inllen2 != sizeof(__u32) ||
2396             data->ioc_plen1 != sizeof(struct obd_statfs) ||
2397             data->ioc_plen2 != sizeof(struct obd_uuid))
2398                 GOTO(out_statfs, rc = -EINVAL);
2399
2400         memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2401         if (type & LL_STATFS_LMV)
2402                 exp = sbi->ll_md_exp;
2403         else if (type & LL_STATFS_LOV)
2404                 exp = sbi->ll_dt_exp;
2405         else
2406                 GOTO(out_statfs, rc = -ENODEV);
2407
2408         rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2409         if (rc)
2410                 GOTO(out_statfs, rc);
2411 out_statfs:
2412         OBD_FREE_LARGE(buf, len);
2413         return rc;
2414 }
2415
2416 int ll_process_config(struct lustre_cfg *lcfg)
2417 {
2418         struct super_block *sb;
2419         unsigned long x;
2420         int rc = 0;
2421         char *ptr;
2422
2423         /* The instance name contains the sb: lustre-client-aacfe000 */
2424         ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2425         if (!ptr || !*(++ptr))
2426                 return -EINVAL;
2427         if (sscanf(ptr, "%lx", &x) != 1)
2428                 return -EINVAL;
2429         sb = (struct super_block *)x;
2430         /* This better be a real Lustre superblock! */
2431         LASSERT(s2lsi(sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2432
2433         /* Note we have not called client_common_fill_super yet, so
2434            proc fns must be able to handle that! */
2435         rc = class_process_proc_param(PARAM_LLITE, lprocfs_llite_obd_vars,
2436                                       lcfg, sb);
2437         if (rc > 0)
2438                 rc = 0;
2439         return rc;
2440 }
2441
2442 /* this function prepares md_op_data hint for passing it down to MD stack. */
2443 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
2444                                       struct inode *i1, struct inode *i2,
2445                                       const char *name, size_t namelen,
2446                                       __u32 mode, __u32 opc, void *data)
2447 {
2448         LASSERT(i1 != NULL);
2449
2450         if (name == NULL) {
2451                 /* Do not reuse namelen for something else. */
2452                 if (namelen != 0)
2453                         return ERR_PTR(-EINVAL);
2454         } else {
2455                 if (namelen > ll_i2sbi(i1)->ll_namelen)
2456                         return ERR_PTR(-ENAMETOOLONG);
2457
2458                 if (!lu_name_is_valid_2(name, namelen))
2459                         return ERR_PTR(-EINVAL);
2460         }
2461
2462         if (op_data == NULL)
2463                 OBD_ALLOC_PTR(op_data);
2464
2465         if (op_data == NULL)
2466                 return ERR_PTR(-ENOMEM);
2467
2468         ll_i2gids(op_data->op_suppgids, i1, i2);
2469         op_data->op_fid1 = *ll_inode2fid(i1);
2470         op_data->op_default_stripe_offset = -1;
2471         if (S_ISDIR(i1->i_mode)) {
2472                 op_data->op_mea1 = ll_i2info(i1)->lli_lsm_md;
2473                 if (opc == LUSTRE_OPC_MKDIR)
2474                         op_data->op_default_stripe_offset =
2475                                    ll_i2info(i1)->lli_def_stripe_offset;
2476         }
2477
2478         if (i2) {
2479                 op_data->op_fid2 = *ll_inode2fid(i2);
2480                 if (S_ISDIR(i2->i_mode))
2481                         op_data->op_mea2 = ll_i2info(i2)->lli_lsm_md;
2482         } else {
2483                 fid_zero(&op_data->op_fid2);
2484         }
2485
2486         if (ll_i2sbi(i1)->ll_flags & LL_SBI_64BIT_HASH)
2487                 op_data->op_cli_flags |= CLI_HASH64;
2488
2489         if (ll_need_32bit_api(ll_i2sbi(i1)))
2490                 op_data->op_cli_flags |= CLI_API32;
2491
2492         op_data->op_name = name;
2493         op_data->op_namelen = namelen;
2494         op_data->op_mode = mode;
2495         op_data->op_mod_time = cfs_time_current_sec();
2496         op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2497         op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2498         op_data->op_cap = cfs_curproc_cap_pack();
2499         if ((opc == LUSTRE_OPC_CREATE) && (name != NULL) &&
2500              filename_is_volatile(name, namelen, &op_data->op_mds)) {
2501                 op_data->op_bias |= MDS_CREATE_VOLATILE;
2502         } else {
2503                 op_data->op_mds = 0;
2504         }
2505         op_data->op_data = data;
2506
2507         return op_data;
2508 }
2509
2510 void ll_finish_md_op_data(struct md_op_data *op_data)
2511 {
2512         security_release_secctx(op_data->op_file_secctx,
2513                                 op_data->op_file_secctx_size);
2514         OBD_FREE_PTR(op_data);
2515 }
2516
2517 #ifdef HAVE_SUPEROPS_USE_DENTRY
2518 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
2519 #else
2520 int ll_show_options(struct seq_file *seq, struct vfsmount *vfs)
2521 #endif
2522 {
2523         struct ll_sb_info *sbi;
2524
2525 #ifdef HAVE_SUPEROPS_USE_DENTRY
2526         LASSERT((seq != NULL) && (dentry != NULL));
2527         sbi = ll_s2sbi(dentry->d_sb);
2528 #else
2529         LASSERT((seq != NULL) && (vfs != NULL));
2530         sbi = ll_s2sbi(vfs->mnt_sb);
2531 #endif
2532
2533         if (sbi->ll_flags & LL_SBI_NOLCK)
2534                 seq_puts(seq, ",nolock");
2535
2536         if (sbi->ll_flags & LL_SBI_FLOCK)
2537                 seq_puts(seq, ",flock");
2538
2539         if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
2540                 seq_puts(seq, ",localflock");
2541
2542         if (sbi->ll_flags & LL_SBI_USER_XATTR)
2543                 seq_puts(seq, ",user_xattr");
2544
2545         if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2546                 seq_puts(seq, ",lazystatfs");
2547
2548         if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
2549                 seq_puts(seq, ",user_fid2path");
2550
2551         if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
2552                 seq_puts(seq, ",always_ping");
2553
2554         RETURN(0);
2555 }
2556
2557 /**
2558  * Get obd name by cmd, and copy out to user space
2559  */
2560 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
2561 {
2562         struct ll_sb_info *sbi = ll_i2sbi(inode);
2563         struct obd_device *obd;
2564         ENTRY;
2565
2566         if (cmd == OBD_IOC_GETDTNAME)
2567                 obd = class_exp2obd(sbi->ll_dt_exp);
2568         else if (cmd == OBD_IOC_GETMDNAME)
2569                 obd = class_exp2obd(sbi->ll_md_exp);
2570         else
2571                 RETURN(-EINVAL);
2572
2573         if (!obd)
2574                 RETURN(-ENOENT);
2575
2576         if (copy_to_user((void __user *)arg, obd->obd_name,
2577                          strlen(obd->obd_name) + 1))
2578                 RETURN(-EFAULT);
2579
2580         RETURN(0);
2581 }
2582
2583 /**
2584  * Get lustre file system name by \a sbi. If \a buf is provided(non-NULL), the
2585  * fsname will be returned in this buffer; otherwise, a static buffer will be
2586  * used to store the fsname and returned to caller.
2587  */
2588 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen)
2589 {
2590         static char fsname_static[MTI_NAME_MAXLEN];
2591         struct lustre_sb_info *lsi = s2lsi(sb);
2592         char *ptr;
2593         int len;
2594
2595         if (buf == NULL) {
2596                 /* this means the caller wants to use static buffer
2597                  * and it doesn't care about race. Usually this is
2598                  * in error reporting path */
2599                 buf = fsname_static;
2600                 buflen = sizeof(fsname_static);
2601         }
2602
2603         len = strlen(lsi->lsi_lmd->lmd_profile);
2604         ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
2605         if (ptr && (strcmp(ptr, "-client") == 0))
2606                 len -= 7;
2607
2608         if (unlikely(len >= buflen))
2609                 len = buflen - 1;
2610         strncpy(buf, lsi->lsi_lmd->lmd_profile, len);
2611         buf[len] = '\0';
2612
2613         return buf;
2614 }
2615
2616 static char* ll_d_path(struct dentry *dentry, char *buf, int bufsize)
2617 {
2618         char *path = NULL;
2619
2620         struct path p;
2621
2622         p.dentry = dentry;
2623         p.mnt = current->fs->root.mnt;
2624         path_get(&p);
2625         path = d_path(&p, buf, bufsize);
2626         path_put(&p);
2627         return path;
2628 }
2629
2630 void ll_dirty_page_discard_warn(struct page *page, int ioret)
2631 {
2632         char *buf, *path = NULL;
2633         struct dentry *dentry = NULL;
2634         struct inode *inode = page->mapping->host;
2635
2636         /* this can be called inside spin lock so use GFP_ATOMIC. */
2637         buf = (char *)__get_free_page(GFP_ATOMIC);
2638         if (buf != NULL) {
2639                 dentry = d_find_alias(page->mapping->host);
2640                 if (dentry != NULL)
2641                         path = ll_d_path(dentry, buf, PAGE_SIZE);
2642         }
2643
2644         CDEBUG(D_WARNING,
2645                "%s: dirty page discard: %s/fid: "DFID"/%s may get corrupted "
2646                "(rc %d)\n", ll_get_fsname(page->mapping->host->i_sb, NULL, 0),
2647                s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
2648                PFID(ll_inode2fid(inode)),
2649                (path && !IS_ERR(path)) ? path : "", ioret);
2650
2651         if (dentry != NULL)
2652                 dput(dentry);
2653
2654         if (buf != NULL)
2655                 free_page((unsigned long)buf);
2656 }
2657
2658 ssize_t ll_copy_user_md(const struct lov_user_md __user *md,
2659                         struct lov_user_md **kbuf)
2660 {
2661         struct lov_user_md      lum;
2662         ssize_t                 lum_size;
2663         ENTRY;
2664
2665         if (copy_from_user(&lum, md, sizeof(lum)))
2666                 RETURN(-EFAULT);
2667
2668         lum_size = ll_lov_user_md_size(&lum);
2669         if (lum_size < 0)
2670                 RETURN(lum_size);
2671
2672         OBD_ALLOC(*kbuf, lum_size);
2673         if (*kbuf == NULL)
2674                 RETURN(-ENOMEM);
2675
2676         if (copy_from_user(*kbuf, md, lum_size) != 0) {
2677                 OBD_FREE(*kbuf, lum_size);
2678                 RETURN(-EFAULT);
2679         }
2680
2681         RETURN(lum_size);
2682 }
2683
2684 /*
2685  * Compute llite root squash state after a change of root squash
2686  * configuration setting or add/remove of a lnet nid
2687  */
2688 void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
2689 {
2690         struct root_squash_info *squash = &sbi->ll_squash;
2691         int i;
2692         bool matched;
2693         struct lnet_process_id id;
2694
2695         /* Update norootsquash flag */
2696         down_write(&squash->rsi_sem);
2697         if (list_empty(&squash->rsi_nosquash_nids))
2698                 sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2699         else {
2700                 /* Do not apply root squash as soon as one of our NIDs is
2701                  * in the nosquash_nids list */
2702                 matched = false;
2703                 i = 0;
2704                 while (LNetGetId(i++, &id) != -ENOENT) {
2705                         if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND)
2706                                 continue;
2707                         if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) {
2708                                 matched = true;
2709                                 break;
2710                         }
2711                 }
2712                 if (matched)
2713                         sbi->ll_flags |= LL_SBI_NOROOTSQUASH;
2714                 else
2715                         sbi->ll_flags &= ~LL_SBI_NOROOTSQUASH;
2716         }
2717         up_write(&squash->rsi_sem);
2718 }
2719
2720 /**
2721  * Parse linkea content to extract information about a given hardlink
2722  *
2723  * \param[in]   ldata      - Initialized linkea data
2724  * \param[in]   linkno     - Link identifier
2725  * \param[out]  parent_fid - The entry's parent FID
2726  * \param[out]  ln         - Entry name destination buffer
2727  *
2728  * \retval 0 on success
2729  * \retval Appropriate negative error code on failure
2730  */
2731 static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
2732                             struct lu_fid *parent_fid, struct lu_name *ln)
2733 {
2734         unsigned int    idx;
2735         int             rc;
2736         ENTRY;
2737
2738         rc = linkea_init_with_rec(ldata);
2739         if (rc < 0)
2740                 RETURN(rc);
2741
2742         if (linkno >= ldata->ld_leh->leh_reccount)
2743                 /* beyond last link */
2744                 RETURN(-ENODATA);
2745
2746         linkea_first_entry(ldata);
2747         for (idx = 0; ldata->ld_lee != NULL; idx++) {
2748                 linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen, ln,
2749                                     parent_fid);
2750                 if (idx == linkno)
2751                         break;
2752
2753                 linkea_next_entry(ldata);
2754         }
2755
2756         if (idx < linkno)
2757                 RETURN(-ENODATA);
2758
2759         RETURN(0);
2760 }
2761
2762 /**
2763  * Get parent FID and name of an identified link. Operation is performed for
2764  * a given link number, letting the caller iterate over linkno to list one or
2765  * all links of an entry.
2766  *
2767  * \param[in]     file - File descriptor against which to perform the operation
2768  * \param[in,out] arg  - User-filled structure containing the linkno to operate
2769  *                       on and the available size. It is eventually filled with
2770  *                       the requested information or left untouched on error
2771  *
2772  * \retval - 0 on success
2773  * \retval - Appropriate negative error code on failure
2774  */
2775 int ll_getparent(struct file *file, struct getparent __user *arg)
2776 {
2777         struct inode            *inode = file_inode(file);
2778         struct linkea_data      *ldata;
2779         struct lu_buf            buf = LU_BUF_NULL;
2780         struct lu_name           ln;
2781         struct lu_fid            parent_fid;
2782         __u32                    linkno;
2783         __u32                    name_size;
2784         int                      rc;
2785
2786         ENTRY;
2787
2788         if (!cfs_capable(CFS_CAP_DAC_READ_SEARCH) &&
2789             !(ll_i2sbi(inode)->ll_flags & LL_SBI_USER_FID2PATH))
2790                 RETURN(-EPERM);
2791
2792         if (get_user(name_size, &arg->gp_name_size))
2793                 RETURN(-EFAULT);
2794
2795         if (get_user(linkno, &arg->gp_linkno))
2796                 RETURN(-EFAULT);
2797
2798         if (name_size > PATH_MAX)
2799                 RETURN(-EINVAL);
2800
2801         OBD_ALLOC(ldata, sizeof(*ldata));
2802         if (ldata == NULL)
2803                 RETURN(-ENOMEM);
2804
2805         rc = linkea_data_new(ldata, &buf);
2806         if (rc < 0)
2807                 GOTO(ldata_free, rc);
2808
2809 #ifdef HAVE_XATTR_HANDLER_FLAGS
2810         rc = ll_xattr_list(inode, XATTR_NAME_LINK, XATTR_TRUSTED_T, buf.lb_buf,
2811                            buf.lb_len, OBD_MD_FLXATTR);
2812 #else
2813         rc = ll_getxattr(file_dentry(file), XATTR_NAME_LINK, buf.lb_buf,
2814                          buf.lb_len);
2815 #endif /* HAVE_XATTR_HANDLER_FLAGS */
2816         if (rc < 0)
2817                 GOTO(lb_free, rc);
2818
2819         rc = ll_linkea_decode(ldata, linkno, &parent_fid, &ln);
2820         if (rc < 0)
2821                 GOTO(lb_free, rc);
2822
2823         if (ln.ln_namelen >= name_size)
2824                 GOTO(lb_free, rc = -EOVERFLOW);
2825
2826         if (copy_to_user(&arg->gp_fid, &parent_fid, sizeof(arg->gp_fid)))
2827                 GOTO(lb_free, rc = -EFAULT);
2828
2829         if (copy_to_user(&arg->gp_name, ln.ln_name, ln.ln_namelen))
2830                 GOTO(lb_free, rc = -EFAULT);
2831
2832         if (put_user('\0', arg->gp_name + ln.ln_namelen))
2833                 GOTO(lb_free, rc = -EFAULT);
2834
2835 lb_free:
2836         lu_buf_free(&buf);
2837 ldata_free:
2838         OBD_FREE(ldata, sizeof(*ldata));
2839
2840         RETURN(rc);
2841 }