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