47f9ad7cbb59a66130e383c4dd148ce97e822837
[linux-2.6-block.git] / drivers / staging / lustre / 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.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Copyright (c) 2011, 2015, Intel Corporation.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * lustre/llite/llite_lib.c
37  *
38  * Lustre Light Super operations
39  */
40
41 #define DEBUG_SUBSYSTEM S_LLITE
42
43 #include <linux/module.h>
44 #include <linux/statfs.h>
45 #include <linux/types.h>
46 #include <linux/mm.h>
47
48 #include "../include/lustre_lite.h"
49 #include "../include/lustre_ha.h"
50 #include "../include/lustre_dlm.h"
51 #include "../include/lprocfs_status.h"
52 #include "../include/lustre_disk.h"
53 #include "../include/lustre_param.h"
54 #include "../include/lustre_log.h"
55 #include "../include/cl_object.h"
56 #include "../include/obd_cksum.h"
57 #include "llite_internal.h"
58
59 struct kmem_cache *ll_file_data_slab;
60 struct dentry *llite_root;
61 struct kset *llite_kset;
62
63 #ifndef log2
64 #define log2(n) ffz(~(n))
65 #endif
66
67 static struct ll_sb_info *ll_init_sbi(struct super_block *sb)
68 {
69         struct ll_sb_info *sbi = NULL;
70         unsigned long pages;
71         unsigned long lru_page_max;
72         struct sysinfo si;
73         class_uuid_t uuid;
74         int i;
75
76         sbi = kzalloc(sizeof(*sbi), GFP_NOFS);
77         if (!sbi)
78                 return NULL;
79
80         spin_lock_init(&sbi->ll_lock);
81         mutex_init(&sbi->ll_lco.lco_lock);
82         spin_lock_init(&sbi->ll_pp_extent_lock);
83         spin_lock_init(&sbi->ll_process_lock);
84         sbi->ll_rw_stats_on = 0;
85
86         si_meminfo(&si);
87         pages = si.totalram - si.totalhigh;
88         if (pages >> (20 - PAGE_CACHE_SHIFT) < 512)
89                 lru_page_max = pages / 2;
90         else
91                 lru_page_max = (pages / 4) * 3;
92
93         /* initialize lru data */
94         atomic_set(&sbi->ll_cache.ccc_users, 0);
95         sbi->ll_cache.ccc_lru_max = lru_page_max;
96         atomic_set(&sbi->ll_cache.ccc_lru_left, lru_page_max);
97         spin_lock_init(&sbi->ll_cache.ccc_lru_lock);
98         INIT_LIST_HEAD(&sbi->ll_cache.ccc_lru);
99
100         sbi->ll_ra_info.ra_max_pages_per_file = min(pages / 32,
101                                            SBI_DEFAULT_READAHEAD_MAX);
102         sbi->ll_ra_info.ra_max_pages = sbi->ll_ra_info.ra_max_pages_per_file;
103         sbi->ll_ra_info.ra_max_read_ahead_whole_pages =
104                                            SBI_DEFAULT_READAHEAD_WHOLE_MAX;
105
106         ll_generate_random_uuid(uuid);
107         class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
108         CDEBUG(D_CONFIG, "generated uuid: %s\n", sbi->ll_sb_uuid.uuid);
109
110         sbi->ll_flags |= LL_SBI_VERBOSE;
111         sbi->ll_flags |= LL_SBI_CHECKSUM;
112
113         sbi->ll_flags |= LL_SBI_LRU_RESIZE;
114
115         for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
116                 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
117                                pp_r_hist.oh_lock);
118                 spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
119                                pp_w_hist.oh_lock);
120         }
121
122         /* metadata statahead is enabled by default */
123         sbi->ll_sa_max = LL_SA_RPC_DEF;
124         atomic_set(&sbi->ll_sa_total, 0);
125         atomic_set(&sbi->ll_sa_wrong, 0);
126         atomic_set(&sbi->ll_agl_total, 0);
127         sbi->ll_flags |= LL_SBI_AGL_ENABLED;
128
129         sbi->ll_sb = sb;
130
131         return sbi;
132 }
133
134 static void ll_free_sbi(struct super_block *sb)
135 {
136         struct ll_sb_info *sbi = ll_s2sbi(sb);
137
138         kfree(sbi);
139 }
140
141 static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
142                                     struct vfsmount *mnt)
143 {
144         struct inode *root = NULL;
145         struct ll_sb_info *sbi = ll_s2sbi(sb);
146         struct obd_device *obd;
147         struct obd_statfs *osfs = NULL;
148         struct ptlrpc_request *request = NULL;
149         struct obd_connect_data *data = NULL;
150         struct obd_uuid *uuid;
151         struct md_op_data *op_data;
152         struct lustre_md lmd;
153         u64 valid;
154         int size, err, checksum;
155
156         obd = class_name2obd(md);
157         if (!obd) {
158                 CERROR("MD %s: not setup or attached\n", md);
159                 return -EINVAL;
160         }
161
162         data = kzalloc(sizeof(*data), GFP_NOFS);
163         if (!data)
164                 return -ENOMEM;
165
166         osfs = kzalloc(sizeof(*osfs), GFP_NOFS);
167         if (!osfs) {
168                 kfree(data);
169                 return -ENOMEM;
170         }
171
172         if (llite_root) {
173                 err = ldebugfs_register_mountpoint(llite_root, sb, dt, md);
174                 if (err < 0)
175                         CERROR("could not register mount in <debugfs>/lustre/llite\n");
176         }
177
178         /* indicate the features supported by this client */
179         data->ocd_connect_flags = OBD_CONNECT_IBITS    | OBD_CONNECT_NODEVOH  |
180                                   OBD_CONNECT_ATTRFID  |
181                                   OBD_CONNECT_VERSION  | OBD_CONNECT_BRW_SIZE |
182                                   OBD_CONNECT_CANCELSET | OBD_CONNECT_FID     |
183                                   OBD_CONNECT_AT       | OBD_CONNECT_LOV_V3   |
184                                   OBD_CONNECT_RMT_CLIENT | OBD_CONNECT_VBR    |
185                                   OBD_CONNECT_FULL20   | OBD_CONNECT_64BITHASH|
186                                   OBD_CONNECT_EINPROGRESS |
187                                   OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
188                                   OBD_CONNECT_LAYOUTLOCK |
189                                   OBD_CONNECT_PINGLESS |
190                                   OBD_CONNECT_MAX_EASIZE |
191                                   OBD_CONNECT_FLOCK_DEAD |
192                                   OBD_CONNECT_DISP_STRIPE;
193
194         if (sbi->ll_flags & LL_SBI_SOM_PREVIEW)
195                 data->ocd_connect_flags |= OBD_CONNECT_SOM;
196
197         if (sbi->ll_flags & LL_SBI_LRU_RESIZE)
198                 data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
199 #ifdef CONFIG_FS_POSIX_ACL
200         data->ocd_connect_flags |= OBD_CONNECT_ACL | OBD_CONNECT_UMASK;
201 #endif
202
203         if (OBD_FAIL_CHECK(OBD_FAIL_MDC_LIGHTWEIGHT))
204                 /* flag mdc connection as lightweight, only used for test
205                  * purpose, use with care
206                  */
207                 data->ocd_connect_flags |= OBD_CONNECT_LIGHTWEIGHT;
208
209         data->ocd_ibits_known = MDS_INODELOCK_FULL;
210         data->ocd_version = LUSTRE_VERSION_CODE;
211
212         if (sb->s_flags & MS_RDONLY)
213                 data->ocd_connect_flags |= OBD_CONNECT_RDONLY;
214         if (sbi->ll_flags & LL_SBI_USER_XATTR)
215                 data->ocd_connect_flags |= OBD_CONNECT_XATTR;
216
217         if (sbi->ll_flags & LL_SBI_FLOCK)
218                 sbi->ll_fop = &ll_file_operations_flock;
219         else if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
220                 sbi->ll_fop = &ll_file_operations;
221         else
222                 sbi->ll_fop = &ll_file_operations_noflock;
223
224         /* real client */
225         data->ocd_connect_flags |= OBD_CONNECT_REAL;
226         if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
227                 data->ocd_connect_flags |= OBD_CONNECT_RMT_CLIENT_FORCE;
228
229         data->ocd_brw_size = MD_MAX_BRW_SIZE;
230
231         err = obd_connect(NULL, &sbi->ll_md_exp, obd, &sbi->ll_sb_uuid,
232                           data, NULL);
233         if (err == -EBUSY) {
234                 LCONSOLE_ERROR_MSG(0x14f, "An MDT (md %s) is performing recovery, of which this client is not a part. Please wait for recovery to complete, abort, or time out.\n",
235                                    md);
236                 goto out;
237         } else if (err) {
238                 CERROR("cannot connect to %s: rc = %d\n", md, err);
239                 goto out;
240         }
241
242         sbi->ll_md_exp->exp_connect_data = *data;
243
244         err = obd_fid_init(sbi->ll_md_exp->exp_obd, sbi->ll_md_exp,
245                            LUSTRE_SEQ_METADATA);
246         if (err) {
247                 CERROR("%s: Can't init metadata layer FID infrastructure, rc = %d\n",
248                        sbi->ll_md_exp->exp_obd->obd_name, err);
249                 goto out_md;
250         }
251
252         /* For mount, we only need fs info from MDT0, and also in DNE, it
253          * can make sure the client can be mounted as long as MDT0 is
254          * available
255          */
256         err = obd_statfs(NULL, sbi->ll_md_exp, osfs,
257                          cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
258                          OBD_STATFS_FOR_MDT0);
259         if (err)
260                 goto out_md_fid;
261
262         /* This needs to be after statfs to ensure connect has finished.
263          * Note that "data" does NOT contain the valid connect reply.
264          * If connecting to a 1.8 server there will be no LMV device, so
265          * we can access the MDC export directly and exp_connect_flags will
266          * be non-zero, but if accessing an upgraded 2.1 server it will
267          * have the correct flags filled in.
268          * XXX: fill in the LMV exp_connect_flags from MDC(s).
269          */
270         valid = exp_connect_flags(sbi->ll_md_exp) & CLIENT_CONNECT_MDT_REQD;
271         if (exp_connect_flags(sbi->ll_md_exp) != 0 &&
272             valid != CLIENT_CONNECT_MDT_REQD) {
273                 char *buf;
274
275                 buf = kzalloc(PAGE_CACHE_SIZE, GFP_KERNEL);
276                 if (!buf) {
277                         err = -ENOMEM;
278                         goto out_md_fid;
279                 }
280                 obd_connect_flags2str(buf, PAGE_CACHE_SIZE,
281                                       valid ^ CLIENT_CONNECT_MDT_REQD, ",");
282                 LCONSOLE_ERROR_MSG(0x170, "Server %s does not support feature(s) needed for correct operation of this client (%s). Please upgrade server or downgrade client.\n",
283                                    sbi->ll_md_exp->exp_obd->obd_name, buf);
284                 kfree(buf);
285                 err = -EPROTO;
286                 goto out_md_fid;
287         }
288
289         size = sizeof(*data);
290         err = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_CONN_DATA),
291                            KEY_CONN_DATA,  &size, data, NULL);
292         if (err) {
293                 CERROR("%s: Get connect data failed: rc = %d\n",
294                        sbi->ll_md_exp->exp_obd->obd_name, err);
295                 goto out_md_fid;
296         }
297
298         LASSERT(osfs->os_bsize);
299         sb->s_blocksize = osfs->os_bsize;
300         sb->s_blocksize_bits = log2(osfs->os_bsize);
301         sb->s_magic = LL_SUPER_MAGIC;
302         sb->s_maxbytes = MAX_LFS_FILESIZE;
303         sbi->ll_namelen = osfs->os_namelen;
304
305         if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
306             !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
307                 LCONSOLE_INFO("Disabling user_xattr feature because it is not supported on the server\n");
308                 sbi->ll_flags &= ~LL_SBI_USER_XATTR;
309         }
310
311         if (data->ocd_connect_flags & OBD_CONNECT_ACL) {
312 #ifdef MS_POSIXACL
313                 sb->s_flags |= MS_POSIXACL;
314 #endif
315                 sbi->ll_flags |= LL_SBI_ACL;
316         } else {
317                 LCONSOLE_INFO("client wants to enable acl, but mdt not!\n");
318 #ifdef MS_POSIXACL
319                 sb->s_flags &= ~MS_POSIXACL;
320 #endif
321                 sbi->ll_flags &= ~LL_SBI_ACL;
322         }
323
324         if (data->ocd_connect_flags & OBD_CONNECT_RMT_CLIENT) {
325                 if (!(sbi->ll_flags & LL_SBI_RMT_CLIENT)) {
326                         sbi->ll_flags |= LL_SBI_RMT_CLIENT;
327                         LCONSOLE_INFO("client is set as remote by default.\n");
328                 }
329         } else {
330                 if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
331                         sbi->ll_flags &= ~LL_SBI_RMT_CLIENT;
332                         LCONSOLE_INFO("client claims to be remote, but server rejected, forced to be local.\n");
333                 }
334         }
335
336         if (data->ocd_connect_flags & OBD_CONNECT_64BITHASH)
337                 sbi->ll_flags |= LL_SBI_64BIT_HASH;
338
339         if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE)
340                 sbi->ll_md_brw_size = data->ocd_brw_size;
341         else
342                 sbi->ll_md_brw_size = PAGE_CACHE_SIZE;
343
344         if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK) {
345                 LCONSOLE_INFO("Layout lock feature supported.\n");
346                 sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
347         }
348
349         if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
350                 if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
351                         LCONSOLE_INFO(
352                                 "%s: disabling xattr cache due to unknown maximum xattr size.\n",
353                                 dt);
354                 } else {
355                         sbi->ll_flags |= LL_SBI_XATTR_CACHE;
356                         sbi->ll_xattr_cache_enabled = 1;
357                 }
358         }
359
360         obd = class_name2obd(dt);
361         if (!obd) {
362                 CERROR("DT %s: not setup or attached\n", dt);
363                 err = -ENODEV;
364                 goto out_md_fid;
365         }
366
367         data->ocd_connect_flags = OBD_CONNECT_GRANT     | OBD_CONNECT_VERSION  |
368                                   OBD_CONNECT_REQPORTAL | OBD_CONNECT_BRW_SIZE |
369                                   OBD_CONNECT_CANCELSET | OBD_CONNECT_FID      |
370                                   OBD_CONNECT_SRVLOCK   | OBD_CONNECT_TRUNCLOCK|
371                                   OBD_CONNECT_AT | OBD_CONNECT_RMT_CLIENT |
372                                   OBD_CONNECT_OSS_CAPA | OBD_CONNECT_VBR|
373                                   OBD_CONNECT_FULL20 | OBD_CONNECT_64BITHASH |
374                                   OBD_CONNECT_MAXBYTES |
375                                   OBD_CONNECT_EINPROGRESS |
376                                   OBD_CONNECT_JOBSTATS | OBD_CONNECT_LVB_TYPE |
377                                   OBD_CONNECT_LAYOUTLOCK | OBD_CONNECT_PINGLESS;
378
379         if (sbi->ll_flags & LL_SBI_SOM_PREVIEW)
380                 data->ocd_connect_flags |= OBD_CONNECT_SOM;
381
382         if (!OBD_FAIL_CHECK(OBD_FAIL_OSC_CONNECT_CKSUM)) {
383                 /* OBD_CONNECT_CKSUM should always be set, even if checksums are
384                  * disabled by default, because it can still be enabled on the
385                  * fly via /sys. As a consequence, we still need to come to an
386                  * agreement on the supported algorithms at connect time
387                  */
388                 data->ocd_connect_flags |= OBD_CONNECT_CKSUM;
389
390                 if (OBD_FAIL_CHECK(OBD_FAIL_OSC_CKSUM_ADLER_ONLY))
391                         data->ocd_cksum_types = OBD_CKSUM_ADLER;
392                 else
393                         data->ocd_cksum_types = cksum_types_supported_client();
394         }
395
396         data->ocd_connect_flags |= OBD_CONNECT_LRU_RESIZE;
397         if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
398                 data->ocd_connect_flags |= OBD_CONNECT_RMT_CLIENT_FORCE;
399
400         CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d ocd_grant: %d\n",
401                data->ocd_connect_flags,
402                data->ocd_version, data->ocd_grant);
403
404         obd->obd_upcall.onu_owner = &sbi->ll_lco;
405         obd->obd_upcall.onu_upcall = cl_ocd_update;
406
407         data->ocd_brw_size = DT_MAX_BRW_SIZE;
408
409         err = obd_connect(NULL, &sbi->ll_dt_exp, obd, &sbi->ll_sb_uuid, data,
410                           NULL);
411         if (err == -EBUSY) {
412                 LCONSOLE_ERROR_MSG(0x150, "An OST (dt %s) is performing recovery, of which this client is not a part.  Please wait for recovery to complete, abort, or time out.\n",
413                                    dt);
414                 goto out_md;
415         } else if (err) {
416                 CERROR("%s: Cannot connect to %s: rc = %d\n",
417                        sbi->ll_dt_exp->exp_obd->obd_name, dt, err);
418                 goto out_md;
419         }
420
421         sbi->ll_dt_exp->exp_connect_data = *data;
422
423         err = obd_fid_init(sbi->ll_dt_exp->exp_obd, sbi->ll_dt_exp,
424                            LUSTRE_SEQ_METADATA);
425         if (err) {
426                 CERROR("%s: Can't init data layer FID infrastructure, rc = %d\n",
427                        sbi->ll_dt_exp->exp_obd->obd_name, err);
428                 goto out_dt;
429         }
430
431         mutex_lock(&sbi->ll_lco.lco_lock);
432         sbi->ll_lco.lco_flags = data->ocd_connect_flags;
433         sbi->ll_lco.lco_md_exp = sbi->ll_md_exp;
434         sbi->ll_lco.lco_dt_exp = sbi->ll_dt_exp;
435         mutex_unlock(&sbi->ll_lco.lco_lock);
436
437         fid_zero(&sbi->ll_root_fid);
438         err = md_getstatus(sbi->ll_md_exp, &sbi->ll_root_fid);
439         if (err) {
440                 CERROR("cannot mds_connect: rc = %d\n", err);
441                 goto out_lock_cn_cb;
442         }
443         if (!fid_is_sane(&sbi->ll_root_fid)) {
444                 CERROR("%s: Invalid root fid "DFID" during mount\n",
445                        sbi->ll_md_exp->exp_obd->obd_name,
446                        PFID(&sbi->ll_root_fid));
447                 err = -EINVAL;
448                 goto out_lock_cn_cb;
449         }
450         CDEBUG(D_SUPER, "rootfid "DFID"\n", PFID(&sbi->ll_root_fid));
451
452         sb->s_op = &lustre_super_operations;
453 #if THREAD_SIZE >= 8192 /*b=17630*/
454         sb->s_export_op = &lustre_export_operations;
455 #endif
456
457         /* make root inode
458          * XXX: move this to after cbd setup?
459          */
460         valid = OBD_MD_FLGETATTR | OBD_MD_FLBLOCKS;
461         if (sbi->ll_flags & LL_SBI_RMT_CLIENT)
462                 valid |= OBD_MD_FLRMTPERM;
463         else if (sbi->ll_flags & LL_SBI_ACL)
464                 valid |= OBD_MD_FLACL;
465
466         op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
467         if (!op_data) {
468                 err = -ENOMEM;
469                 goto out_lock_cn_cb;
470         }
471
472         op_data->op_fid1 = sbi->ll_root_fid;
473         op_data->op_mode = 0;
474         op_data->op_valid = valid;
475
476         err = md_getattr(sbi->ll_md_exp, op_data, &request);
477         kfree(op_data);
478         if (err) {
479                 CERROR("%s: md_getattr failed for root: rc = %d\n",
480                        sbi->ll_md_exp->exp_obd->obd_name, err);
481                 goto out_lock_cn_cb;
482         }
483
484         err = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
485                                sbi->ll_md_exp, &lmd);
486         if (err) {
487                 CERROR("failed to understand root inode md: rc = %d\n", err);
488                 ptlrpc_req_finished(request);
489                 goto out_lock_cn_cb;
490         }
491
492         LASSERT(fid_is_sane(&sbi->ll_root_fid));
493         root = ll_iget(sb, cl_fid_build_ino(&sbi->ll_root_fid,
494                                             sbi->ll_flags & LL_SBI_32BIT_API),
495                        &lmd);
496         md_free_lustre_md(sbi->ll_md_exp, &lmd);
497         ptlrpc_req_finished(request);
498
499         if (!(root)) {
500                 if (lmd.lsm)
501                         obd_free_memmd(sbi->ll_dt_exp, &lmd.lsm);
502 #ifdef CONFIG_FS_POSIX_ACL
503                 if (lmd.posix_acl) {
504                         posix_acl_release(lmd.posix_acl);
505                         lmd.posix_acl = NULL;
506                 }
507 #endif
508                 err = -EBADF;
509                 CERROR("lustre_lite: bad iget4 for root\n");
510                 goto out_root;
511         }
512
513         err = ll_close_thread_start(&sbi->ll_lcq);
514         if (err) {
515                 CERROR("cannot start close thread: rc %d\n", err);
516                 goto out_root;
517         }
518
519 #ifdef CONFIG_FS_POSIX_ACL
520         if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
521                 rct_init(&sbi->ll_rct);
522                 et_init(&sbi->ll_et);
523         }
524 #endif
525
526         checksum = sbi->ll_flags & LL_SBI_CHECKSUM;
527         err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
528                                  KEY_CHECKSUM, sizeof(checksum), &checksum,
529                                  NULL);
530         cl_sb_init(sb);
531
532         err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CACHE_SET),
533                                  KEY_CACHE_SET, sizeof(sbi->ll_cache),
534                                  &sbi->ll_cache, NULL);
535
536         sb->s_root = d_make_root(root);
537         if (!sb->s_root) {
538                 CERROR("%s: can't make root dentry\n",
539                        ll_get_fsname(sb, NULL, 0));
540                 err = -ENOMEM;
541                 goto out_lock_cn_cb;
542         }
543
544         sbi->ll_sdev_orig = sb->s_dev;
545
546         /* We set sb->s_dev equal on all lustre clients in order to support
547          * NFS export clustering.  NFSD requires that the FSID be the same
548          * on all clients.
549          */
550         /* s_dev is also used in lt_compare() to compare two fs, but that is
551          * only a node-local comparison.
552          */
553         uuid = obd_get_uuid(sbi->ll_md_exp);
554         if (uuid) {
555                 sb->s_dev = get_uuid2int(uuid->uuid, strlen(uuid->uuid));
556                 get_uuid2fsid(uuid->uuid, strlen(uuid->uuid), &sbi->ll_fsid);
557         }
558
559         kfree(data);
560         kfree(osfs);
561
562         return err;
563 out_root:
564         iput(root);
565 out_lock_cn_cb:
566         obd_fid_fini(sbi->ll_dt_exp->exp_obd);
567 out_dt:
568         obd_disconnect(sbi->ll_dt_exp);
569         sbi->ll_dt_exp = NULL;
570         /* Make sure all OScs are gone, since cl_cache is accessing sbi. */
571         obd_zombie_barrier();
572 out_md_fid:
573         obd_fid_fini(sbi->ll_md_exp->exp_obd);
574 out_md:
575         obd_disconnect(sbi->ll_md_exp);
576         sbi->ll_md_exp = NULL;
577 out:
578         kfree(data);
579         kfree(osfs);
580         ldebugfs_unregister_mountpoint(sbi);
581         return err;
582 }
583
584 int ll_get_max_mdsize(struct ll_sb_info *sbi, int *lmmsize)
585 {
586         int size, rc;
587
588         *lmmsize = obd_size_diskmd(sbi->ll_dt_exp, NULL);
589         size = sizeof(int);
590         rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_MAX_EASIZE),
591                           KEY_MAX_EASIZE, &size, lmmsize, NULL);
592         if (rc)
593                 CERROR("Get max mdsize error rc %d\n", rc);
594
595         return rc;
596 }
597
598 int ll_get_default_mdsize(struct ll_sb_info *sbi, int *lmmsize)
599 {
600         int size, rc;
601
602         size = sizeof(int);
603         rc = obd_get_info(NULL, sbi->ll_md_exp, sizeof(KEY_DEFAULT_EASIZE),
604                           KEY_DEFAULT_EASIZE, &size, lmmsize, NULL);
605         if (rc)
606                 CERROR("Get default mdsize error rc %d\n", rc);
607
608         return rc;
609 }
610
611 static void client_common_put_super(struct super_block *sb)
612 {
613         struct ll_sb_info *sbi = ll_s2sbi(sb);
614
615 #ifdef CONFIG_FS_POSIX_ACL
616         if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
617                 et_fini(&sbi->ll_et);
618                 rct_fini(&sbi->ll_rct);
619         }
620 #endif
621
622         ll_close_thread_shutdown(sbi->ll_lcq);
623
624         cl_sb_fini(sb);
625
626         obd_fid_fini(sbi->ll_dt_exp->exp_obd);
627         obd_disconnect(sbi->ll_dt_exp);
628         sbi->ll_dt_exp = NULL;
629         /* wait till all OSCs are gone, since cl_cache is accessing sbi.
630          * see LU-2543.
631          */
632         obd_zombie_barrier();
633
634         ldebugfs_unregister_mountpoint(sbi);
635
636         obd_fid_fini(sbi->ll_md_exp->exp_obd);
637         obd_disconnect(sbi->ll_md_exp);
638         sbi->ll_md_exp = NULL;
639 }
640
641 void ll_kill_super(struct super_block *sb)
642 {
643         struct ll_sb_info *sbi;
644
645         /* not init sb ?*/
646         if (!(sb->s_flags & MS_ACTIVE))
647                 return;
648
649         sbi = ll_s2sbi(sb);
650         /* we need to restore s_dev from changed for clustered NFS before
651          * put_super because new kernels have cached s_dev and change sb->s_dev
652          * in put_super not affected real removing devices
653          */
654         if (sbi) {
655                 sb->s_dev = sbi->ll_sdev_orig;
656                 sbi->ll_umounting = 1;
657         }
658 }
659
660 static inline int ll_set_opt(const char *opt, char *data, int fl)
661 {
662         if (strncmp(opt, data, strlen(opt)) != 0)
663                 return 0;
664         else
665                 return fl;
666 }
667
668 /* non-client-specific mount options are parsed in lmd_parse */
669 static int ll_options(char *options, int *flags)
670 {
671         int tmp;
672         char *s1 = options, *s2;
673
674         if (!options)
675                 return 0;
676
677         CDEBUG(D_CONFIG, "Parsing opts %s\n", options);
678
679         while (*s1) {
680                 CDEBUG(D_SUPER, "next opt=%s\n", s1);
681                 tmp = ll_set_opt("nolock", s1, LL_SBI_NOLCK);
682                 if (tmp) {
683                         *flags |= tmp;
684                         goto next;
685                 }
686                 tmp = ll_set_opt("flock", s1, LL_SBI_FLOCK);
687                 if (tmp) {
688                         *flags |= tmp;
689                         goto next;
690                 }
691                 tmp = ll_set_opt("localflock", s1, LL_SBI_LOCALFLOCK);
692                 if (tmp) {
693                         *flags |= tmp;
694                         goto next;
695                 }
696                 tmp = ll_set_opt("noflock", s1, LL_SBI_FLOCK|LL_SBI_LOCALFLOCK);
697                 if (tmp) {
698                         *flags &= ~tmp;
699                         goto next;
700                 }
701                 tmp = ll_set_opt("user_xattr", s1, LL_SBI_USER_XATTR);
702                 if (tmp) {
703                         *flags |= tmp;
704                         goto next;
705                 }
706                 tmp = ll_set_opt("nouser_xattr", s1, LL_SBI_USER_XATTR);
707                 if (tmp) {
708                         *flags &= ~tmp;
709                         goto next;
710                 }
711                 tmp = ll_set_opt("remote_client", s1, LL_SBI_RMT_CLIENT);
712                 if (tmp) {
713                         *flags |= tmp;
714                         goto next;
715                 }
716                 tmp = ll_set_opt("user_fid2path", s1, LL_SBI_USER_FID2PATH);
717                 if (tmp) {
718                         *flags |= tmp;
719                         goto next;
720                 }
721                 tmp = ll_set_opt("nouser_fid2path", s1, LL_SBI_USER_FID2PATH);
722                 if (tmp) {
723                         *flags &= ~tmp;
724                         goto next;
725                 }
726
727                 tmp = ll_set_opt("checksum", s1, LL_SBI_CHECKSUM);
728                 if (tmp) {
729                         *flags |= tmp;
730                         goto next;
731                 }
732                 tmp = ll_set_opt("nochecksum", s1, LL_SBI_CHECKSUM);
733                 if (tmp) {
734                         *flags &= ~tmp;
735                         goto next;
736                 }
737                 tmp = ll_set_opt("lruresize", s1, LL_SBI_LRU_RESIZE);
738                 if (tmp) {
739                         *flags |= tmp;
740                         goto next;
741                 }
742                 tmp = ll_set_opt("nolruresize", s1, LL_SBI_LRU_RESIZE);
743                 if (tmp) {
744                         *flags &= ~tmp;
745                         goto next;
746                 }
747                 tmp = ll_set_opt("lazystatfs", s1, LL_SBI_LAZYSTATFS);
748                 if (tmp) {
749                         *flags |= tmp;
750                         goto next;
751                 }
752                 tmp = ll_set_opt("nolazystatfs", s1, LL_SBI_LAZYSTATFS);
753                 if (tmp) {
754                         *flags &= ~tmp;
755                         goto next;
756                 }
757                 tmp = ll_set_opt("som_preview", s1, LL_SBI_SOM_PREVIEW);
758                 if (tmp) {
759                         *flags |= tmp;
760                         goto next;
761                 }
762                 tmp = ll_set_opt("32bitapi", s1, LL_SBI_32BIT_API);
763                 if (tmp) {
764                         *flags |= tmp;
765                         goto next;
766                 }
767                 tmp = ll_set_opt("verbose", s1, LL_SBI_VERBOSE);
768                 if (tmp) {
769                         *flags |= tmp;
770                         goto next;
771                 }
772                 tmp = ll_set_opt("noverbose", s1, LL_SBI_VERBOSE);
773                 if (tmp) {
774                         *flags &= ~tmp;
775                         goto next;
776                 }
777                 LCONSOLE_ERROR_MSG(0x152, "Unknown option '%s', won't mount.\n",
778                                    s1);
779                 return -EINVAL;
780
781 next:
782                 /* Find next opt */
783                 s2 = strchr(s1, ',');
784                 if (!s2)
785                         break;
786                 s1 = s2 + 1;
787         }
788         return 0;
789 }
790
791 void ll_lli_init(struct ll_inode_info *lli)
792 {
793         lli->lli_inode_magic = LLI_INODE_MAGIC;
794         lli->lli_flags = 0;
795         lli->lli_ioepoch = 0;
796         lli->lli_maxbytes = MAX_LFS_FILESIZE;
797         spin_lock_init(&lli->lli_lock);
798         lli->lli_posix_acl = NULL;
799         lli->lli_remote_perms = NULL;
800         mutex_init(&lli->lli_rmtperm_mutex);
801         /* Do not set lli_fid, it has been initialized already. */
802         fid_zero(&lli->lli_pfid);
803         INIT_LIST_HEAD(&lli->lli_close_list);
804         lli->lli_rmtperm_time = 0;
805         lli->lli_pending_och = NULL;
806         lli->lli_mds_read_och = NULL;
807         lli->lli_mds_write_och = NULL;
808         lli->lli_mds_exec_och = NULL;
809         lli->lli_open_fd_read_count = 0;
810         lli->lli_open_fd_write_count = 0;
811         lli->lli_open_fd_exec_count = 0;
812         mutex_init(&lli->lli_och_mutex);
813         spin_lock_init(&lli->lli_agl_lock);
814         lli->lli_has_smd = false;
815         spin_lock_init(&lli->lli_layout_lock);
816         ll_layout_version_set(lli, LL_LAYOUT_GEN_NONE);
817         lli->lli_clob = NULL;
818
819         init_rwsem(&lli->lli_xattrs_list_rwsem);
820         mutex_init(&lli->lli_xattrs_enq_lock);
821
822         LASSERT(lli->lli_vfs_inode.i_mode != 0);
823         if (S_ISDIR(lli->lli_vfs_inode.i_mode)) {
824                 mutex_init(&lli->lli_readdir_mutex);
825                 lli->lli_opendir_key = NULL;
826                 lli->lli_sai = NULL;
827                 spin_lock_init(&lli->lli_sa_lock);
828                 lli->lli_opendir_pid = 0;
829         } else {
830                 mutex_init(&lli->lli_size_mutex);
831                 lli->lli_symlink_name = NULL;
832                 init_rwsem(&lli->lli_trunc_sem);
833                 mutex_init(&lli->lli_write_mutex);
834                 init_rwsem(&lli->lli_glimpse_sem);
835                 lli->lli_glimpse_time = 0;
836                 INIT_LIST_HEAD(&lli->lli_agl_list);
837                 lli->lli_agl_index = 0;
838                 lli->lli_async_rc = 0;
839         }
840         mutex_init(&lli->lli_layout_mutex);
841 }
842
843 static inline int ll_bdi_register(struct backing_dev_info *bdi)
844 {
845         static atomic_t ll_bdi_num = ATOMIC_INIT(0);
846
847         bdi->name = "lustre";
848         return bdi_register(bdi, NULL, "lustre-%d",
849                             atomic_inc_return(&ll_bdi_num));
850 }
851
852 int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
853 {
854         struct lustre_profile *lprof = NULL;
855         struct lustre_sb_info *lsi = s2lsi(sb);
856         struct ll_sb_info *sbi;
857         char  *dt = NULL, *md = NULL;
858         char  *profilenm = get_profile_name(sb);
859         struct config_llog_instance *cfg;
860         int    err;
861
862         CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
863
864         cfg = kzalloc(sizeof(*cfg), GFP_NOFS);
865         if (!cfg)
866                 return -ENOMEM;
867
868         try_module_get(THIS_MODULE);
869
870         /* client additional sb info */
871         lsi->lsi_llsbi = sbi = ll_init_sbi(sb);
872         if (!sbi) {
873                 module_put(THIS_MODULE);
874                 kfree(cfg);
875                 return -ENOMEM;
876         }
877
878         err = ll_options(lsi->lsi_lmd->lmd_opts, &sbi->ll_flags);
879         if (err)
880                 goto out_free;
881
882         err = bdi_init(&lsi->lsi_bdi);
883         if (err)
884                 goto out_free;
885         lsi->lsi_flags |= LSI_BDI_INITIALIZED;
886         lsi->lsi_bdi.capabilities = 0;
887         err = ll_bdi_register(&lsi->lsi_bdi);
888         if (err)
889                 goto out_free;
890
891         sb->s_bdi = &lsi->lsi_bdi;
892         /* kernel >= 2.6.38 store dentry operations in sb->s_d_op. */
893         sb->s_d_op = &ll_d_ops;
894
895         /* Generate a string unique to this super, in case some joker tries
896          * to mount the same fs at two mount points.
897          * Use the address of the super itself.
898          */
899         cfg->cfg_instance = sb;
900         cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
901         cfg->cfg_callback = class_config_llog_handler;
902         /* set up client obds */
903         err = lustre_process_log(sb, profilenm, cfg);
904         if (err < 0) {
905                 CERROR("Unable to process log: %d\n", err);
906                 goto out_free;
907         }
908
909         /* Profile set with LCFG_MOUNTOPT so we can find our mdc and osc obds */
910         lprof = class_get_profile(profilenm);
911         if (!lprof) {
912                 LCONSOLE_ERROR_MSG(0x156, "The client profile '%s' could not be read from the MGS.  Does that filesystem exist?\n",
913                                    profilenm);
914                 err = -EINVAL;
915                 goto out_free;
916         }
917         CDEBUG(D_CONFIG, "Found profile %s: mdc=%s osc=%s\n", profilenm,
918                lprof->lp_md, lprof->lp_dt);
919
920         dt = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_dt, cfg->cfg_instance);
921         if (!dt) {
922                 err = -ENOMEM;
923                 goto out_free;
924         }
925
926         md = kasprintf(GFP_NOFS, "%s-%p", lprof->lp_md, cfg->cfg_instance);
927         if (!md) {
928                 err = -ENOMEM;
929                 goto out_free;
930         }
931
932         /* connections, registrations, sb setup */
933         err = client_common_fill_super(sb, md, dt, mnt);
934
935 out_free:
936         kfree(md);
937         kfree(dt);
938         if (err)
939                 ll_put_super(sb);
940         else if (sbi->ll_flags & LL_SBI_VERBOSE)
941                 LCONSOLE_WARN("Mounted %s\n", profilenm);
942
943         kfree(cfg);
944         return err;
945 } /* ll_fill_super */
946
947 void ll_put_super(struct super_block *sb)
948 {
949         struct config_llog_instance cfg, params_cfg;
950         struct obd_device *obd;
951         struct lustre_sb_info *lsi = s2lsi(sb);
952         struct ll_sb_info *sbi = ll_s2sbi(sb);
953         char *profilenm = get_profile_name(sb);
954         int next, force = 1;
955
956         CDEBUG(D_VFSTRACE, "VFS Op: sb %p - %s\n", sb, profilenm);
957
958         cfg.cfg_instance = sb;
959         lustre_end_log(sb, profilenm, &cfg);
960
961         params_cfg.cfg_instance = sb;
962         lustre_end_log(sb, PARAMS_FILENAME, &params_cfg);
963
964         if (sbi->ll_md_exp) {
965                 obd = class_exp2obd(sbi->ll_md_exp);
966                 if (obd)
967                         force = obd->obd_force;
968         }
969
970         /* We need to set force before the lov_disconnect in
971          * lustre_common_put_super, since l_d cleans up osc's as well.
972          */
973         if (force) {
974                 next = 0;
975                 while ((obd = class_devices_in_group(&sbi->ll_sb_uuid,
976                                                      &next)) != NULL) {
977                         obd->obd_force = force;
978                 }
979         }
980
981         if (sbi->ll_lcq) {
982                 /* Only if client_common_fill_super succeeded */
983                 client_common_put_super(sb);
984         }
985
986         next = 0;
987         while ((obd = class_devices_in_group(&sbi->ll_sb_uuid, &next)))
988                 class_manual_cleanup(obd);
989
990         if (sbi->ll_flags & LL_SBI_VERBOSE)
991                 LCONSOLE_WARN("Unmounted %s\n", profilenm ? profilenm : "");
992
993         if (profilenm)
994                 class_del_profile(profilenm);
995
996         if (lsi->lsi_flags & LSI_BDI_INITIALIZED) {
997                 bdi_destroy(&lsi->lsi_bdi);
998                 lsi->lsi_flags &= ~LSI_BDI_INITIALIZED;
999         }
1000
1001         ll_free_sbi(sb);
1002         lsi->lsi_llsbi = NULL;
1003
1004         lustre_common_put_super(sb);
1005
1006         module_put(THIS_MODULE);
1007 } /* client_put_super */
1008
1009 struct inode *ll_inode_from_resource_lock(struct ldlm_lock *lock)
1010 {
1011         struct inode *inode = NULL;
1012
1013         /* NOTE: we depend on atomic igrab() -bzzz */
1014         lock_res_and_lock(lock);
1015         if (lock->l_resource->lr_lvb_inode) {
1016                 struct ll_inode_info *lli;
1017
1018                 lli = ll_i2info(lock->l_resource->lr_lvb_inode);
1019                 if (lli->lli_inode_magic == LLI_INODE_MAGIC) {
1020                         inode = igrab(lock->l_resource->lr_lvb_inode);
1021                 } else {
1022                         inode = lock->l_resource->lr_lvb_inode;
1023                         LDLM_DEBUG_LIMIT(inode->i_state & I_FREEING ?  D_INFO :
1024                                          D_WARNING, lock, "lr_lvb_inode %p is bogus: magic %08x",
1025                                          lock->l_resource->lr_lvb_inode,
1026                                          lli->lli_inode_magic);
1027                         inode = NULL;
1028                 }
1029         }
1030         unlock_res_and_lock(lock);
1031         return inode;
1032 }
1033
1034 void ll_clear_inode(struct inode *inode)
1035 {
1036         struct ll_inode_info *lli = ll_i2info(inode);
1037         struct ll_sb_info *sbi = ll_i2sbi(inode);
1038
1039         CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1040                inode->i_generation, inode);
1041
1042         if (S_ISDIR(inode->i_mode)) {
1043                 /* these should have been cleared in ll_file_release */
1044                 LASSERT(!lli->lli_opendir_key);
1045                 LASSERT(!lli->lli_sai);
1046                 LASSERT(lli->lli_opendir_pid == 0);
1047         }
1048
1049         spin_lock(&lli->lli_lock);
1050         ll_i2info(inode)->lli_flags &= ~LLIF_MDS_SIZE_LOCK;
1051         spin_unlock(&lli->lli_lock);
1052         md_null_inode(sbi->ll_md_exp, ll_inode2fid(inode));
1053
1054         LASSERT(!lli->lli_open_fd_write_count);
1055         LASSERT(!lli->lli_open_fd_read_count);
1056         LASSERT(!lli->lli_open_fd_exec_count);
1057
1058         if (lli->lli_mds_write_och)
1059                 ll_md_real_close(inode, FMODE_WRITE);
1060         if (lli->lli_mds_exec_och)
1061                 ll_md_real_close(inode, FMODE_EXEC);
1062         if (lli->lli_mds_read_och)
1063                 ll_md_real_close(inode, FMODE_READ);
1064
1065         if (S_ISLNK(inode->i_mode)) {
1066                 kfree(lli->lli_symlink_name);
1067                 lli->lli_symlink_name = NULL;
1068         }
1069
1070         ll_xattr_cache_destroy(inode);
1071
1072         if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
1073                 LASSERT(!lli->lli_posix_acl);
1074                 if (lli->lli_remote_perms) {
1075                         free_rmtperm_hash(lli->lli_remote_perms);
1076                         lli->lli_remote_perms = NULL;
1077                 }
1078         }
1079 #ifdef CONFIG_FS_POSIX_ACL
1080         else if (lli->lli_posix_acl) {
1081                 LASSERT(atomic_read(&lli->lli_posix_acl->a_refcount) == 1);
1082                 LASSERT(!lli->lli_remote_perms);
1083                 posix_acl_release(lli->lli_posix_acl);
1084                 lli->lli_posix_acl = NULL;
1085         }
1086 #endif
1087         lli->lli_inode_magic = LLI_INODE_DEAD;
1088
1089         if (!S_ISDIR(inode->i_mode))
1090                 LASSERT(list_empty(&lli->lli_agl_list));
1091
1092         /*
1093          * XXX This has to be done before lsm is freed below, because
1094          * cl_object still uses inode lsm.
1095          */
1096         cl_inode_fini(inode);
1097         lli->lli_has_smd = false;
1098 }
1099
1100 #define TIMES_SET_FLAGS (ATTR_MTIME_SET | ATTR_ATIME_SET | ATTR_TIMES_SET)
1101
1102 static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data,
1103                          struct md_open_data **mod)
1104 {
1105         struct lustre_md md;
1106         struct inode *inode = d_inode(dentry);
1107         struct ll_sb_info *sbi = ll_i2sbi(inode);
1108         struct ptlrpc_request *request = NULL;
1109         int rc, ia_valid;
1110
1111         op_data = ll_prep_md_op_data(op_data, inode, NULL, NULL, 0, 0,
1112                                      LUSTRE_OPC_ANY, NULL);
1113         if (IS_ERR(op_data))
1114                 return PTR_ERR(op_data);
1115
1116         rc = md_setattr(sbi->ll_md_exp, op_data, NULL, 0, NULL, 0,
1117                         &request, mod);
1118         if (rc) {
1119                 ptlrpc_req_finished(request);
1120                 if (rc == -ENOENT) {
1121                         clear_nlink(inode);
1122                         /* Unlinked special device node? Or just a race?
1123                          * Pretend we did everything.
1124                          */
1125                         if (!S_ISREG(inode->i_mode) &&
1126                             !S_ISDIR(inode->i_mode)) {
1127                                 ia_valid = op_data->op_attr.ia_valid;
1128                                 op_data->op_attr.ia_valid &= ~TIMES_SET_FLAGS;
1129                                 rc = simple_setattr(dentry, &op_data->op_attr);
1130                                 op_data->op_attr.ia_valid = ia_valid;
1131                         }
1132                 } else if (rc != -EPERM && rc != -EACCES && rc != -ETXTBSY) {
1133                         CERROR("md_setattr fails: rc = %d\n", rc);
1134                 }
1135                 return rc;
1136         }
1137
1138         rc = md_get_lustre_md(sbi->ll_md_exp, request, sbi->ll_dt_exp,
1139                               sbi->ll_md_exp, &md);
1140         if (rc) {
1141                 ptlrpc_req_finished(request);
1142                 return rc;
1143         }
1144
1145         ia_valid = op_data->op_attr.ia_valid;
1146         /* inode size will be in cl_setattr_ost, can't do it now since dirty
1147          * cache is not cleared yet.
1148          */
1149         op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
1150         rc = simple_setattr(dentry, &op_data->op_attr);
1151         op_data->op_attr.ia_valid = ia_valid;
1152
1153         /* Extract epoch data if obtained. */
1154         op_data->op_handle = md.body->handle;
1155         op_data->op_ioepoch = md.body->ioepoch;
1156
1157         ll_update_inode(inode, &md);
1158         ptlrpc_req_finished(request);
1159
1160         return rc;
1161 }
1162
1163 /* Close IO epoch and send Size-on-MDS attribute update. */
1164 static int ll_setattr_done_writing(struct inode *inode,
1165                                    struct md_op_data *op_data,
1166                                    struct md_open_data *mod)
1167 {
1168         struct ll_inode_info *lli = ll_i2info(inode);
1169         int rc = 0;
1170
1171         if (!S_ISREG(inode->i_mode))
1172                 return 0;
1173
1174         CDEBUG(D_INODE, "Epoch %llu closed on "DFID" for truncate\n",
1175                op_data->op_ioepoch, PFID(&lli->lli_fid));
1176
1177         op_data->op_flags = MF_EPOCH_CLOSE;
1178         ll_done_writing_attr(inode, op_data);
1179         ll_pack_inode2opdata(inode, op_data, NULL);
1180
1181         rc = md_done_writing(ll_i2sbi(inode)->ll_md_exp, op_data, mod);
1182         if (rc == -EAGAIN)
1183                 /* MDS has instructed us to obtain Size-on-MDS attribute
1184                  * from OSTs and send setattr to back to MDS.
1185                  */
1186                 rc = ll_som_update(inode, op_data);
1187         else if (rc)
1188                 CERROR("inode %lu mdc truncate failed: rc = %d\n",
1189                        inode->i_ino, rc);
1190         return rc;
1191 }
1192
1193 /* If this inode has objects allocated to it (lsm != NULL), then the OST
1194  * object(s) determine the file size and mtime.  Otherwise, the MDS will
1195  * keep these values until such a time that objects are allocated for it.
1196  * We do the MDS operations first, as it is checking permissions for us.
1197  * We don't to the MDS RPC if there is nothing that we want to store there,
1198  * otherwise there is no harm in updating mtime/atime on the MDS if we are
1199  * going to do an RPC anyways.
1200  *
1201  * If we are doing a truncate, we will send the mtime and ctime updates
1202  * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
1203  * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
1204  * at the same time.
1205  *
1206  * In case of HSMimport, we only set attr on MDS.
1207  */
1208 int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
1209 {
1210         struct inode *inode = d_inode(dentry);
1211         struct ll_inode_info *lli = ll_i2info(inode);
1212         struct md_op_data *op_data = NULL;
1213         struct md_open_data *mod = NULL;
1214         bool file_is_released = false;
1215         int rc = 0, rc1 = 0;
1216
1217         CDEBUG(D_VFSTRACE,
1218                "%s: setattr inode %p/fid:" DFID
1219                " from %llu to %llu, valid %x, hsm_import %d\n",
1220                ll_get_fsname(inode->i_sb, NULL, 0), inode,
1221                PFID(&lli->lli_fid), i_size_read(inode), attr->ia_size,
1222                attr->ia_valid, hsm_import);
1223
1224         if (attr->ia_valid & ATTR_SIZE) {
1225                 /* Check new size against VFS/VM file size limit and rlimit */
1226                 rc = inode_newsize_ok(inode, attr->ia_size);
1227                 if (rc)
1228                         return rc;
1229
1230                 /* The maximum Lustre file size is variable, based on the
1231                  * OST maximum object size and number of stripes.  This
1232                  * needs another check in addition to the VFS check above.
1233                  */
1234                 if (attr->ia_size > ll_file_maxbytes(inode)) {
1235                         CDEBUG(D_INODE, "file "DFID" too large %llu > %llu\n",
1236                                PFID(&lli->lli_fid), attr->ia_size,
1237                                ll_file_maxbytes(inode));
1238                         return -EFBIG;
1239                 }
1240
1241                 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
1242         }
1243
1244         /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
1245         if (attr->ia_valid & TIMES_SET_FLAGS) {
1246                 if ((!uid_eq(current_fsuid(), inode->i_uid)) &&
1247                     !capable(CFS_CAP_FOWNER))
1248                         return -EPERM;
1249         }
1250
1251         /* We mark all of the fields "set" so MDS/OST does not re-set them */
1252         if (attr->ia_valid & ATTR_CTIME) {
1253                 attr->ia_ctime = CURRENT_TIME;
1254                 attr->ia_valid |= ATTR_CTIME_SET;
1255         }
1256         if (!(attr->ia_valid & ATTR_ATIME_SET) &&
1257             (attr->ia_valid & ATTR_ATIME)) {
1258                 attr->ia_atime = CURRENT_TIME;
1259                 attr->ia_valid |= ATTR_ATIME_SET;
1260         }
1261         if (!(attr->ia_valid & ATTR_MTIME_SET) &&
1262             (attr->ia_valid & ATTR_MTIME)) {
1263                 attr->ia_mtime = CURRENT_TIME;
1264                 attr->ia_valid |= ATTR_MTIME_SET;
1265         }
1266
1267         if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
1268                 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %llu\n",
1269                        LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
1270                        (s64)ktime_get_real_seconds());
1271
1272         /* If we are changing file size, file content is modified, flag it. */
1273         if (attr->ia_valid & ATTR_SIZE) {
1274                 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1275                 spin_lock(&lli->lli_lock);
1276                 lli->lli_flags |= LLIF_DATA_MODIFIED;
1277                 spin_unlock(&lli->lli_lock);
1278         }
1279
1280         /* We always do an MDS RPC, even if we're only changing the size;
1281          * only the MDS knows whether truncate() should fail with -ETXTBUSY
1282          */
1283
1284         op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
1285         if (!op_data)
1286                 return -ENOMEM;
1287
1288         if (!S_ISDIR(inode->i_mode))
1289                 inode_unlock(inode);
1290
1291         memcpy(&op_data->op_attr, attr, sizeof(*attr));
1292
1293         /* Open epoch for truncate. */
1294         if (exp_connect_som(ll_i2mdexp(inode)) &&
1295             (attr->ia_valid & (ATTR_SIZE | ATTR_MTIME | ATTR_MTIME_SET)))
1296                 op_data->op_flags = MF_EPOCH_OPEN;
1297
1298         /* truncate on a released file must failed with -ENODATA,
1299          * so size must not be set on MDS for released file
1300          * but other attributes must be set
1301          */
1302         if (S_ISREG(inode->i_mode)) {
1303                 struct lov_stripe_md *lsm;
1304                 __u32 gen;
1305
1306                 ll_layout_refresh(inode, &gen);
1307                 lsm = ccc_inode_lsm_get(inode);
1308                 if (lsm && lsm->lsm_pattern & LOV_PATTERN_F_RELEASED)
1309                         file_is_released = true;
1310                 ccc_inode_lsm_put(inode, lsm);
1311         }
1312
1313         /* if not in HSM import mode, clear size attr for released file
1314          * we clear the attribute send to MDT in op_data, not the original
1315          * received from caller in attr which is used later to
1316          * decide return code
1317          */
1318         if (file_is_released && (attr->ia_valid & ATTR_SIZE) && !hsm_import)
1319                 op_data->op_attr.ia_valid &= ~ATTR_SIZE;
1320
1321         rc = ll_md_setattr(dentry, op_data, &mod);
1322         if (rc)
1323                 goto out;
1324
1325         /* truncate failed (only when non HSM import), others succeed */
1326         if (file_is_released) {
1327                 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1328                         rc = -ENODATA;
1329                 else
1330                         rc = 0;
1331                 goto out;
1332         }
1333
1334         /* RPC to MDT is sent, cancel data modification flag */
1335         if (rc == 0 && (op_data->op_bias & MDS_DATA_MODIFIED)) {
1336                 spin_lock(&lli->lli_lock);
1337                 lli->lli_flags &= ~LLIF_DATA_MODIFIED;
1338                 spin_unlock(&lli->lli_lock);
1339         }
1340
1341         ll_ioepoch_open(lli, op_data->op_ioepoch);
1342         if (!S_ISREG(inode->i_mode)) {
1343                 rc = 0;
1344                 goto out;
1345         }
1346
1347         if (attr->ia_valid & (ATTR_SIZE |
1348                               ATTR_ATIME | ATTR_ATIME_SET |
1349                               ATTR_MTIME | ATTR_MTIME_SET)) {
1350                 /* For truncate and utimes sending attributes to OSTs, setting
1351                  * mtime/atime to the past will be performed under PW [0:EOF]
1352                  * extent lock (new_size:EOF for truncate).  It may seem
1353                  * excessive to send mtime/atime updates to OSTs when not
1354                  * setting times to past, but it is necessary due to possible
1355                  * time de-synchronization between MDT inode and OST objects
1356                  */
1357                 if (attr->ia_valid & ATTR_SIZE)
1358                         down_write(&lli->lli_trunc_sem);
1359                 rc = cl_setattr_ost(inode, attr);
1360                 if (attr->ia_valid & ATTR_SIZE)
1361                         up_write(&lli->lli_trunc_sem);
1362         }
1363 out:
1364         if (op_data->op_ioepoch) {
1365                 rc1 = ll_setattr_done_writing(inode, op_data, mod);
1366                 if (!rc)
1367                         rc = rc1;
1368         }
1369         ll_finish_md_op_data(op_data);
1370
1371         if (!S_ISDIR(inode->i_mode)) {
1372                 inode_lock(inode);
1373                 if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
1374                         inode_dio_wait(inode);
1375         }
1376
1377         ll_stats_ops_tally(ll_i2sbi(inode), (attr->ia_valid & ATTR_SIZE) ?
1378                         LPROC_LL_TRUNC : LPROC_LL_SETATTR, 1);
1379
1380         return rc;
1381 }
1382
1383 int ll_setattr(struct dentry *de, struct iattr *attr)
1384 {
1385         int mode = d_inode(de)->i_mode;
1386
1387         if ((attr->ia_valid & (ATTR_CTIME|ATTR_SIZE|ATTR_MODE)) ==
1388                               (ATTR_CTIME|ATTR_SIZE|ATTR_MODE))
1389                 attr->ia_valid |= MDS_OPEN_OWNEROVERRIDE;
1390
1391         if (((attr->ia_valid & (ATTR_MODE|ATTR_FORCE|ATTR_SIZE)) ==
1392                                (ATTR_SIZE|ATTR_MODE)) &&
1393             (((mode & S_ISUID) && !(attr->ia_mode & S_ISUID)) ||
1394              (((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1395               !(attr->ia_mode & S_ISGID))))
1396                 attr->ia_valid |= ATTR_FORCE;
1397
1398         if ((attr->ia_valid & ATTR_MODE) &&
1399             (mode & S_ISUID) &&
1400             !(attr->ia_mode & S_ISUID) &&
1401             !(attr->ia_valid & ATTR_KILL_SUID))
1402                 attr->ia_valid |= ATTR_KILL_SUID;
1403
1404         if ((attr->ia_valid & ATTR_MODE) &&
1405             ((mode & (S_ISGID|S_IXGRP)) == (S_ISGID|S_IXGRP)) &&
1406             !(attr->ia_mode & S_ISGID) &&
1407             !(attr->ia_valid & ATTR_KILL_SGID))
1408                 attr->ia_valid |= ATTR_KILL_SGID;
1409
1410         return ll_setattr_raw(de, attr, false);
1411 }
1412
1413 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
1414                        __u64 max_age, __u32 flags)
1415 {
1416         struct ll_sb_info *sbi = ll_s2sbi(sb);
1417         struct obd_statfs obd_osfs;
1418         int rc;
1419
1420         rc = obd_statfs(NULL, sbi->ll_md_exp, osfs, max_age, flags);
1421         if (rc) {
1422                 CERROR("md_statfs fails: rc = %d\n", rc);
1423                 return rc;
1424         }
1425
1426         osfs->os_type = sb->s_magic;
1427
1428         CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
1429                osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,
1430                osfs->os_files);
1431
1432         if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
1433                 flags |= OBD_STATFS_NODELAY;
1434
1435         rc = obd_statfs_rqset(sbi->ll_dt_exp, &obd_osfs, max_age, flags);
1436         if (rc) {
1437                 CERROR("obd_statfs fails: rc = %d\n", rc);
1438                 return rc;
1439         }
1440
1441         CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
1442                obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
1443                obd_osfs.os_files);
1444
1445         osfs->os_bsize = obd_osfs.os_bsize;
1446         osfs->os_blocks = obd_osfs.os_blocks;
1447         osfs->os_bfree = obd_osfs.os_bfree;
1448         osfs->os_bavail = obd_osfs.os_bavail;
1449
1450         /* If we don't have as many objects free on the OST as inodes
1451          * on the MDS, we reduce the total number of inodes to
1452          * compensate, so that the "inodes in use" number is correct.
1453          */
1454         if (obd_osfs.os_ffree < osfs->os_ffree) {
1455                 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
1456                         obd_osfs.os_ffree;
1457                 osfs->os_ffree = obd_osfs.os_ffree;
1458         }
1459
1460         return rc;
1461 }
1462
1463 int ll_statfs(struct dentry *de, struct kstatfs *sfs)
1464 {
1465         struct super_block *sb = de->d_sb;
1466         struct obd_statfs osfs;
1467         int rc;
1468
1469         CDEBUG(D_VFSTRACE, "VFS Op: at %llu jiffies\n", get_jiffies_64());
1470         ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
1471
1472         /* Some amount of caching on the client is allowed */
1473         rc = ll_statfs_internal(sb, &osfs,
1474                                 cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS),
1475                                 0);
1476         if (rc)
1477                 return rc;
1478
1479         statfs_unpack(sfs, &osfs);
1480
1481         /* We need to downshift for all 32-bit kernels, because we can't
1482          * tell if the kernel is being called via sys_statfs64() or not.
1483          * Stop before overflowing f_bsize - in which case it is better
1484          * to just risk EOVERFLOW if caller is using old sys_statfs().
1485          */
1486         if (sizeof(long) < 8) {
1487                 while (osfs.os_blocks > ~0UL && sfs->f_bsize < 0x40000000) {
1488                         sfs->f_bsize <<= 1;
1489
1490                         osfs.os_blocks >>= 1;
1491                         osfs.os_bfree >>= 1;
1492                         osfs.os_bavail >>= 1;
1493                 }
1494         }
1495
1496         sfs->f_blocks = osfs.os_blocks;
1497         sfs->f_bfree = osfs.os_bfree;
1498         sfs->f_bavail = osfs.os_bavail;
1499         sfs->f_fsid = ll_s2sbi(sb)->ll_fsid;
1500         return 0;
1501 }
1502
1503 void ll_inode_size_lock(struct inode *inode)
1504 {
1505         struct ll_inode_info *lli;
1506
1507         LASSERT(!S_ISDIR(inode->i_mode));
1508
1509         lli = ll_i2info(inode);
1510         mutex_lock(&lli->lli_size_mutex);
1511 }
1512
1513 void ll_inode_size_unlock(struct inode *inode)
1514 {
1515         struct ll_inode_info *lli;
1516
1517         lli = ll_i2info(inode);
1518         mutex_unlock(&lli->lli_size_mutex);
1519 }
1520
1521 void ll_update_inode(struct inode *inode, struct lustre_md *md)
1522 {
1523         struct ll_inode_info *lli = ll_i2info(inode);
1524         struct mdt_body *body = md->body;
1525         struct lov_stripe_md *lsm = md->lsm;
1526         struct ll_sb_info *sbi = ll_i2sbi(inode);
1527
1528         LASSERT((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
1529         if (lsm) {
1530                 if (!lli->lli_has_smd &&
1531                     !(sbi->ll_flags & LL_SBI_LAYOUT_LOCK))
1532                         cl_file_inode_init(inode, md);
1533
1534                 lli->lli_maxbytes = lsm->lsm_maxbytes;
1535                 if (lli->lli_maxbytes > MAX_LFS_FILESIZE)
1536                         lli->lli_maxbytes = MAX_LFS_FILESIZE;
1537         }
1538
1539         if (sbi->ll_flags & LL_SBI_RMT_CLIENT) {
1540                 if (body->valid & OBD_MD_FLRMTPERM)
1541                         ll_update_remote_perm(inode, md->remote_perm);
1542         }
1543 #ifdef CONFIG_FS_POSIX_ACL
1544         else if (body->valid & OBD_MD_FLACL) {
1545                 spin_lock(&lli->lli_lock);
1546                 if (lli->lli_posix_acl)
1547                         posix_acl_release(lli->lli_posix_acl);
1548                 lli->lli_posix_acl = md->posix_acl;
1549                 spin_unlock(&lli->lli_lock);
1550         }
1551 #endif
1552         inode->i_ino = cl_fid_build_ino(&body->fid1,
1553                                         sbi->ll_flags & LL_SBI_32BIT_API);
1554         inode->i_generation = cl_fid_build_gen(&body->fid1);
1555
1556         if (body->valid & OBD_MD_FLATIME) {
1557                 if (body->atime > LTIME_S(inode->i_atime))
1558                         LTIME_S(inode->i_atime) = body->atime;
1559                 lli->lli_lvb.lvb_atime = body->atime;
1560         }
1561         if (body->valid & OBD_MD_FLMTIME) {
1562                 if (body->mtime > LTIME_S(inode->i_mtime)) {
1563                         CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %llu\n",
1564                                inode->i_ino, LTIME_S(inode->i_mtime),
1565                                body->mtime);
1566                         LTIME_S(inode->i_mtime) = body->mtime;
1567                 }
1568                 lli->lli_lvb.lvb_mtime = body->mtime;
1569         }
1570         if (body->valid & OBD_MD_FLCTIME) {
1571                 if (body->ctime > LTIME_S(inode->i_ctime))
1572                         LTIME_S(inode->i_ctime) = body->ctime;
1573                 lli->lli_lvb.lvb_ctime = body->ctime;
1574         }
1575         if (body->valid & OBD_MD_FLMODE)
1576                 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1577         if (body->valid & OBD_MD_FLTYPE)
1578                 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1579         LASSERT(inode->i_mode != 0);
1580         if (S_ISREG(inode->i_mode))
1581                 inode->i_blkbits = min(PTLRPC_MAX_BRW_BITS + 1,
1582                                        LL_MAX_BLKSIZE_BITS);
1583         else
1584                 inode->i_blkbits = inode->i_sb->s_blocksize_bits;
1585         if (body->valid & OBD_MD_FLUID)
1586                 inode->i_uid = make_kuid(&init_user_ns, body->uid);
1587         if (body->valid & OBD_MD_FLGID)
1588                 inode->i_gid = make_kgid(&init_user_ns, body->gid);
1589         if (body->valid & OBD_MD_FLFLAGS)
1590                 inode->i_flags = ll_ext_to_inode_flags(body->flags);
1591         if (body->valid & OBD_MD_FLNLINK)
1592                 set_nlink(inode, body->nlink);
1593         if (body->valid & OBD_MD_FLRDEV)
1594                 inode->i_rdev = old_decode_dev(body->rdev);
1595
1596         if (body->valid & OBD_MD_FLID) {
1597                 /* FID shouldn't be changed! */
1598                 if (fid_is_sane(&lli->lli_fid)) {
1599                         LASSERTF(lu_fid_eq(&lli->lli_fid, &body->fid1),
1600                                  "Trying to change FID "DFID
1601                                  " to the "DFID", inode %lu/%u(%p)\n",
1602                                  PFID(&lli->lli_fid), PFID(&body->fid1),
1603                                  inode->i_ino, inode->i_generation, inode);
1604                 } else
1605                         lli->lli_fid = body->fid1;
1606         }
1607
1608         LASSERT(fid_seq(&lli->lli_fid) != 0);
1609
1610         if (body->valid & OBD_MD_FLSIZE) {
1611                 if (exp_connect_som(ll_i2mdexp(inode)) &&
1612                     S_ISREG(inode->i_mode)) {
1613                         struct lustre_handle lockh;
1614                         enum ldlm_mode mode;
1615
1616                         /* As it is possible a blocking ast has been processed
1617                          * by this time, we need to check there is an UPDATE
1618                          * lock on the client and set LLIF_MDS_SIZE_LOCK holding
1619                          * it.
1620                          */
1621                         mode = ll_take_md_lock(inode, MDS_INODELOCK_UPDATE,
1622                                                &lockh, LDLM_FL_CBPENDING,
1623                                                LCK_CR | LCK_CW |
1624                                                LCK_PR | LCK_PW);
1625                         if (mode) {
1626                                 if (lli->lli_flags & (LLIF_DONE_WRITING |
1627                                                       LLIF_EPOCH_PENDING |
1628                                                       LLIF_SOM_DIRTY)) {
1629                                         CERROR("ino %lu flags %u still has size authority! do not trust the size got from MDS\n",
1630                                                inode->i_ino, lli->lli_flags);
1631                                 } else {
1632                                         /* Use old size assignment to avoid
1633                                          * deadlock bz14138 & bz14326
1634                                          */
1635                                         i_size_write(inode, body->size);
1636                                         spin_lock(&lli->lli_lock);
1637                                         lli->lli_flags |= LLIF_MDS_SIZE_LOCK;
1638                                         spin_unlock(&lli->lli_lock);
1639                                 }
1640                                 ldlm_lock_decref(&lockh, mode);
1641                         }
1642                 } else {
1643                         /* Use old size assignment to avoid
1644                          * deadlock bz14138 & bz14326
1645                          */
1646                         i_size_write(inode, body->size);
1647
1648                         CDEBUG(D_VFSTRACE, "inode=%lu, updating i_size %llu\n",
1649                                inode->i_ino, (unsigned long long)body->size);
1650                 }
1651
1652                 if (body->valid & OBD_MD_FLBLOCKS)
1653                         inode->i_blocks = body->blocks;
1654         }
1655
1656         if (body->valid & OBD_MD_TSTATE) {
1657                 if (body->t_state & MS_RESTORE)
1658                         lli->lli_flags |= LLIF_FILE_RESTORING;
1659         }
1660 }
1661
1662 void ll_read_inode2(struct inode *inode, void *opaque)
1663 {
1664         struct lustre_md *md = opaque;
1665         struct ll_inode_info *lli = ll_i2info(inode);
1666
1667         CDEBUG(D_VFSTRACE, "VFS Op:inode="DFID"(%p)\n",
1668                PFID(&lli->lli_fid), inode);
1669
1670         LASSERT(!lli->lli_has_smd);
1671
1672         /* Core attributes from the MDS first.  This is a new inode, and
1673          * the VFS doesn't zero times in the core inode so we have to do
1674          * it ourselves.  They will be overwritten by either MDS or OST
1675          * attributes - we just need to make sure they aren't newer.
1676          */
1677         LTIME_S(inode->i_mtime) = 0;
1678         LTIME_S(inode->i_atime) = 0;
1679         LTIME_S(inode->i_ctime) = 0;
1680         inode->i_rdev = 0;
1681         ll_update_inode(inode, md);
1682
1683         /* OIDEBUG(inode); */
1684
1685         if (S_ISREG(inode->i_mode)) {
1686                 struct ll_sb_info *sbi = ll_i2sbi(inode);
1687
1688                 inode->i_op = &ll_file_inode_operations;
1689                 inode->i_fop = sbi->ll_fop;
1690                 inode->i_mapping->a_ops = (struct address_space_operations *)&ll_aops;
1691         } else if (S_ISDIR(inode->i_mode)) {
1692                 inode->i_op = &ll_dir_inode_operations;
1693                 inode->i_fop = &ll_dir_operations;
1694         } else if (S_ISLNK(inode->i_mode)) {
1695                 inode->i_op = &ll_fast_symlink_inode_operations;
1696         } else {
1697                 inode->i_op = &ll_special_inode_operations;
1698
1699                 init_special_inode(inode, inode->i_mode,
1700                                    inode->i_rdev);
1701         }
1702 }
1703
1704 void ll_delete_inode(struct inode *inode)
1705 {
1706         struct cl_inode_info *lli = cl_i2info(inode);
1707
1708         if (S_ISREG(inode->i_mode) && lli->lli_clob)
1709                 /* discard all dirty pages before truncating them, required by
1710                  * osc_extent implementation at LU-1030.
1711                  */
1712                 cl_sync_file_range(inode, 0, OBD_OBJECT_EOF,
1713                                    CL_FSYNC_DISCARD, 1);
1714
1715         truncate_inode_pages_final(&inode->i_data);
1716
1717         /* Workaround for LU-118 */
1718         if (inode->i_data.nrpages) {
1719                 spin_lock_irq(&inode->i_data.tree_lock);
1720                 spin_unlock_irq(&inode->i_data.tree_lock);
1721                 LASSERTF(inode->i_data.nrpages == 0,
1722                          "inode=%lu/%u(%p) nrpages=%lu, see http://jira.whamcloud.com/browse/LU-118\n",
1723                          inode->i_ino, inode->i_generation, inode,
1724                          inode->i_data.nrpages);
1725         }
1726         /* Workaround end */
1727
1728         ll_clear_inode(inode);
1729         clear_inode(inode);
1730 }
1731
1732 int ll_iocontrol(struct inode *inode, struct file *file,
1733                  unsigned int cmd, unsigned long arg)
1734 {
1735         struct ll_sb_info *sbi = ll_i2sbi(inode);
1736         struct ptlrpc_request *req = NULL;
1737         int rc, flags = 0;
1738
1739         switch (cmd) {
1740         case FSFILT_IOC_GETFLAGS: {
1741                 struct mdt_body *body;
1742                 struct md_op_data *op_data;
1743
1744                 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL,
1745                                              0, 0, LUSTRE_OPC_ANY,
1746                                              NULL);
1747                 if (IS_ERR(op_data))
1748                         return PTR_ERR(op_data);
1749
1750                 op_data->op_valid = OBD_MD_FLFLAGS;
1751                 rc = md_getattr(sbi->ll_md_exp, op_data, &req);
1752                 ll_finish_md_op_data(op_data);
1753                 if (rc) {
1754                         CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1755                         return -abs(rc);
1756                 }
1757
1758                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1759
1760                 flags = body->flags;
1761
1762                 ptlrpc_req_finished(req);
1763
1764                 return put_user(flags, (int __user *)arg);
1765         }
1766         case FSFILT_IOC_SETFLAGS: {
1767                 struct lov_stripe_md *lsm;
1768                 struct obd_info oinfo = { };
1769                 struct md_op_data *op_data;
1770
1771                 if (get_user(flags, (int __user *)arg))
1772                         return -EFAULT;
1773
1774                 op_data = ll_prep_md_op_data(NULL, inode, NULL, NULL, 0, 0,
1775                                              LUSTRE_OPC_ANY, NULL);
1776                 if (IS_ERR(op_data))
1777                         return PTR_ERR(op_data);
1778
1779                 ((struct ll_iattr *)&op_data->op_attr)->ia_attr_flags = flags;
1780                 op_data->op_attr.ia_valid |= ATTR_ATTR_FLAG;
1781                 rc = md_setattr(sbi->ll_md_exp, op_data,
1782                                 NULL, 0, NULL, 0, &req, NULL);
1783                 ll_finish_md_op_data(op_data);
1784                 ptlrpc_req_finished(req);
1785                 if (rc)
1786                         return rc;
1787
1788                 inode->i_flags = ll_ext_to_inode_flags(flags);
1789
1790                 lsm = ccc_inode_lsm_get(inode);
1791                 if (!lsm_has_objects(lsm)) {
1792                         ccc_inode_lsm_put(inode, lsm);
1793                         return 0;
1794                 }
1795
1796                 oinfo.oi_oa = kmem_cache_alloc(obdo_cachep,
1797                                                GFP_NOFS | __GFP_ZERO);
1798                 if (!oinfo.oi_oa) {
1799                         ccc_inode_lsm_put(inode, lsm);
1800                         return -ENOMEM;
1801                 }
1802                 oinfo.oi_md = lsm;
1803                 oinfo.oi_oa->o_oi = lsm->lsm_oi;
1804                 oinfo.oi_oa->o_flags = flags;
1805                 oinfo.oi_oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS |
1806                                        OBD_MD_FLGROUP;
1807                 obdo_set_parent_fid(oinfo.oi_oa, &ll_i2info(inode)->lli_fid);
1808                 rc = obd_setattr_rqset(sbi->ll_dt_exp, &oinfo, NULL);
1809                 kmem_cache_free(obdo_cachep, oinfo.oi_oa);
1810                 ccc_inode_lsm_put(inode, lsm);
1811
1812                 if (rc && rc != -EPERM && rc != -EACCES)
1813                         CERROR("osc_setattr_async fails: rc = %d\n", rc);
1814
1815                 return rc;
1816         }
1817         default:
1818                 return -ENOSYS;
1819         }
1820
1821         return 0;
1822 }
1823
1824 int ll_flush_ctx(struct inode *inode)
1825 {
1826         struct ll_sb_info  *sbi = ll_i2sbi(inode);
1827
1828         CDEBUG(D_SEC, "flush context for user %d\n",
1829                from_kuid(&init_user_ns, current_uid()));
1830
1831         obd_set_info_async(NULL, sbi->ll_md_exp,
1832                            sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
1833                            0, NULL, NULL);
1834         obd_set_info_async(NULL, sbi->ll_dt_exp,
1835                            sizeof(KEY_FLUSH_CTX), KEY_FLUSH_CTX,
1836                            0, NULL, NULL);
1837         return 0;
1838 }
1839
1840 /* umount -f client means force down, don't save state */
1841 void ll_umount_begin(struct super_block *sb)
1842 {
1843         struct ll_sb_info *sbi = ll_s2sbi(sb);
1844         struct obd_device *obd;
1845         struct obd_ioctl_data *ioc_data;
1846
1847         CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
1848                sb->s_count, atomic_read(&sb->s_active));
1849
1850         obd = class_exp2obd(sbi->ll_md_exp);
1851         if (!obd) {
1852                 CERROR("Invalid MDC connection handle %#llx\n",
1853                        sbi->ll_md_exp->exp_handle.h_cookie);
1854                 return;
1855         }
1856         obd->obd_force = 1;
1857
1858         obd = class_exp2obd(sbi->ll_dt_exp);
1859         if (!obd) {
1860                 CERROR("Invalid LOV connection handle %#llx\n",
1861                        sbi->ll_dt_exp->exp_handle.h_cookie);
1862                 return;
1863         }
1864         obd->obd_force = 1;
1865
1866         ioc_data = kzalloc(sizeof(*ioc_data), GFP_NOFS);
1867         if (ioc_data) {
1868                 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_md_exp,
1869                               sizeof(*ioc_data), ioc_data, NULL);
1870
1871                 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_dt_exp,
1872                               sizeof(*ioc_data), ioc_data, NULL);
1873
1874                 kfree(ioc_data);
1875         }
1876
1877         /* Really, we'd like to wait until there are no requests outstanding,
1878          * and then continue.  For now, we just invalidate the requests,
1879          * schedule() and sleep one second if needed, and hope.
1880          */
1881         schedule();
1882 }
1883
1884 int ll_remount_fs(struct super_block *sb, int *flags, char *data)
1885 {
1886         struct ll_sb_info *sbi = ll_s2sbi(sb);
1887         char *profilenm = get_profile_name(sb);
1888         int err;
1889         __u32 read_only;
1890
1891         if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
1892                 read_only = *flags & MS_RDONLY;
1893                 err = obd_set_info_async(NULL, sbi->ll_md_exp,
1894                                          sizeof(KEY_READ_ONLY),
1895                                          KEY_READ_ONLY, sizeof(read_only),
1896                                          &read_only, NULL);
1897                 if (err) {
1898                         LCONSOLE_WARN("Failed to remount %s %s (%d)\n",
1899                                       profilenm, read_only ?
1900                                       "read-only" : "read-write", err);
1901                         return err;
1902                 }
1903
1904                 if (read_only)
1905                         sb->s_flags |= MS_RDONLY;
1906                 else
1907                         sb->s_flags &= ~MS_RDONLY;
1908
1909                 if (sbi->ll_flags & LL_SBI_VERBOSE)
1910                         LCONSOLE_WARN("Remounted %s %s\n", profilenm,
1911                                       read_only ?  "read-only" : "read-write");
1912         }
1913         return 0;
1914 }
1915
1916 /**
1917  * Cleanup the open handle that is cached on MDT-side.
1918  *
1919  * For open case, the client side open handling thread may hit error
1920  * after the MDT grant the open. Under such case, the client should
1921  * send close RPC to the MDT as cleanup; otherwise, the open handle
1922  * on the MDT will be leaked there until the client umount or evicted.
1923  *
1924  * In further, if someone unlinked the file, because the open handle
1925  * holds the reference on such file/object, then it will block the
1926  * subsequent threads that want to locate such object via FID.
1927  *
1928  * \param[in] sb        super block for this file-system
1929  * \param[in] open_req  pointer to the original open request
1930  */
1931 void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
1932 {
1933         struct mdt_body                 *body;
1934         struct md_op_data               *op_data;
1935         struct ptlrpc_request           *close_req = NULL;
1936         struct obd_export               *exp       = ll_s2sbi(sb)->ll_md_exp;
1937
1938         body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
1939         op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
1940         if (!op_data) {
1941                 CWARN("%s: cannot allocate op_data to release open handle for "
1942                       DFID "\n",
1943                       ll_get_fsname(sb, NULL, 0), PFID(&body->fid1));
1944
1945                 return;
1946         }
1947
1948         op_data->op_fid1 = body->fid1;
1949         op_data->op_ioepoch = body->ioepoch;
1950         op_data->op_handle = body->handle;
1951         op_data->op_mod_time = get_seconds();
1952         md_close(exp, op_data, NULL, &close_req);
1953         ptlrpc_req_finished(close_req);
1954         ll_finish_md_op_data(op_data);
1955 }
1956
1957 int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
1958                   struct super_block *sb, struct lookup_intent *it)
1959 {
1960         struct ll_sb_info *sbi = NULL;
1961         struct lustre_md md = { NULL };
1962         int rc;
1963
1964         LASSERT(*inode || sb);
1965         sbi = sb ? ll_s2sbi(sb) : ll_i2sbi(*inode);
1966         rc = md_get_lustre_md(sbi->ll_md_exp, req, sbi->ll_dt_exp,
1967                               sbi->ll_md_exp, &md);
1968         if (rc)
1969                 goto cleanup;
1970
1971         if (*inode) {
1972                 ll_update_inode(*inode, &md);
1973         } else {
1974                 LASSERT(sb);
1975
1976                 /*
1977                  * At this point server returns to client's same fid as client
1978                  * generated for creating. So using ->fid1 is okay here.
1979                  */
1980                 LASSERT(fid_is_sane(&md.body->fid1));
1981
1982                 *inode = ll_iget(sb, cl_fid_build_ino(&md.body->fid1,
1983                                              sbi->ll_flags & LL_SBI_32BIT_API),
1984                                  &md);
1985                 if (!inode) {
1986 #ifdef CONFIG_FS_POSIX_ACL
1987                         if (md.posix_acl) {
1988                                 posix_acl_release(md.posix_acl);
1989                                 md.posix_acl = NULL;
1990                         }
1991 #endif
1992                         rc = -ENOMEM;
1993                         CERROR("new_inode -fatal: rc %d\n", rc);
1994                         goto out;
1995                 }
1996         }
1997
1998         /* Handling piggyback layout lock.
1999          * Layout lock can be piggybacked by getattr and open request.
2000          * The lsm can be applied to inode only if it comes with a layout lock
2001          * otherwise correct layout may be overwritten, for example:
2002          * 1. proc1: mdt returns a lsm but not granting layout
2003          * 2. layout was changed by another client
2004          * 3. proc2: refresh layout and layout lock granted
2005          * 4. proc1: to apply a stale layout
2006          */
2007         if (it && it->d.lustre.it_lock_mode != 0) {
2008                 struct lustre_handle lockh;
2009                 struct ldlm_lock *lock;
2010
2011                 lockh.cookie = it->d.lustre.it_lock_handle;
2012                 lock = ldlm_handle2lock(&lockh);
2013                 LASSERT(lock);
2014                 if (ldlm_has_layout(lock)) {
2015                         struct cl_object_conf conf;
2016
2017                         memset(&conf, 0, sizeof(conf));
2018                         conf.coc_opc = OBJECT_CONF_SET;
2019                         conf.coc_inode = *inode;
2020                         conf.coc_lock = lock;
2021                         conf.u.coc_md = &md;
2022                         (void)ll_layout_conf(*inode, &conf);
2023                 }
2024                 LDLM_LOCK_PUT(lock);
2025         }
2026
2027 out:
2028         if (md.lsm)
2029                 obd_free_memmd(sbi->ll_dt_exp, &md.lsm);
2030         md_free_lustre_md(sbi->ll_md_exp, &md);
2031
2032 cleanup:
2033         if (rc != 0 && it && it->it_op & IT_OPEN)
2034                 ll_open_cleanup(sb ? sb : (*inode)->i_sb, req);
2035
2036         return rc;
2037 }
2038
2039 int ll_obd_statfs(struct inode *inode, void __user *arg)
2040 {
2041         struct ll_sb_info *sbi = NULL;
2042         struct obd_export *exp;
2043         char *buf = NULL;
2044         struct obd_ioctl_data *data = NULL;
2045         __u32 type;
2046         int len = 0, rc;
2047
2048         if (!inode) {
2049                 rc = -EINVAL;
2050                 goto out_statfs;
2051         }
2052
2053         sbi = ll_i2sbi(inode);
2054         if (!sbi) {
2055                 rc = -EINVAL;
2056                 goto out_statfs;
2057         }
2058
2059         rc = obd_ioctl_getdata(&buf, &len, arg);
2060         if (rc)
2061                 goto out_statfs;
2062
2063         data = (void *)buf;
2064         if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2 ||
2065             !data->ioc_pbuf1 || !data->ioc_pbuf2) {
2066                 rc = -EINVAL;
2067                 goto out_statfs;
2068         }
2069
2070         if (data->ioc_inllen1 != sizeof(__u32) ||
2071             data->ioc_inllen2 != sizeof(__u32) ||
2072             data->ioc_plen1 != sizeof(struct obd_statfs) ||
2073             data->ioc_plen2 != sizeof(struct obd_uuid)) {
2074                 rc = -EINVAL;
2075                 goto out_statfs;
2076         }
2077
2078         memcpy(&type, data->ioc_inlbuf1, sizeof(__u32));
2079         if (type & LL_STATFS_LMV)
2080                 exp = sbi->ll_md_exp;
2081         else if (type & LL_STATFS_LOV)
2082                 exp = sbi->ll_dt_exp;
2083         else {
2084                 rc = -ENODEV;
2085                 goto out_statfs;
2086         }
2087
2088         rc = obd_iocontrol(IOC_OBD_STATFS, exp, len, buf, NULL);
2089         if (rc)
2090                 goto out_statfs;
2091 out_statfs:
2092         if (buf)
2093                 obd_ioctl_freedata(buf, len);
2094         return rc;
2095 }
2096
2097 int ll_process_config(struct lustre_cfg *lcfg)
2098 {
2099         char *ptr;
2100         void *sb;
2101         struct lprocfs_static_vars lvars;
2102         unsigned long x;
2103         int rc = 0;
2104
2105         lprocfs_llite_init_vars(&lvars);
2106
2107         /* The instance name contains the sb: lustre-client-aacfe000 */
2108         ptr = strrchr(lustre_cfg_string(lcfg, 0), '-');
2109         if (!ptr || !*(++ptr))
2110                 return -EINVAL;
2111         rc = kstrtoul(ptr, 16, &x);
2112         if (rc != 0)
2113                 return -EINVAL;
2114         sb = (void *)x;
2115         /* This better be a real Lustre superblock! */
2116         LASSERT(s2lsi((struct super_block *)sb)->lsi_lmd->lmd_magic == LMD_MAGIC);
2117
2118         /* Note we have not called client_common_fill_super yet, so
2119          * proc fns must be able to handle that!
2120          */
2121         rc = class_process_proc_param(PARAM_LLITE, lvars.obd_vars,
2122                                       lcfg, sb);
2123         if (rc > 0)
2124                 rc = 0;
2125         return rc;
2126 }
2127
2128 /* this function prepares md_op_data hint for passing ot down to MD stack. */
2129 struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
2130                                       struct inode *i1, struct inode *i2,
2131                                       const char *name, int namelen,
2132                                       int mode, __u32 opc, void *data)
2133 {
2134         if (namelen > ll_i2sbi(i1)->ll_namelen)
2135                 return ERR_PTR(-ENAMETOOLONG);
2136
2137         if (!op_data)
2138                 op_data = kzalloc(sizeof(*op_data), GFP_NOFS);
2139
2140         if (!op_data)
2141                 return ERR_PTR(-ENOMEM);
2142
2143         ll_i2gids(op_data->op_suppgids, i1, i2);
2144         op_data->op_fid1 = *ll_inode2fid(i1);
2145
2146         if (i2)
2147                 op_data->op_fid2 = *ll_inode2fid(i2);
2148         else
2149                 fid_zero(&op_data->op_fid2);
2150
2151         op_data->op_name = name;
2152         op_data->op_namelen = namelen;
2153         op_data->op_mode = mode;
2154         op_data->op_mod_time = ktime_get_real_seconds();
2155         op_data->op_fsuid = from_kuid(&init_user_ns, current_fsuid());
2156         op_data->op_fsgid = from_kgid(&init_user_ns, current_fsgid());
2157         op_data->op_cap = cfs_curproc_cap_pack();
2158         op_data->op_bias = 0;
2159         op_data->op_cli_flags = 0;
2160         if ((opc == LUSTRE_OPC_CREATE) && name &&
2161             filename_is_volatile(name, namelen, NULL))
2162                 op_data->op_bias |= MDS_CREATE_VOLATILE;
2163         op_data->op_opc = opc;
2164         op_data->op_mds = 0;
2165         op_data->op_data = data;
2166
2167         /* If the file is being opened after mknod() (normally due to NFS)
2168          * try to use the default stripe data from parent directory for
2169          * allocating OST objects.  Try to pass the parent FID to MDS.
2170          */
2171         if (opc == LUSTRE_OPC_CREATE && i1 == i2 && S_ISREG(i2->i_mode) &&
2172             !ll_i2info(i2)->lli_has_smd) {
2173                 struct ll_inode_info *lli = ll_i2info(i2);
2174
2175                 spin_lock(&lli->lli_lock);
2176                 if (likely(!lli->lli_has_smd && !fid_is_zero(&lli->lli_pfid)))
2177                         op_data->op_fid1 = lli->lli_pfid;
2178                 spin_unlock(&lli->lli_lock);
2179         }
2180
2181         /* When called by ll_setattr_raw, file is i1. */
2182         if (ll_i2info(i1)->lli_flags & LLIF_DATA_MODIFIED)
2183                 op_data->op_bias |= MDS_DATA_MODIFIED;
2184
2185         return op_data;
2186 }
2187
2188 void ll_finish_md_op_data(struct md_op_data *op_data)
2189 {
2190         kfree(op_data);
2191 }
2192
2193 int ll_show_options(struct seq_file *seq, struct dentry *dentry)
2194 {
2195         struct ll_sb_info *sbi;
2196
2197         LASSERT(seq && dentry);
2198         sbi = ll_s2sbi(dentry->d_sb);
2199
2200         if (sbi->ll_flags & LL_SBI_NOLCK)
2201                 seq_puts(seq, ",nolock");
2202
2203         if (sbi->ll_flags & LL_SBI_FLOCK)
2204                 seq_puts(seq, ",flock");
2205
2206         if (sbi->ll_flags & LL_SBI_LOCALFLOCK)
2207                 seq_puts(seq, ",localflock");
2208
2209         if (sbi->ll_flags & LL_SBI_USER_XATTR)
2210                 seq_puts(seq, ",user_xattr");
2211
2212         if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
2213                 seq_puts(seq, ",lazystatfs");
2214
2215         if (sbi->ll_flags & LL_SBI_USER_FID2PATH)
2216                 seq_puts(seq, ",user_fid2path");
2217
2218         return 0;
2219 }
2220
2221 /**
2222  * Get obd name by cmd, and copy out to user space
2223  */
2224 int ll_get_obd_name(struct inode *inode, unsigned int cmd, unsigned long arg)
2225 {
2226         struct ll_sb_info *sbi = ll_i2sbi(inode);
2227         struct obd_device *obd;
2228
2229         if (cmd == OBD_IOC_GETDTNAME)
2230                 obd = class_exp2obd(sbi->ll_dt_exp);
2231         else if (cmd == OBD_IOC_GETMDNAME)
2232                 obd = class_exp2obd(sbi->ll_md_exp);
2233         else
2234                 return -EINVAL;
2235
2236         if (!obd)
2237                 return -ENOENT;
2238
2239         if (copy_to_user((void __user *)arg, obd->obd_name,
2240                          strlen(obd->obd_name) + 1))
2241                 return -EFAULT;
2242
2243         return 0;
2244 }
2245
2246 /**
2247  * Get lustre file system name by \a sbi. If \a buf is provided(non-NULL), the
2248  * fsname will be returned in this buffer; otherwise, a static buffer will be
2249  * used to store the fsname and returned to caller.
2250  */
2251 char *ll_get_fsname(struct super_block *sb, char *buf, int buflen)
2252 {
2253         static char fsname_static[MTI_NAME_MAXLEN];
2254         struct lustre_sb_info *lsi = s2lsi(sb);
2255         char *ptr;
2256         int len;
2257
2258         if (!buf) {
2259                 /* this means the caller wants to use static buffer
2260                  * and it doesn't care about race. Usually this is
2261                  * in error reporting path
2262                  */
2263                 buf = fsname_static;
2264                 buflen = sizeof(fsname_static);
2265         }
2266
2267         len = strlen(lsi->lsi_lmd->lmd_profile);
2268         ptr = strrchr(lsi->lsi_lmd->lmd_profile, '-');
2269         if (ptr && (strcmp(ptr, "-client") == 0))
2270                 len -= 7;
2271
2272         if (unlikely(len >= buflen))
2273                 len = buflen - 1;
2274         strncpy(buf, lsi->lsi_lmd->lmd_profile, len);
2275         buf[len] = '\0';
2276
2277         return buf;
2278 }
2279
2280 void ll_dirty_page_discard_warn(struct page *page, int ioret)
2281 {
2282         char *buf, *path = NULL;
2283         struct dentry *dentry = NULL;
2284         struct ccc_object *obj = cl_inode2ccc(page->mapping->host);
2285
2286         /* this can be called inside spin lock so use GFP_ATOMIC. */
2287         buf = (char *)__get_free_page(GFP_ATOMIC);
2288         if (buf) {
2289                 dentry = d_find_alias(page->mapping->host);
2290                 if (dentry)
2291                         path = dentry_path_raw(dentry, buf, PAGE_SIZE);
2292         }
2293
2294         CDEBUG(D_WARNING,
2295                "%s: dirty page discard: %s/fid: " DFID "/%s may get corrupted (rc %d)\n",
2296                ll_get_fsname(page->mapping->host->i_sb, NULL, 0),
2297                s2lsi(page->mapping->host->i_sb)->lsi_lmd->lmd_dev,
2298                PFID(&obj->cob_header.coh_lu.loh_fid),
2299                (path && !IS_ERR(path)) ? path : "", ioret);
2300
2301         if (dentry)
2302                 dput(dentry);
2303
2304         if (buf)
2305                 free_page((unsigned long)buf);
2306 }