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