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