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 | |
18 | * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf | |
19 | * | |
20 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, | |
21 | * CA 95054 USA or visit www.sun.com if you need additional information or | |
22 | * have any questions. | |
23 | * | |
24 | * GPL HEADER END | |
25 | */ | |
26 | /* | |
27 | * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved. | |
28 | * Use is subject to license terms. | |
29 | * | |
1dc563a6 | 30 | * Copyright (c) 2011, 2015, Intel Corporation. |
d7e09d03 PT |
31 | */ |
32 | /* | |
33 | * This file is part of Lustre, http://www.lustre.org/ | |
34 | * Lustre is a trademark of Sun Microsystems, Inc. | |
35 | */ | |
36 | ||
37 | #define DEBUG_SUBSYSTEM S_MDC | |
38 | ||
39 | # include <linux/module.h> | |
40 | # include <linux/pagemap.h> | |
41 | # include <linux/miscdevice.h> | |
42 | # include <linux/init.h> | |
43 | # include <linux/utsname.h> | |
44 | ||
05932307 GKH |
45 | #include "../include/lustre_acl.h" |
46 | #include "../include/obd_class.h" | |
47 | #include "../include/lustre_fid.h" | |
48 | #include "../include/lprocfs_status.h" | |
49 | #include "../include/lustre_param.h" | |
50 | #include "../include/lustre_log.h" | |
e2780478 | 51 | #include "../include/lustre_kernelcomm.h" |
d7e09d03 PT |
52 | |
53 | #include "mdc_internal.h" | |
54 | ||
55 | #define REQUEST_MINOR 244 | |
56 | ||
d7e09d03 PT |
57 | static int mdc_cleanup(struct obd_device *obd); |
58 | ||
d7e09d03 PT |
59 | static inline int mdc_queue_wait(struct ptlrpc_request *req) |
60 | { | |
61 | struct client_obd *cli = &req->rq_import->imp_obd->u.cli; | |
62 | int rc; | |
63 | ||
64 | /* mdc_enter_request() ensures that this client has no more | |
65 | * than cl_max_rpcs_in_flight RPCs simultaneously inf light | |
1df232ee OD |
66 | * against an MDT. |
67 | */ | |
d7e09d03 PT |
68 | rc = mdc_enter_request(cli); |
69 | if (rc != 0) | |
70 | return rc; | |
71 | ||
72 | rc = ptlrpc_queue_wait(req); | |
73 | mdc_exit_request(cli); | |
74 | ||
75 | return rc; | |
76 | } | |
77 | ||
ef2e0f55 | 78 | static int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid) |
d7e09d03 PT |
79 | { |
80 | struct ptlrpc_request *req; | |
81 | struct mdt_body *body; | |
82 | int rc; | |
d7e09d03 | 83 | |
ef2e0f55 OD |
84 | req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), |
85 | &RQF_MDS_GETSTATUS, | |
d7e09d03 | 86 | LUSTRE_MDS_VERSION, MDS_GETSTATUS); |
34e3ff96 | 87 | if (!req) |
0a3bdb00 | 88 | return -ENOMEM; |
d7e09d03 | 89 | |
ef2e0f55 OD |
90 | mdc_pack_body(req, NULL, 0, 0, -1, 0); |
91 | req->rq_send_state = LUSTRE_IMP_FULL; | |
d7e09d03 PT |
92 | |
93 | ptlrpc_request_set_replen(req); | |
94 | ||
95 | rc = ptlrpc_queue_wait(req); | |
96 | if (rc) | |
d5fdc207 | 97 | goto out; |
d7e09d03 PT |
98 | |
99 | body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); | |
34e3ff96 | 100 | if (!body) { |
d5fdc207 JL |
101 | rc = -EPROTO; |
102 | goto out; | |
103 | } | |
d7e09d03 | 104 | |
d7e09d03 PT |
105 | *rootfid = body->fid1; |
106 | CDEBUG(D_NET, | |
b0f5aad5 | 107 | "root fid="DFID", last_committed=%llu\n", |
d7e09d03 PT |
108 | PFID(rootfid), |
109 | lustre_msg_get_last_committed(req->rq_repmsg)); | |
d7e09d03 PT |
110 | out: |
111 | ptlrpc_req_finished(req); | |
112 | return rc; | |
113 | } | |
114 | ||
d7e09d03 PT |
115 | /* |
116 | * This function now is known to always saying that it will receive 4 buffers | |
117 | * from server. Even for cases when acl_size and md_size is zero, RPC header | |
118 | * will contain 4 fields and RPC itself will contain zero size fields. This is | |
119 | * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed | |
120 | * and thus zero, it shrinks it, making zero size. The same story about | |
121 | * md_size. And this is course of problem when client waits for smaller number | |
122 | * of fields. This issue will be fixed later when client gets aware of RPC | |
123 | * layouts. --umka | |
124 | */ | |
125 | static int mdc_getattr_common(struct obd_export *exp, | |
126 | struct ptlrpc_request *req) | |
127 | { | |
128 | struct req_capsule *pill = &req->rq_pill; | |
129 | struct mdt_body *body; | |
130 | void *eadata; | |
131 | int rc; | |
d7e09d03 PT |
132 | |
133 | /* Request message already built. */ | |
134 | rc = ptlrpc_queue_wait(req); | |
135 | if (rc != 0) | |
0a3bdb00 | 136 | return rc; |
d7e09d03 PT |
137 | |
138 | /* sanity check for the reply */ | |
139 | body = req_capsule_server_get(pill, &RMF_MDT_BODY); | |
34e3ff96 | 140 | if (!body) |
0a3bdb00 | 141 | return -EPROTO; |
d7e09d03 PT |
142 | |
143 | CDEBUG(D_NET, "mode: %o\n", body->mode); | |
144 | ||
145 | if (body->eadatasize != 0) { | |
146 | mdc_update_max_ea_from_body(exp, body); | |
147 | ||
148 | eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD, | |
149 | body->eadatasize); | |
34e3ff96 | 150 | if (!eadata) |
0a3bdb00 | 151 | return -EPROTO; |
d7e09d03 PT |
152 | } |
153 | ||
154 | if (body->valid & OBD_MD_FLRMTPERM) { | |
155 | struct mdt_remote_perm *perm; | |
156 | ||
157 | LASSERT(client_is_remote(exp)); | |
158 | perm = req_capsule_server_swab_get(pill, &RMF_ACL, | |
159 | lustre_swab_mdt_remote_perm); | |
34e3ff96 | 160 | if (!perm) |
0a3bdb00 | 161 | return -EPROTO; |
d7e09d03 PT |
162 | } |
163 | ||
0a3bdb00 | 164 | return 0; |
d7e09d03 PT |
165 | } |
166 | ||
60ebee3b | 167 | static int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data, |
22e0bc6a | 168 | struct ptlrpc_request **request) |
d7e09d03 PT |
169 | { |
170 | struct ptlrpc_request *req; | |
171 | int rc; | |
d7e09d03 PT |
172 | |
173 | /* Single MDS without an LMV case */ | |
174 | if (op_data->op_flags & MF_GET_MDT_IDX) { | |
175 | op_data->op_mds = 0; | |
0a3bdb00 | 176 | return 0; |
d7e09d03 PT |
177 | } |
178 | *request = NULL; | |
179 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR); | |
34e3ff96 | 180 | if (!req) |
0a3bdb00 | 181 | return -ENOMEM; |
d7e09d03 | 182 | |
d7e09d03 PT |
183 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR); |
184 | if (rc) { | |
185 | ptlrpc_request_free(req); | |
0a3bdb00 | 186 | return rc; |
d7e09d03 PT |
187 | } |
188 | ||
ef2e0f55 OD |
189 | mdc_pack_body(req, &op_data->op_fid1, op_data->op_valid, |
190 | op_data->op_mode, -1, 0); | |
d7e09d03 PT |
191 | |
192 | req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, | |
193 | op_data->op_mode); | |
194 | if (op_data->op_valid & OBD_MD_FLRMTPERM) { | |
195 | LASSERT(client_is_remote(exp)); | |
196 | req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER, | |
197 | sizeof(struct mdt_remote_perm)); | |
198 | } | |
199 | ptlrpc_request_set_replen(req); | |
200 | ||
201 | rc = mdc_getattr_common(exp, req); | |
202 | if (rc) | |
203 | ptlrpc_req_finished(req); | |
204 | else | |
205 | *request = req; | |
0a3bdb00 | 206 | return rc; |
d7e09d03 PT |
207 | } |
208 | ||
60ebee3b | 209 | static int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data, |
22e0bc6a | 210 | struct ptlrpc_request **request) |
d7e09d03 PT |
211 | { |
212 | struct ptlrpc_request *req; | |
213 | int rc; | |
d7e09d03 PT |
214 | |
215 | *request = NULL; | |
216 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), | |
217 | &RQF_MDS_GETATTR_NAME); | |
34e3ff96 | 218 | if (!req) |
0a3bdb00 | 219 | return -ENOMEM; |
d7e09d03 | 220 | |
d7e09d03 PT |
221 | req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, |
222 | op_data->op_namelen + 1); | |
223 | ||
224 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME); | |
225 | if (rc) { | |
226 | ptlrpc_request_free(req); | |
0a3bdb00 | 227 | return rc; |
d7e09d03 PT |
228 | } |
229 | ||
ef2e0f55 OD |
230 | mdc_pack_body(req, &op_data->op_fid1, op_data->op_valid, |
231 | op_data->op_mode, op_data->op_suppgids[0], 0); | |
d7e09d03 PT |
232 | |
233 | if (op_data->op_name) { | |
234 | char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME); | |
7436d070 | 235 | |
d7e09d03 PT |
236 | LASSERT(strnlen(op_data->op_name, op_data->op_namelen) == |
237 | op_data->op_namelen); | |
238 | memcpy(name, op_data->op_name, op_data->op_namelen); | |
239 | } | |
240 | ||
241 | req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, | |
242 | op_data->op_mode); | |
243 | ptlrpc_request_set_replen(req); | |
244 | ||
245 | rc = mdc_getattr_common(exp, req); | |
246 | if (rc) | |
247 | ptlrpc_req_finished(req); | |
248 | else | |
249 | *request = req; | |
0a3bdb00 | 250 | return rc; |
d7e09d03 PT |
251 | } |
252 | ||
253 | static int mdc_is_subdir(struct obd_export *exp, | |
254 | const struct lu_fid *pfid, | |
255 | const struct lu_fid *cfid, | |
256 | struct ptlrpc_request **request) | |
257 | { | |
258 | struct ptlrpc_request *req; | |
259 | int rc; | |
260 | ||
d7e09d03 PT |
261 | *request = NULL; |
262 | req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), | |
263 | &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION, | |
264 | MDS_IS_SUBDIR); | |
34e3ff96 | 265 | if (!req) |
0a3bdb00 | 266 | return -ENOMEM; |
d7e09d03 PT |
267 | |
268 | mdc_is_subdir_pack(req, pfid, cfid, 0); | |
269 | ptlrpc_request_set_replen(req); | |
270 | ||
271 | rc = ptlrpc_queue_wait(req); | |
272 | if (rc && rc != -EREMOTE) | |
273 | ptlrpc_req_finished(req); | |
274 | else | |
275 | *request = req; | |
0a3bdb00 | 276 | return rc; |
d7e09d03 PT |
277 | } |
278 | ||
301af906 SM |
279 | static int mdc_xattr_common(struct obd_export *exp, |
280 | const struct req_format *fmt, | |
d7e09d03 | 281 | const struct lu_fid *fid, |
ef2e0f55 | 282 | int opcode, u64 valid, |
d7e09d03 PT |
283 | const char *xattr_name, const char *input, |
284 | int input_size, int output_size, int flags, | |
285 | __u32 suppgid, struct ptlrpc_request **request) | |
286 | { | |
287 | struct ptlrpc_request *req; | |
288 | int xattr_namelen = 0; | |
289 | char *tmp; | |
290 | int rc; | |
d7e09d03 PT |
291 | |
292 | *request = NULL; | |
293 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt); | |
34e3ff96 | 294 | if (!req) |
0a3bdb00 | 295 | return -ENOMEM; |
d7e09d03 | 296 | |
d7e09d03 PT |
297 | if (xattr_name) { |
298 | xattr_namelen = strlen(xattr_name) + 1; | |
299 | req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT, | |
300 | xattr_namelen); | |
301 | } | |
302 | if (input_size) { | |
303 | LASSERT(input); | |
304 | req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT, | |
305 | input_size); | |
306 | } | |
307 | ||
e93a3082 AP |
308 | /* Flush local XATTR locks to get rid of a possible cancel RPC */ |
309 | if (opcode == MDS_REINT && fid_is_sane(fid) && | |
310 | exp->exp_connect_data.ocd_ibits_known & MDS_INODELOCK_XATTR) { | |
311 | LIST_HEAD(cancels); | |
312 | int count; | |
313 | ||
314 | /* Without that packing would fail */ | |
315 | if (input_size == 0) | |
316 | req_capsule_set_size(&req->rq_pill, &RMF_EADATA, | |
317 | RCL_CLIENT, 0); | |
318 | ||
319 | count = mdc_resource_get_unused(exp, fid, | |
320 | &cancels, LCK_EX, | |
321 | MDS_INODELOCK_XATTR); | |
322 | ||
323 | rc = mdc_prep_elc_req(exp, req, MDS_REINT, &cancels, count); | |
324 | if (rc) { | |
325 | ptlrpc_request_free(req); | |
326 | return rc; | |
327 | } | |
328 | } else { | |
329 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode); | |
330 | if (rc) { | |
331 | ptlrpc_request_free(req); | |
332 | return rc; | |
333 | } | |
d7e09d03 PT |
334 | } |
335 | ||
336 | if (opcode == MDS_REINT) { | |
337 | struct mdt_rec_setxattr *rec; | |
338 | ||
339 | CLASSERT(sizeof(struct mdt_rec_setxattr) == | |
340 | sizeof(struct mdt_rec_reint)); | |
341 | rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT); | |
342 | rec->sx_opcode = REINT_SETXATTR; | |
4b1a25f0 PT |
343 | rec->sx_fsuid = from_kuid(&init_user_ns, current_fsuid()); |
344 | rec->sx_fsgid = from_kgid(&init_user_ns, current_fsgid()); | |
d7e09d03 PT |
345 | rec->sx_cap = cfs_curproc_cap_pack(); |
346 | rec->sx_suppgid1 = suppgid; | |
347 | rec->sx_suppgid2 = -1; | |
348 | rec->sx_fid = *fid; | |
349 | rec->sx_valid = valid | OBD_MD_FLCTIME; | |
14e3f92a | 350 | rec->sx_time = ktime_get_real_seconds(); |
d7e09d03 PT |
351 | rec->sx_size = output_size; |
352 | rec->sx_flags = flags; | |
353 | ||
d7e09d03 | 354 | } else { |
ef2e0f55 | 355 | mdc_pack_body(req, fid, valid, output_size, suppgid, flags); |
d7e09d03 PT |
356 | } |
357 | ||
358 | if (xattr_name) { | |
359 | tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME); | |
360 | memcpy(tmp, xattr_name, xattr_namelen); | |
361 | } | |
362 | if (input_size) { | |
363 | tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA); | |
364 | memcpy(tmp, input, input_size); | |
365 | } | |
366 | ||
367 | if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER)) | |
368 | req_capsule_set_size(&req->rq_pill, &RMF_EADATA, | |
369 | RCL_SERVER, output_size); | |
370 | ptlrpc_request_set_replen(req); | |
371 | ||
372 | /* make rpc */ | |
373 | if (opcode == MDS_REINT) | |
374 | mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); | |
375 | ||
376 | rc = ptlrpc_queue_wait(req); | |
377 | ||
378 | if (opcode == MDS_REINT) | |
379 | mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); | |
380 | ||
381 | if (rc) | |
382 | ptlrpc_req_finished(req); | |
383 | else | |
384 | *request = req; | |
0a3bdb00 | 385 | return rc; |
d7e09d03 PT |
386 | } |
387 | ||
60ebee3b | 388 | static int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid, |
ef2e0f55 OD |
389 | u64 valid, const char *xattr_name, |
390 | const char *input, int input_size, int output_size, | |
391 | int flags, __u32 suppgid, | |
392 | struct ptlrpc_request **request) | |
d7e09d03 PT |
393 | { |
394 | return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR, | |
ef2e0f55 | 395 | fid, MDS_REINT, valid, xattr_name, |
d7e09d03 PT |
396 | input, input_size, output_size, flags, |
397 | suppgid, request); | |
398 | } | |
399 | ||
60ebee3b | 400 | static int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid, |
ef2e0f55 OD |
401 | u64 valid, const char *xattr_name, |
402 | const char *input, int input_size, int output_size, | |
403 | int flags, struct ptlrpc_request **request) | |
d7e09d03 PT |
404 | { |
405 | return mdc_xattr_common(exp, &RQF_MDS_GETXATTR, | |
ef2e0f55 | 406 | fid, MDS_GETXATTR, valid, xattr_name, |
d7e09d03 PT |
407 | input, input_size, output_size, flags, |
408 | -1, request); | |
409 | } | |
410 | ||
411 | #ifdef CONFIG_FS_POSIX_ACL | |
412 | static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md) | |
413 | { | |
414 | struct req_capsule *pill = &req->rq_pill; | |
415 | struct mdt_body *body = md->body; | |
416 | struct posix_acl *acl; | |
417 | void *buf; | |
418 | int rc; | |
d7e09d03 PT |
419 | |
420 | if (!body->aclsize) | |
0a3bdb00 | 421 | return 0; |
d7e09d03 PT |
422 | |
423 | buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize); | |
424 | ||
425 | if (!buf) | |
0a3bdb00 | 426 | return -EPROTO; |
d7e09d03 PT |
427 | |
428 | acl = posix_acl_from_xattr(&init_user_ns, buf, body->aclsize); | |
34e3ff96 | 429 | if (!acl) |
f4289400 CM |
430 | return 0; |
431 | ||
d7e09d03 PT |
432 | if (IS_ERR(acl)) { |
433 | rc = PTR_ERR(acl); | |
434 | CERROR("convert xattr to acl: %d\n", rc); | |
0a3bdb00 | 435 | return rc; |
d7e09d03 PT |
436 | } |
437 | ||
438 | rc = posix_acl_valid(acl); | |
439 | if (rc) { | |
440 | CERROR("validate acl: %d\n", rc); | |
441 | posix_acl_release(acl); | |
0a3bdb00 | 442 | return rc; |
d7e09d03 PT |
443 | } |
444 | ||
445 | md->posix_acl = acl; | |
0a3bdb00 | 446 | return 0; |
d7e09d03 PT |
447 | } |
448 | #else | |
449 | #define mdc_unpack_acl(req, md) 0 | |
450 | #endif | |
451 | ||
358855b2 SB |
452 | static int mdc_get_lustre_md(struct obd_export *exp, |
453 | struct ptlrpc_request *req, | |
454 | struct obd_export *dt_exp, | |
455 | struct obd_export *md_exp, | |
456 | struct lustre_md *md) | |
d7e09d03 PT |
457 | { |
458 | struct req_capsule *pill = &req->rq_pill; | |
459 | int rc; | |
d7e09d03 PT |
460 | |
461 | LASSERT(md); | |
462 | memset(md, 0, sizeof(*md)); | |
463 | ||
464 | md->body = req_capsule_server_get(pill, &RMF_MDT_BODY); | |
d7e09d03 PT |
465 | |
466 | if (md->body->valid & OBD_MD_FLEASIZE) { | |
467 | int lmmsize; | |
468 | struct lov_mds_md *lmm; | |
469 | ||
470 | if (!S_ISREG(md->body->mode)) { | |
ee990b33 SM |
471 | CDEBUG(D_INFO, |
472 | "OBD_MD_FLEASIZE set, should be a regular file, but is not\n"); | |
d5fdc207 JL |
473 | rc = -EPROTO; |
474 | goto out; | |
d7e09d03 PT |
475 | } |
476 | ||
477 | if (md->body->eadatasize == 0) { | |
ee990b33 SM |
478 | CDEBUG(D_INFO, |
479 | "OBD_MD_FLEASIZE set, but eadatasize 0\n"); | |
d5fdc207 JL |
480 | rc = -EPROTO; |
481 | goto out; | |
d7e09d03 PT |
482 | } |
483 | lmmsize = md->body->eadatasize; | |
484 | lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize); | |
d5fdc207 JL |
485 | if (!lmm) { |
486 | rc = -EPROTO; | |
487 | goto out; | |
488 | } | |
d7e09d03 PT |
489 | |
490 | rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize); | |
491 | if (rc < 0) | |
d5fdc207 | 492 | goto out; |
d7e09d03 PT |
493 | |
494 | if (rc < sizeof(*md->lsm)) { | |
ee990b33 SM |
495 | CDEBUG(D_INFO, |
496 | "lsm size too small: rc < sizeof (*md->lsm) (%d < %d)\n", | |
d7e09d03 | 497 | rc, (int)sizeof(*md->lsm)); |
d5fdc207 JL |
498 | rc = -EPROTO; |
499 | goto out; | |
d7e09d03 PT |
500 | } |
501 | ||
502 | } else if (md->body->valid & OBD_MD_FLDIREA) { | |
503 | int lmvsize; | |
504 | struct lov_mds_md *lmv; | |
505 | ||
301af906 | 506 | if (!S_ISDIR(md->body->mode)) { |
ee990b33 SM |
507 | CDEBUG(D_INFO, |
508 | "OBD_MD_FLDIREA set, should be a directory, but is not\n"); | |
d5fdc207 JL |
509 | rc = -EPROTO; |
510 | goto out; | |
d7e09d03 PT |
511 | } |
512 | ||
513 | if (md->body->eadatasize == 0) { | |
ee990b33 SM |
514 | CDEBUG(D_INFO, |
515 | "OBD_MD_FLDIREA is set, but eadatasize 0\n"); | |
0a3bdb00 | 516 | return -EPROTO; |
d7e09d03 PT |
517 | } |
518 | if (md->body->valid & OBD_MD_MEA) { | |
519 | lmvsize = md->body->eadatasize; | |
520 | lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD, | |
521 | lmvsize); | |
d5fdc207 JL |
522 | if (!lmv) { |
523 | rc = -EPROTO; | |
524 | goto out; | |
525 | } | |
d7e09d03 PT |
526 | |
527 | rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv, | |
528 | lmvsize); | |
529 | if (rc < 0) | |
d5fdc207 | 530 | goto out; |
d7e09d03 PT |
531 | |
532 | if (rc < sizeof(*md->mea)) { | |
ee990b33 SM |
533 | CDEBUG(D_INFO, |
534 | "size too small: rc < sizeof(*md->mea) (%d < %d)\n", | |
d7e09d03 | 535 | rc, (int)sizeof(*md->mea)); |
d5fdc207 JL |
536 | rc = -EPROTO; |
537 | goto out; | |
d7e09d03 PT |
538 | } |
539 | } | |
540 | } | |
541 | rc = 0; | |
542 | ||
543 | if (md->body->valid & OBD_MD_FLRMTPERM) { | |
544 | /* remote permission */ | |
545 | LASSERT(client_is_remote(exp)); | |
546 | md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL, | |
547 | lustre_swab_mdt_remote_perm); | |
d5fdc207 JL |
548 | if (!md->remote_perm) { |
549 | rc = -EPROTO; | |
550 | goto out; | |
551 | } | |
78dd0798 | 552 | } else if (md->body->valid & OBD_MD_FLACL) { |
d7e09d03 PT |
553 | /* for ACL, it's possible that FLACL is set but aclsize is zero. |
554 | * only when aclsize != 0 there's an actual segment for ACL | |
555 | * in reply buffer. | |
556 | */ | |
557 | if (md->body->aclsize) { | |
558 | rc = mdc_unpack_acl(req, md); | |
559 | if (rc) | |
d5fdc207 | 560 | goto out; |
d7e09d03 PT |
561 | #ifdef CONFIG_FS_POSIX_ACL |
562 | } else { | |
563 | md->posix_acl = NULL; | |
564 | #endif | |
565 | } | |
566 | } | |
d7e09d03 | 567 | |
d7e09d03 PT |
568 | out: |
569 | if (rc) { | |
d7e09d03 PT |
570 | #ifdef CONFIG_FS_POSIX_ACL |
571 | posix_acl_release(md->posix_acl); | |
572 | #endif | |
573 | if (md->lsm) | |
574 | obd_free_memmd(dt_exp, &md->lsm); | |
575 | } | |
576 | return rc; | |
577 | } | |
578 | ||
358855b2 | 579 | static int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md) |
d7e09d03 | 580 | { |
0a3bdb00 | 581 | return 0; |
d7e09d03 PT |
582 | } |
583 | ||
584 | /** | |
585 | * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING | |
586 | * RPC chains. | |
587 | */ | |
588 | void mdc_replay_open(struct ptlrpc_request *req) | |
589 | { | |
590 | struct md_open_data *mod = req->rq_cb_data; | |
591 | struct ptlrpc_request *close_req; | |
592 | struct obd_client_handle *och; | |
593 | struct lustre_handle old; | |
594 | struct mdt_body *body; | |
d7e09d03 | 595 | |
34e3ff96 | 596 | if (!mod) { |
d7e09d03 PT |
597 | DEBUG_REQ(D_ERROR, req, |
598 | "Can't properly replay without open data."); | |
d7e09d03 PT |
599 | return; |
600 | } | |
601 | ||
602 | body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); | |
d7e09d03 PT |
603 | |
604 | och = mod->mod_och; | |
34e3ff96 | 605 | if (och) { |
d7e09d03 PT |
606 | struct lustre_handle *file_fh; |
607 | ||
608 | LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC); | |
609 | ||
610 | file_fh = &och->och_fh; | |
55f5a824 | 611 | CDEBUG(D_HA, "updating handle from %#llx to %#llx\n", |
d7e09d03 PT |
612 | file_fh->cookie, body->handle.cookie); |
613 | old = *file_fh; | |
614 | *file_fh = body->handle; | |
615 | } | |
616 | close_req = mod->mod_close_req; | |
34e3ff96 | 617 | if (close_req) { |
d7e09d03 PT |
618 | __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg); |
619 | struct mdt_ioepoch *epoch; | |
620 | ||
621 | LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING); | |
622 | epoch = req_capsule_client_get(&close_req->rq_pill, | |
623 | &RMF_MDT_EPOCH); | |
624 | LASSERT(epoch); | |
625 | ||
34e3ff96 | 626 | if (och) |
d7e09d03 PT |
627 | LASSERT(!memcmp(&old, &epoch->handle, sizeof(old))); |
628 | DEBUG_REQ(D_HA, close_req, "updating close body with new fh"); | |
629 | epoch->handle = body->handle; | |
630 | } | |
d7e09d03 PT |
631 | } |
632 | ||
633 | void mdc_commit_open(struct ptlrpc_request *req) | |
634 | { | |
635 | struct md_open_data *mod = req->rq_cb_data; | |
7436d070 | 636 | |
34e3ff96 | 637 | if (!mod) |
d7e09d03 PT |
638 | return; |
639 | ||
640 | /** | |
641 | * No need to touch md_open_data::mod_och, it holds a reference on | |
642 | * \var mod and will zero references to each other, \var mod will be | |
643 | * freed after that when md_open_data::mod_och will put the reference. | |
644 | */ | |
645 | ||
646 | /** | |
647 | * Do not let open request to disappear as it still may be needed | |
648 | * for close rpc to happen (it may happen on evict only, otherwise | |
649 | * ptlrpc_request::rq_replay does not let mdc_commit_open() to be | |
650 | * called), just mark this rpc as committed to distinguish these 2 | |
651 | * cases, see mdc_close() for details. The open request reference will | |
652 | * be put along with freeing \var mod. | |
653 | */ | |
654 | ptlrpc_request_addref(req); | |
655 | spin_lock(&req->rq_lock); | |
656 | req->rq_committed = 1; | |
657 | spin_unlock(&req->rq_lock); | |
658 | req->rq_cb_data = NULL; | |
659 | obd_mod_put(mod); | |
660 | } | |
661 | ||
662 | int mdc_set_open_replay_data(struct obd_export *exp, | |
663 | struct obd_client_handle *och, | |
63d42578 | 664 | struct lookup_intent *it) |
d7e09d03 PT |
665 | { |
666 | struct md_open_data *mod; | |
667 | struct mdt_rec_create *rec; | |
668 | struct mdt_body *body; | |
63d42578 | 669 | struct ptlrpc_request *open_req = it->d.lustre.it_data; |
d7e09d03 | 670 | struct obd_import *imp = open_req->rq_import; |
d7e09d03 PT |
671 | |
672 | if (!open_req->rq_replay) | |
0a3bdb00 | 673 | return 0; |
d7e09d03 PT |
674 | |
675 | rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT); | |
676 | body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY); | |
34e3ff96 | 677 | LASSERT(rec); |
d7e09d03 PT |
678 | /* Incoming message in my byte order (it's been swabbed). */ |
679 | /* Outgoing messages always in my byte order. */ | |
34e3ff96 | 680 | LASSERT(body); |
d7e09d03 PT |
681 | |
682 | /* Only if the import is replayable, we set replay_open data */ | |
683 | if (och && imp->imp_replayable) { | |
684 | mod = obd_mod_alloc(); | |
34e3ff96 | 685 | if (!mod) { |
d7e09d03 PT |
686 | DEBUG_REQ(D_ERROR, open_req, |
687 | "Can't allocate md_open_data"); | |
0a3bdb00 | 688 | return 0; |
d7e09d03 PT |
689 | } |
690 | ||
691 | /** | |
692 | * Take a reference on \var mod, to be freed on mdc_close(). | |
693 | * It protects \var mod from being freed on eviction (commit | |
694 | * callback is called despite rq_replay flag). | |
695 | * Another reference for \var och. | |
696 | */ | |
697 | obd_mod_get(mod); | |
698 | obd_mod_get(mod); | |
699 | ||
700 | spin_lock(&open_req->rq_lock); | |
701 | och->och_mod = mod; | |
702 | mod->mod_och = och; | |
63d42578 HZ |
703 | mod->mod_is_create = it_disposition(it, DISP_OPEN_CREATE) || |
704 | it_disposition(it, DISP_OPEN_STRIPE); | |
d7e09d03 PT |
705 | mod->mod_open_req = open_req; |
706 | open_req->rq_cb_data = mod; | |
707 | open_req->rq_commit_cb = mdc_commit_open; | |
708 | spin_unlock(&open_req->rq_lock); | |
709 | } | |
710 | ||
711 | rec->cr_fid2 = body->fid1; | |
712 | rec->cr_ioepoch = body->ioepoch; | |
713 | rec->cr_old_handle.cookie = body->handle.cookie; | |
714 | open_req->rq_replay_cb = mdc_replay_open; | |
715 | if (!fid_is_sane(&body->fid1)) { | |
ee990b33 SM |
716 | DEBUG_REQ(D_ERROR, open_req, |
717 | "Saving replay request with insane fid"); | |
d7e09d03 PT |
718 | LBUG(); |
719 | } | |
720 | ||
721 | DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data"); | |
0a3bdb00 | 722 | return 0; |
d7e09d03 PT |
723 | } |
724 | ||
63d42578 HZ |
725 | static void mdc_free_open(struct md_open_data *mod) |
726 | { | |
727 | int committed = 0; | |
728 | ||
729 | if (mod->mod_is_create == 0 && | |
730 | imp_connect_disp_stripe(mod->mod_open_req->rq_import)) | |
731 | committed = 1; | |
732 | ||
733 | LASSERT(mod->mod_open_req->rq_replay == 0); | |
734 | ||
735 | DEBUG_REQ(D_RPCTRACE, mod->mod_open_req, "free open request\n"); | |
736 | ||
737 | ptlrpc_request_committed(mod->mod_open_req, committed); | |
738 | if (mod->mod_close_req) | |
739 | ptlrpc_request_committed(mod->mod_close_req, committed); | |
740 | } | |
741 | ||
358855b2 SB |
742 | static int mdc_clear_open_replay_data(struct obd_export *exp, |
743 | struct obd_client_handle *och) | |
d7e09d03 PT |
744 | { |
745 | struct md_open_data *mod = och->och_mod; | |
d7e09d03 PT |
746 | |
747 | /** | |
748 | * It is possible to not have \var mod in a case of eviction between | |
749 | * lookup and ll_file_open(). | |
750 | **/ | |
34e3ff96 | 751 | if (!mod) |
0a3bdb00 | 752 | return 0; |
d7e09d03 PT |
753 | |
754 | LASSERT(mod != LP_POISON); | |
34e3ff96 | 755 | LASSERT(mod->mod_open_req); |
63d42578 | 756 | mdc_free_open(mod); |
d7e09d03 PT |
757 | |
758 | mod->mod_och = NULL; | |
759 | och->och_mod = NULL; | |
760 | obd_mod_put(mod); | |
761 | ||
0a3bdb00 | 762 | return 0; |
d7e09d03 PT |
763 | } |
764 | ||
765 | /* Prepares the request for the replay by the given reply */ | |
766 | static void mdc_close_handle_reply(struct ptlrpc_request *req, | |
767 | struct md_op_data *op_data, int rc) { | |
768 | struct mdt_body *repbody; | |
769 | struct mdt_ioepoch *epoch; | |
770 | ||
771 | if (req && rc == -EAGAIN) { | |
772 | repbody = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); | |
773 | epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH); | |
774 | ||
775 | epoch->flags |= MF_SOM_AU; | |
776 | if (repbody->valid & OBD_MD_FLGETATTRLOCK) | |
777 | op_data->op_flags |= MF_GETATTR_LOCK; | |
778 | } | |
779 | } | |
780 | ||
f6219c16 LC |
781 | static int mdc_close(struct obd_export *exp, struct md_op_data *op_data, |
782 | struct md_open_data *mod, struct ptlrpc_request **request) | |
d7e09d03 PT |
783 | { |
784 | struct obd_device *obd = class_exp2obd(exp); | |
785 | struct ptlrpc_request *req; | |
48d23e61 JX |
786 | struct req_format *req_fmt; |
787 | int rc; | |
788 | int saved_rc = 0; | |
789 | ||
48d23e61 JX |
790 | req_fmt = &RQF_MDS_CLOSE; |
791 | if (op_data->op_bias & MDS_HSM_RELEASE) { | |
792 | req_fmt = &RQF_MDS_RELEASE_CLOSE; | |
793 | ||
794 | /* allocate a FID for volatile file */ | |
795 | rc = mdc_fid_alloc(exp, &op_data->op_fid2, op_data); | |
796 | if (rc < 0) { | |
797 | CERROR("%s: "DFID" failed to allocate FID: %d\n", | |
798 | obd->obd_name, PFID(&op_data->op_fid1), rc); | |
799 | /* save the errcode and proceed to close */ | |
800 | saved_rc = rc; | |
801 | } | |
802 | } | |
d7e09d03 PT |
803 | |
804 | *request = NULL; | |
48d23e61 | 805 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), req_fmt); |
34e3ff96 | 806 | if (!req) |
0a3bdb00 | 807 | return -ENOMEM; |
d7e09d03 | 808 | |
d7e09d03 PT |
809 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE); |
810 | if (rc) { | |
811 | ptlrpc_request_free(req); | |
0a3bdb00 | 812 | return rc; |
d7e09d03 PT |
813 | } |
814 | ||
815 | /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a | |
816 | * portal whose threads are not taking any DLM locks and are therefore | |
1df232ee OD |
817 | * always progressing |
818 | */ | |
d7e09d03 PT |
819 | req->rq_request_portal = MDS_READPAGE_PORTAL; |
820 | ptlrpc_at_set_req_timeout(req); | |
821 | ||
822 | /* Ensure that this close's handle is fixed up during replay. */ | |
34e3ff96 OD |
823 | if (likely(mod)) { |
824 | LASSERTF(mod->mod_open_req && | |
d7e09d03 PT |
825 | mod->mod_open_req->rq_type != LI_POISON, |
826 | "POISONED open %p!\n", mod->mod_open_req); | |
827 | ||
828 | mod->mod_close_req = req; | |
829 | ||
830 | DEBUG_REQ(D_HA, mod->mod_open_req, "matched open"); | |
831 | /* We no longer want to preserve this open for replay even | |
1df232ee OD |
832 | * though the open was committed. b=3632, b=3633 |
833 | */ | |
d7e09d03 PT |
834 | spin_lock(&mod->mod_open_req->rq_lock); |
835 | mod->mod_open_req->rq_replay = 0; | |
836 | spin_unlock(&mod->mod_open_req->rq_lock); | |
837 | } else { | |
e5e663ae SM |
838 | CDEBUG(D_HA, |
839 | "couldn't find open req; expecting close error\n"); | |
d7e09d03 PT |
840 | } |
841 | ||
842 | mdc_close_pack(req, op_data); | |
843 | ||
844 | req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER, | |
44779340 | 845 | obd->u.cli.cl_default_mds_easize); |
d7e09d03 | 846 | req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER, |
44779340 | 847 | obd->u.cli.cl_default_mds_cookiesize); |
d7e09d03 PT |
848 | |
849 | ptlrpc_request_set_replen(req); | |
850 | ||
851 | mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL); | |
852 | rc = ptlrpc_queue_wait(req); | |
853 | mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL); | |
854 | ||
34e3ff96 | 855 | if (!req->rq_repmsg) { |
d7e09d03 PT |
856 | CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req, |
857 | req->rq_status); | |
858 | if (rc == 0) | |
859 | rc = req->rq_status ?: -EIO; | |
860 | } else if (rc == 0 || rc == -EAGAIN) { | |
861 | struct mdt_body *body; | |
862 | ||
863 | rc = lustre_msg_get_status(req->rq_repmsg); | |
864 | if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) { | |
ee990b33 SM |
865 | DEBUG_REQ(D_ERROR, req, |
866 | "type == PTL_RPC_MSG_ERR, err = %d", rc); | |
d7e09d03 PT |
867 | if (rc > 0) |
868 | rc = -rc; | |
869 | } | |
870 | body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY); | |
34e3ff96 | 871 | if (!body) |
d7e09d03 PT |
872 | rc = -EPROTO; |
873 | } else if (rc == -ESTALE) { | |
874 | /** | |
875 | * it can be allowed error after 3633 if open was committed and | |
876 | * server failed before close was sent. Let's check if mod | |
877 | * exists and return no error in that case | |
878 | */ | |
879 | if (mod) { | |
880 | DEBUG_REQ(D_HA, req, "Reset ESTALE = %d", rc); | |
d7e09d03 PT |
881 | if (mod->mod_open_req->rq_committed) |
882 | rc = 0; | |
883 | } | |
884 | } | |
885 | ||
886 | if (mod) { | |
887 | if (rc != 0) | |
888 | mod->mod_close_req = NULL; | |
889 | /* Since now, mod is accessed through open_req only, | |
1df232ee OD |
890 | * thus close req does not keep a reference on mod anymore. |
891 | */ | |
d7e09d03 PT |
892 | obd_mod_put(mod); |
893 | } | |
894 | *request = req; | |
895 | mdc_close_handle_reply(req, op_data, rc); | |
48d23e61 | 896 | return rc < 0 ? rc : saved_rc; |
d7e09d03 PT |
897 | } |
898 | ||
f6219c16 LC |
899 | static int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data, |
900 | struct md_open_data *mod) | |
d7e09d03 PT |
901 | { |
902 | struct obd_device *obd = class_exp2obd(exp); | |
903 | struct ptlrpc_request *req; | |
904 | int rc; | |
d7e09d03 PT |
905 | |
906 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), | |
907 | &RQF_MDS_DONE_WRITING); | |
34e3ff96 | 908 | if (!req) |
0a3bdb00 | 909 | return -ENOMEM; |
d7e09d03 | 910 | |
d7e09d03 PT |
911 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING); |
912 | if (rc) { | |
913 | ptlrpc_request_free(req); | |
0a3bdb00 | 914 | return rc; |
d7e09d03 PT |
915 | } |
916 | ||
34e3ff96 OD |
917 | if (mod) { |
918 | LASSERTF(mod->mod_open_req && | |
d7e09d03 PT |
919 | mod->mod_open_req->rq_type != LI_POISON, |
920 | "POISONED setattr %p!\n", mod->mod_open_req); | |
921 | ||
922 | mod->mod_close_req = req; | |
923 | DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr"); | |
924 | /* We no longer want to preserve this setattr for replay even | |
1df232ee OD |
925 | * though the open was committed. b=3632, b=3633 |
926 | */ | |
d7e09d03 PT |
927 | spin_lock(&mod->mod_open_req->rq_lock); |
928 | mod->mod_open_req->rq_replay = 0; | |
929 | spin_unlock(&mod->mod_open_req->rq_lock); | |
930 | } | |
931 | ||
932 | mdc_close_pack(req, op_data); | |
933 | ptlrpc_request_set_replen(req); | |
934 | ||
935 | mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL); | |
936 | rc = ptlrpc_queue_wait(req); | |
937 | mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL); | |
938 | ||
939 | if (rc == -ESTALE) { | |
940 | /** | |
941 | * it can be allowed error after 3633 if open or setattr were | |
942 | * committed and server failed before close was sent. | |
943 | * Let's check if mod exists and return no error in that case | |
944 | */ | |
945 | if (mod) { | |
d7e09d03 PT |
946 | if (mod->mod_open_req->rq_committed) |
947 | rc = 0; | |
948 | } | |
949 | } | |
950 | ||
951 | if (mod) { | |
952 | if (rc != 0) | |
953 | mod->mod_close_req = NULL; | |
34e3ff96 | 954 | LASSERT(mod->mod_open_req); |
63d42578 HZ |
955 | mdc_free_open(mod); |
956 | ||
d7e09d03 | 957 | /* Since now, mod is accessed through setattr req only, |
1df232ee OD |
958 | * thus DW req does not keep a reference on mod anymore. |
959 | */ | |
d7e09d03 PT |
960 | obd_mod_put(mod); |
961 | } | |
962 | ||
963 | mdc_close_handle_reply(req, op_data, rc); | |
964 | ptlrpc_req_finished(req); | |
0a3bdb00 | 965 | return rc; |
d7e09d03 PT |
966 | } |
967 | ||
f6219c16 LC |
968 | static int mdc_readpage(struct obd_export *exp, struct md_op_data *op_data, |
969 | struct page **pages, struct ptlrpc_request **request) | |
d7e09d03 PT |
970 | { |
971 | struct ptlrpc_request *req; | |
972 | struct ptlrpc_bulk_desc *desc; | |
973 | int i; | |
974 | wait_queue_head_t waitq; | |
975 | int resends = 0; | |
976 | struct l_wait_info lwi; | |
977 | int rc; | |
d7e09d03 PT |
978 | |
979 | *request = NULL; | |
980 | init_waitqueue_head(&waitq); | |
981 | ||
982 | restart_bulk: | |
983 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE); | |
34e3ff96 | 984 | if (!req) |
0a3bdb00 | 985 | return -ENOMEM; |
d7e09d03 | 986 | |
d7e09d03 PT |
987 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE); |
988 | if (rc) { | |
989 | ptlrpc_request_free(req); | |
0a3bdb00 | 990 | return rc; |
d7e09d03 PT |
991 | } |
992 | ||
993 | req->rq_request_portal = MDS_READPAGE_PORTAL; | |
994 | ptlrpc_at_set_req_timeout(req); | |
995 | ||
996 | desc = ptlrpc_prep_bulk_imp(req, op_data->op_npages, 1, BULK_PUT_SINK, | |
997 | MDS_BULK_PORTAL); | |
34e3ff96 | 998 | if (!desc) { |
d7e09d03 | 999 | ptlrpc_request_free(req); |
0a3bdb00 | 1000 | return -ENOMEM; |
d7e09d03 PT |
1001 | } |
1002 | ||
1003 | /* NB req now owns desc and will free it when it gets freed */ | |
1004 | for (i = 0; i < op_data->op_npages; i++) | |
1005 | ptlrpc_prep_bulk_page_pin(desc, pages[i], 0, PAGE_CACHE_SIZE); | |
1006 | ||
1007 | mdc_readdir_pack(req, op_data->op_offset, | |
1008 | PAGE_CACHE_SIZE * op_data->op_npages, | |
ef2e0f55 | 1009 | &op_data->op_fid1); |
d7e09d03 PT |
1010 | |
1011 | ptlrpc_request_set_replen(req); | |
1012 | rc = ptlrpc_queue_wait(req); | |
1013 | if (rc) { | |
1014 | ptlrpc_req_finished(req); | |
1015 | if (rc != -ETIMEDOUT) | |
0a3bdb00 | 1016 | return rc; |
d7e09d03 PT |
1017 | |
1018 | resends++; | |
1019 | if (!client_should_resend(resends, &exp->exp_obd->u.cli)) { | |
1020 | CERROR("too many resend retries, returning error\n"); | |
0a3bdb00 | 1021 | return -EIO; |
d7e09d03 | 1022 | } |
e5e663ae SM |
1023 | lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), |
1024 | NULL, NULL, NULL); | |
d7e09d03 PT |
1025 | l_wait_event(waitq, 0, &lwi); |
1026 | ||
1027 | goto restart_bulk; | |
1028 | } | |
1029 | ||
1030 | rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk, | |
1031 | req->rq_bulk->bd_nob_transferred); | |
1032 | if (rc < 0) { | |
1033 | ptlrpc_req_finished(req); | |
0a3bdb00 | 1034 | return rc; |
d7e09d03 PT |
1035 | } |
1036 | ||
1037 | if (req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK) { | |
1038 | CERROR("Unexpected # bytes transferred: %d (%ld expected)\n", | |
22e0bc6a OD |
1039 | req->rq_bulk->bd_nob_transferred, |
1040 | PAGE_CACHE_SIZE * op_data->op_npages); | |
d7e09d03 | 1041 | ptlrpc_req_finished(req); |
0a3bdb00 | 1042 | return -EPROTO; |
d7e09d03 PT |
1043 | } |
1044 | ||
1045 | *request = req; | |
0a3bdb00 | 1046 | return 0; |
d7e09d03 PT |
1047 | } |
1048 | ||
1049 | static int mdc_statfs(const struct lu_env *env, | |
1050 | struct obd_export *exp, struct obd_statfs *osfs, | |
1051 | __u64 max_age, __u32 flags) | |
1052 | { | |
1053 | struct obd_device *obd = class_exp2obd(exp); | |
1054 | struct ptlrpc_request *req; | |
1055 | struct obd_statfs *msfs; | |
1056 | struct obd_import *imp = NULL; | |
1057 | int rc; | |
d7e09d03 PT |
1058 | |
1059 | /* | |
1060 | * Since the request might also come from lprocfs, so we need | |
1061 | * sync this with client_disconnect_export Bug15684 | |
1062 | */ | |
1063 | down_read(&obd->u.cli.cl_sem); | |
1064 | if (obd->u.cli.cl_import) | |
1065 | imp = class_import_get(obd->u.cli.cl_import); | |
1066 | up_read(&obd->u.cli.cl_sem); | |
1067 | if (!imp) | |
0a3bdb00 | 1068 | return -ENODEV; |
d7e09d03 PT |
1069 | |
1070 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_STATFS, | |
1071 | LUSTRE_MDS_VERSION, MDS_STATFS); | |
34e3ff96 | 1072 | if (!req) { |
d5fdc207 JL |
1073 | rc = -ENOMEM; |
1074 | goto output; | |
1075 | } | |
d7e09d03 PT |
1076 | |
1077 | ptlrpc_request_set_replen(req); | |
1078 | ||
1079 | if (flags & OBD_STATFS_NODELAY) { | |
1080 | /* procfs requests not want stay in wait for avoid deadlock */ | |
1081 | req->rq_no_resend = 1; | |
1082 | req->rq_no_delay = 1; | |
1083 | } | |
1084 | ||
1085 | rc = ptlrpc_queue_wait(req); | |
1086 | if (rc) { | |
1087 | /* check connection error first */ | |
1088 | if (imp->imp_connect_error) | |
1089 | rc = imp->imp_connect_error; | |
d5fdc207 | 1090 | goto out; |
d7e09d03 PT |
1091 | } |
1092 | ||
1093 | msfs = req_capsule_server_get(&req->rq_pill, &RMF_OBD_STATFS); | |
34e3ff96 | 1094 | if (!msfs) { |
d5fdc207 JL |
1095 | rc = -EPROTO; |
1096 | goto out; | |
1097 | } | |
d7e09d03 PT |
1098 | |
1099 | *osfs = *msfs; | |
d7e09d03 PT |
1100 | out: |
1101 | ptlrpc_req_finished(req); | |
1102 | output: | |
1103 | class_import_put(imp); | |
1104 | return rc; | |
1105 | } | |
1106 | ||
1107 | static int mdc_ioc_fid2path(struct obd_export *exp, struct getinfo_fid2path *gf) | |
1108 | { | |
1109 | __u32 keylen, vallen; | |
1110 | void *key; | |
1111 | int rc; | |
1112 | ||
1113 | if (gf->gf_pathlen > PATH_MAX) | |
0a3bdb00 | 1114 | return -ENAMETOOLONG; |
d7e09d03 | 1115 | if (gf->gf_pathlen < 2) |
0a3bdb00 | 1116 | return -EOVERFLOW; |
d7e09d03 PT |
1117 | |
1118 | /* Key is KEY_FID2PATH + getinfo_fid2path description */ | |
1119 | keylen = cfs_size_round(sizeof(KEY_FID2PATH)) + sizeof(*gf); | |
7b81779d | 1120 | key = kzalloc(keylen, GFP_NOFS); |
bb144d09 | 1121 | if (!key) |
0a3bdb00 | 1122 | return -ENOMEM; |
d7e09d03 PT |
1123 | memcpy(key, KEY_FID2PATH, sizeof(KEY_FID2PATH)); |
1124 | memcpy(key + cfs_size_round(sizeof(KEY_FID2PATH)), gf, sizeof(*gf)); | |
1125 | ||
b0f5aad5 | 1126 | CDEBUG(D_IOCTL, "path get "DFID" from %llu #%d\n", |
d7e09d03 PT |
1127 | PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno); |
1128 | ||
d5fdc207 JL |
1129 | if (!fid_is_sane(&gf->gf_fid)) { |
1130 | rc = -EINVAL; | |
1131 | goto out; | |
1132 | } | |
d7e09d03 PT |
1133 | |
1134 | /* Val is struct getinfo_fid2path result plus path */ | |
1135 | vallen = sizeof(*gf) + gf->gf_pathlen; | |
1136 | ||
1137 | rc = obd_get_info(NULL, exp, keylen, key, &vallen, gf, NULL); | |
1138 | if (rc != 0 && rc != -EREMOTE) | |
d5fdc207 | 1139 | goto out; |
d7e09d03 | 1140 | |
d5fdc207 JL |
1141 | if (vallen <= sizeof(*gf)) { |
1142 | rc = -EPROTO; | |
1143 | goto out; | |
1144 | } else if (vallen > sizeof(*gf) + gf->gf_pathlen) { | |
1145 | rc = -EOVERFLOW; | |
1146 | goto out; | |
1147 | } | |
d7e09d03 | 1148 | |
b0f5aad5 | 1149 | CDEBUG(D_IOCTL, "path get "DFID" from %llu #%d\n%s\n", |
d7e09d03 PT |
1150 | PFID(&gf->gf_fid), gf->gf_recno, gf->gf_linkno, gf->gf_path); |
1151 | ||
1152 | out: | |
7b81779d | 1153 | kfree(key); |
d7e09d03 PT |
1154 | return rc; |
1155 | } | |
1156 | ||
1157 | static int mdc_ioc_hsm_progress(struct obd_export *exp, | |
1158 | struct hsm_progress_kernel *hpk) | |
1159 | { | |
1160 | struct obd_import *imp = class_exp2cliimp(exp); | |
1161 | struct hsm_progress_kernel *req_hpk; | |
1162 | struct ptlrpc_request *req; | |
1163 | int rc; | |
d7e09d03 PT |
1164 | |
1165 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_PROGRESS, | |
1166 | LUSTRE_MDS_VERSION, MDS_HSM_PROGRESS); | |
34e3ff96 | 1167 | if (!req) { |
d5fdc207 JL |
1168 | rc = -ENOMEM; |
1169 | goto out; | |
1170 | } | |
d7e09d03 | 1171 | |
ef2e0f55 | 1172 | mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0); |
d7e09d03 PT |
1173 | |
1174 | /* Copy hsm_progress struct */ | |
1175 | req_hpk = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_PROGRESS); | |
34e3ff96 | 1176 | if (!req_hpk) { |
d5fdc207 JL |
1177 | rc = -EPROTO; |
1178 | goto out; | |
1179 | } | |
d7e09d03 PT |
1180 | |
1181 | *req_hpk = *hpk; | |
2d58de78 | 1182 | req_hpk->hpk_errval = lustre_errno_hton(hpk->hpk_errval); |
d7e09d03 PT |
1183 | |
1184 | ptlrpc_request_set_replen(req); | |
1185 | ||
1186 | rc = mdc_queue_wait(req); | |
d7e09d03 PT |
1187 | out: |
1188 | ptlrpc_req_finished(req); | |
1189 | return rc; | |
1190 | } | |
1191 | ||
1192 | static int mdc_ioc_hsm_ct_register(struct obd_import *imp, __u32 archives) | |
1193 | { | |
1194 | __u32 *archive_mask; | |
1195 | struct ptlrpc_request *req; | |
1196 | int rc; | |
d7e09d03 PT |
1197 | |
1198 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_REGISTER, | |
1199 | LUSTRE_MDS_VERSION, | |
1200 | MDS_HSM_CT_REGISTER); | |
34e3ff96 | 1201 | if (!req) { |
d5fdc207 JL |
1202 | rc = -ENOMEM; |
1203 | goto out; | |
1204 | } | |
d7e09d03 | 1205 | |
ef2e0f55 | 1206 | mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0); |
d7e09d03 PT |
1207 | |
1208 | /* Copy hsm_progress struct */ | |
1209 | archive_mask = req_capsule_client_get(&req->rq_pill, | |
1210 | &RMF_MDS_HSM_ARCHIVE); | |
34e3ff96 | 1211 | if (!archive_mask) { |
d5fdc207 JL |
1212 | rc = -EPROTO; |
1213 | goto out; | |
1214 | } | |
d7e09d03 PT |
1215 | |
1216 | *archive_mask = archives; | |
1217 | ||
1218 | ptlrpc_request_set_replen(req); | |
1219 | ||
1220 | rc = mdc_queue_wait(req); | |
d7e09d03 PT |
1221 | out: |
1222 | ptlrpc_req_finished(req); | |
1223 | return rc; | |
1224 | } | |
1225 | ||
1226 | static int mdc_ioc_hsm_current_action(struct obd_export *exp, | |
1227 | struct md_op_data *op_data) | |
1228 | { | |
1229 | struct hsm_current_action *hca = op_data->op_data; | |
1230 | struct hsm_current_action *req_hca; | |
1231 | struct ptlrpc_request *req; | |
1232 | int rc; | |
d7e09d03 PT |
1233 | |
1234 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), | |
1235 | &RQF_MDS_HSM_ACTION); | |
34e3ff96 | 1236 | if (!req) |
0a3bdb00 | 1237 | return -ENOMEM; |
d7e09d03 | 1238 | |
d7e09d03 PT |
1239 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_ACTION); |
1240 | if (rc) { | |
1241 | ptlrpc_request_free(req); | |
0a3bdb00 | 1242 | return rc; |
d7e09d03 PT |
1243 | } |
1244 | ||
ef2e0f55 OD |
1245 | mdc_pack_body(req, &op_data->op_fid1, OBD_MD_FLRMTPERM, 0, |
1246 | op_data->op_suppgids[0], 0); | |
d7e09d03 PT |
1247 | |
1248 | ptlrpc_request_set_replen(req); | |
1249 | ||
1250 | rc = mdc_queue_wait(req); | |
1251 | if (rc) | |
d5fdc207 | 1252 | goto out; |
d7e09d03 PT |
1253 | |
1254 | req_hca = req_capsule_server_get(&req->rq_pill, | |
1255 | &RMF_MDS_HSM_CURRENT_ACTION); | |
34e3ff96 | 1256 | if (!req_hca) { |
d5fdc207 JL |
1257 | rc = -EPROTO; |
1258 | goto out; | |
1259 | } | |
d7e09d03 PT |
1260 | |
1261 | *hca = *req_hca; | |
1262 | ||
d7e09d03 PT |
1263 | out: |
1264 | ptlrpc_req_finished(req); | |
1265 | return rc; | |
1266 | } | |
1267 | ||
1268 | static int mdc_ioc_hsm_ct_unregister(struct obd_import *imp) | |
1269 | { | |
1270 | struct ptlrpc_request *req; | |
1271 | int rc; | |
d7e09d03 PT |
1272 | |
1273 | req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_HSM_CT_UNREGISTER, | |
1274 | LUSTRE_MDS_VERSION, | |
1275 | MDS_HSM_CT_UNREGISTER); | |
34e3ff96 | 1276 | if (!req) { |
d5fdc207 JL |
1277 | rc = -ENOMEM; |
1278 | goto out; | |
1279 | } | |
d7e09d03 | 1280 | |
ef2e0f55 | 1281 | mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0); |
d7e09d03 PT |
1282 | |
1283 | ptlrpc_request_set_replen(req); | |
1284 | ||
1285 | rc = mdc_queue_wait(req); | |
d7e09d03 PT |
1286 | out: |
1287 | ptlrpc_req_finished(req); | |
1288 | return rc; | |
1289 | } | |
1290 | ||
1291 | static int mdc_ioc_hsm_state_get(struct obd_export *exp, | |
1292 | struct md_op_data *op_data) | |
1293 | { | |
1294 | struct hsm_user_state *hus = op_data->op_data; | |
1295 | struct hsm_user_state *req_hus; | |
1296 | struct ptlrpc_request *req; | |
1297 | int rc; | |
d7e09d03 PT |
1298 | |
1299 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), | |
1300 | &RQF_MDS_HSM_STATE_GET); | |
34e3ff96 | 1301 | if (!req) |
0a3bdb00 | 1302 | return -ENOMEM; |
d7e09d03 | 1303 | |
d7e09d03 PT |
1304 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_GET); |
1305 | if (rc != 0) { | |
1306 | ptlrpc_request_free(req); | |
0a3bdb00 | 1307 | return rc; |
d7e09d03 PT |
1308 | } |
1309 | ||
ef2e0f55 OD |
1310 | mdc_pack_body(req, &op_data->op_fid1, OBD_MD_FLRMTPERM, 0, |
1311 | op_data->op_suppgids[0], 0); | |
d7e09d03 PT |
1312 | |
1313 | ptlrpc_request_set_replen(req); | |
1314 | ||
1315 | rc = mdc_queue_wait(req); | |
1316 | if (rc) | |
d5fdc207 | 1317 | goto out; |
d7e09d03 PT |
1318 | |
1319 | req_hus = req_capsule_server_get(&req->rq_pill, &RMF_HSM_USER_STATE); | |
34e3ff96 | 1320 | if (!req_hus) { |
d5fdc207 JL |
1321 | rc = -EPROTO; |
1322 | goto out; | |
1323 | } | |
d7e09d03 PT |
1324 | |
1325 | *hus = *req_hus; | |
1326 | ||
d7e09d03 PT |
1327 | out: |
1328 | ptlrpc_req_finished(req); | |
1329 | return rc; | |
1330 | } | |
1331 | ||
1332 | static int mdc_ioc_hsm_state_set(struct obd_export *exp, | |
1333 | struct md_op_data *op_data) | |
1334 | { | |
1335 | struct hsm_state_set *hss = op_data->op_data; | |
1336 | struct hsm_state_set *req_hss; | |
1337 | struct ptlrpc_request *req; | |
1338 | int rc; | |
d7e09d03 PT |
1339 | |
1340 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), | |
1341 | &RQF_MDS_HSM_STATE_SET); | |
34e3ff96 | 1342 | if (!req) |
0a3bdb00 | 1343 | return -ENOMEM; |
d7e09d03 | 1344 | |
d7e09d03 PT |
1345 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_STATE_SET); |
1346 | if (rc) { | |
1347 | ptlrpc_request_free(req); | |
0a3bdb00 | 1348 | return rc; |
d7e09d03 PT |
1349 | } |
1350 | ||
ef2e0f55 OD |
1351 | mdc_pack_body(req, &op_data->op_fid1, OBD_MD_FLRMTPERM, 0, |
1352 | op_data->op_suppgids[0], 0); | |
d7e09d03 PT |
1353 | |
1354 | /* Copy states */ | |
1355 | req_hss = req_capsule_client_get(&req->rq_pill, &RMF_HSM_STATE_SET); | |
34e3ff96 | 1356 | if (!req_hss) { |
d5fdc207 JL |
1357 | rc = -EPROTO; |
1358 | goto out; | |
1359 | } | |
d7e09d03 PT |
1360 | *req_hss = *hss; |
1361 | ||
1362 | ptlrpc_request_set_replen(req); | |
1363 | ||
1364 | rc = mdc_queue_wait(req); | |
d7e09d03 PT |
1365 | out: |
1366 | ptlrpc_req_finished(req); | |
1367 | return rc; | |
1368 | } | |
1369 | ||
1370 | static int mdc_ioc_hsm_request(struct obd_export *exp, | |
1371 | struct hsm_user_request *hur) | |
1372 | { | |
1373 | struct obd_import *imp = class_exp2cliimp(exp); | |
1374 | struct ptlrpc_request *req; | |
1375 | struct hsm_request *req_hr; | |
1376 | struct hsm_user_item *req_hui; | |
1377 | char *req_opaque; | |
1378 | int rc; | |
d7e09d03 PT |
1379 | |
1380 | req = ptlrpc_request_alloc(imp, &RQF_MDS_HSM_REQUEST); | |
34e3ff96 | 1381 | if (!req) { |
d5fdc207 JL |
1382 | rc = -ENOMEM; |
1383 | goto out; | |
1384 | } | |
d7e09d03 PT |
1385 | |
1386 | req_capsule_set_size(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM, RCL_CLIENT, | |
1387 | hur->hur_request.hr_itemcount | |
1388 | * sizeof(struct hsm_user_item)); | |
1389 | req_capsule_set_size(&req->rq_pill, &RMF_GENERIC_DATA, RCL_CLIENT, | |
1390 | hur->hur_request.hr_data_len); | |
1391 | ||
1392 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_HSM_REQUEST); | |
1393 | if (rc) { | |
1394 | ptlrpc_request_free(req); | |
0a3bdb00 | 1395 | return rc; |
d7e09d03 PT |
1396 | } |
1397 | ||
ef2e0f55 | 1398 | mdc_pack_body(req, NULL, OBD_MD_FLRMTPERM, 0, 0, 0); |
d7e09d03 PT |
1399 | |
1400 | /* Copy hsm_request struct */ | |
1401 | req_hr = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_REQUEST); | |
34e3ff96 | 1402 | if (!req_hr) { |
d5fdc207 JL |
1403 | rc = -EPROTO; |
1404 | goto out; | |
1405 | } | |
d7e09d03 PT |
1406 | *req_hr = hur->hur_request; |
1407 | ||
1408 | /* Copy hsm_user_item structs */ | |
1409 | req_hui = req_capsule_client_get(&req->rq_pill, &RMF_MDS_HSM_USER_ITEM); | |
34e3ff96 | 1410 | if (!req_hui) { |
d5fdc207 JL |
1411 | rc = -EPROTO; |
1412 | goto out; | |
1413 | } | |
d7e09d03 PT |
1414 | memcpy(req_hui, hur->hur_user_item, |
1415 | hur->hur_request.hr_itemcount * sizeof(struct hsm_user_item)); | |
1416 | ||
1417 | /* Copy opaque field */ | |
1418 | req_opaque = req_capsule_client_get(&req->rq_pill, &RMF_GENERIC_DATA); | |
34e3ff96 | 1419 | if (!req_opaque) { |
d5fdc207 JL |
1420 | rc = -EPROTO; |
1421 | goto out; | |
1422 | } | |
d7e09d03 PT |
1423 | memcpy(req_opaque, hur_data(hur), hur->hur_request.hr_data_len); |
1424 | ||
1425 | ptlrpc_request_set_replen(req); | |
1426 | ||
1427 | rc = mdc_queue_wait(req); | |
d7e09d03 PT |
1428 | out: |
1429 | ptlrpc_req_finished(req); | |
1430 | return rc; | |
1431 | } | |
1432 | ||
1433 | static struct kuc_hdr *changelog_kuc_hdr(char *buf, int len, int flags) | |
1434 | { | |
1435 | struct kuc_hdr *lh = (struct kuc_hdr *)buf; | |
1436 | ||
18e042f0 | 1437 | LASSERT(len <= KUC_CHANGELOG_MSG_MAXSIZE); |
d7e09d03 PT |
1438 | |
1439 | lh->kuc_magic = KUC_MAGIC; | |
1440 | lh->kuc_transport = KUC_TRANSPORT_CHANGELOG; | |
1441 | lh->kuc_flags = flags; | |
1442 | lh->kuc_msgtype = CL_RECORD; | |
1443 | lh->kuc_msglen = len; | |
1444 | return lh; | |
1445 | } | |
1446 | ||
1447 | #define D_CHANGELOG 0 | |
1448 | ||
1449 | struct changelog_show { | |
1450 | __u64 cs_startrec; | |
1451 | __u32 cs_flags; | |
1452 | struct file *cs_fp; | |
1453 | char *cs_buf; | |
1454 | struct obd_device *cs_obd; | |
1455 | }; | |
1456 | ||
e377988e | 1457 | static int changelog_kkuc_cb(const struct lu_env *env, struct llog_handle *llh, |
d7e09d03 PT |
1458 | struct llog_rec_hdr *hdr, void *data) |
1459 | { | |
1460 | struct changelog_show *cs = data; | |
1461 | struct llog_changelog_rec *rec = (struct llog_changelog_rec *)hdr; | |
1462 | struct kuc_hdr *lh; | |
1463 | int len, rc; | |
d7e09d03 | 1464 | |
e377988e AD |
1465 | if (rec->cr_hdr.lrh_type != CHANGELOG_REC) { |
1466 | rc = -EINVAL; | |
1467 | CERROR("%s: not a changelog rec %x/%d: rc = %d\n", | |
1468 | cs->cs_obd->obd_name, rec->cr_hdr.lrh_type, | |
1469 | rec->cr.cr_type, rc); | |
0a3bdb00 | 1470 | return rc; |
d7e09d03 PT |
1471 | } |
1472 | ||
1473 | if (rec->cr.cr_index < cs->cs_startrec) { | |
1474 | /* Skip entries earlier than what we are interested in */ | |
b0f5aad5 | 1475 | CDEBUG(D_CHANGELOG, "rec=%llu start=%llu\n", |
d7e09d03 | 1476 | rec->cr.cr_index, cs->cs_startrec); |
0a3bdb00 | 1477 | return 0; |
d7e09d03 PT |
1478 | } |
1479 | ||
b0f5aad5 | 1480 | CDEBUG(D_CHANGELOG, "%llu %02d%-5s %llu 0x%x t="DFID" p="DFID |
d7e09d03 PT |
1481 | " %.*s\n", rec->cr.cr_index, rec->cr.cr_type, |
1482 | changelog_type2str(rec->cr.cr_type), rec->cr.cr_time, | |
1483 | rec->cr.cr_flags & CLF_FLAGMASK, | |
1484 | PFID(&rec->cr.cr_tfid), PFID(&rec->cr.cr_pfid), | |
1485 | rec->cr.cr_namelen, changelog_rec_name(&rec->cr)); | |
1486 | ||
1487 | len = sizeof(*lh) + changelog_rec_size(&rec->cr) + rec->cr.cr_namelen; | |
1488 | ||
1489 | /* Set up the message */ | |
1490 | lh = changelog_kuc_hdr(cs->cs_buf, len, cs->cs_flags); | |
1491 | memcpy(lh + 1, &rec->cr, len - sizeof(*lh)); | |
1492 | ||
1493 | rc = libcfs_kkuc_msg_put(cs->cs_fp, lh); | |
301af906 | 1494 | CDEBUG(D_CHANGELOG, "kucmsg fp %p len %d rc %d\n", cs->cs_fp, len, rc); |
d7e09d03 | 1495 | |
0a3bdb00 | 1496 | return rc; |
d7e09d03 PT |
1497 | } |
1498 | ||
1499 | static int mdc_changelog_send_thread(void *csdata) | |
1500 | { | |
1501 | struct changelog_show *cs = csdata; | |
1502 | struct llog_ctxt *ctxt = NULL; | |
1503 | struct llog_handle *llh = NULL; | |
1504 | struct kuc_hdr *kuch; | |
1505 | int rc; | |
1506 | ||
b0f5aad5 | 1507 | CDEBUG(D_CHANGELOG, "changelog to fp=%p start %llu\n", |
d7e09d03 PT |
1508 | cs->cs_fp, cs->cs_startrec); |
1509 | ||
7b81779d | 1510 | cs->cs_buf = kzalloc(KUC_CHANGELOG_MSG_MAXSIZE, GFP_NOFS); |
bb144d09 | 1511 | if (!cs->cs_buf) { |
d5fdc207 JL |
1512 | rc = -ENOMEM; |
1513 | goto out; | |
1514 | } | |
d7e09d03 PT |
1515 | |
1516 | /* Set up the remote catalog handle */ | |
1517 | ctxt = llog_get_context(cs->cs_obd, LLOG_CHANGELOG_REPL_CTXT); | |
34e3ff96 | 1518 | if (!ctxt) { |
d5fdc207 JL |
1519 | rc = -ENOENT; |
1520 | goto out; | |
1521 | } | |
d7e09d03 PT |
1522 | rc = llog_open(NULL, ctxt, &llh, NULL, CHANGELOG_CATALOG, |
1523 | LLOG_OPEN_EXISTS); | |
1524 | if (rc) { | |
1525 | CERROR("%s: fail to open changelog catalog: rc = %d\n", | |
1526 | cs->cs_obd->obd_name, rc); | |
d5fdc207 | 1527 | goto out; |
d7e09d03 PT |
1528 | } |
1529 | rc = llog_init_handle(NULL, llh, LLOG_F_IS_CAT, NULL); | |
1530 | if (rc) { | |
1531 | CERROR("llog_init_handle failed %d\n", rc); | |
d5fdc207 | 1532 | goto out; |
d7e09d03 PT |
1533 | } |
1534 | ||
e377988e | 1535 | rc = llog_cat_process(NULL, llh, changelog_kkuc_cb, cs, 0, 0); |
d7e09d03 PT |
1536 | |
1537 | /* Send EOF no matter what our result */ | |
4a87df3e CP |
1538 | kuch = changelog_kuc_hdr(cs->cs_buf, sizeof(*kuch), cs->cs_flags); |
1539 | if (kuch) { | |
d7e09d03 PT |
1540 | kuch->kuc_msgtype = CL_EOF; |
1541 | libcfs_kkuc_msg_put(cs->cs_fp, kuch); | |
1542 | } | |
1543 | ||
1544 | out: | |
1545 | fput(cs->cs_fp); | |
1546 | if (llh) | |
1547 | llog_cat_close(NULL, llh); | |
1548 | if (ctxt) | |
1549 | llog_ctxt_put(ctxt); | |
6fa7cbab | 1550 | kfree(cs->cs_buf); |
7b81779d | 1551 | kfree(cs); |
d7e09d03 PT |
1552 | return rc; |
1553 | } | |
1554 | ||
1555 | static int mdc_ioc_changelog_send(struct obd_device *obd, | |
1556 | struct ioc_changelog *icc) | |
1557 | { | |
1558 | struct changelog_show *cs; | |
060c2820 | 1559 | struct task_struct *task; |
d7e09d03 PT |
1560 | int rc; |
1561 | ||
1562 | /* Freed in mdc_changelog_send_thread */ | |
7b81779d | 1563 | cs = kzalloc(sizeof(*cs), GFP_NOFS); |
d7e09d03 PT |
1564 | if (!cs) |
1565 | return -ENOMEM; | |
1566 | ||
1567 | cs->cs_obd = obd; | |
1568 | cs->cs_startrec = icc->icc_recno; | |
1569 | /* matching fput in mdc_changelog_send_thread */ | |
1570 | cs->cs_fp = fget(icc->icc_id); | |
1571 | cs->cs_flags = icc->icc_flags; | |
1572 | ||
1573 | /* | |
1574 | * New thread because we should return to user app before | |
1575 | * writing into our pipe | |
1576 | */ | |
060c2820 JH |
1577 | task = kthread_run(mdc_changelog_send_thread, cs, |
1578 | "mdc_clg_send_thread"); | |
1579 | if (IS_ERR(task)) { | |
1580 | rc = PTR_ERR(task); | |
1581 | CERROR("%s: can't start changelog thread: rc = %d\n", | |
1582 | obd->obd_name, rc); | |
1583 | kfree(cs); | |
1584 | } else { | |
1585 | rc = 0; | |
1586 | CDEBUG(D_CHANGELOG, "%s: started changelog thread\n", | |
1587 | obd->obd_name); | |
d7e09d03 PT |
1588 | } |
1589 | ||
1590 | CERROR("Failed to start changelog thread: %d\n", rc); | |
d7e09d03 PT |
1591 | return rc; |
1592 | } | |
1593 | ||
1594 | static int mdc_ioc_hsm_ct_start(struct obd_export *exp, | |
1595 | struct lustre_kernelcomm *lk); | |
1596 | ||
1597 | static int mdc_quotacheck(struct obd_device *unused, struct obd_export *exp, | |
1598 | struct obd_quotactl *oqctl) | |
1599 | { | |
1600 | struct client_obd *cli = &exp->exp_obd->u.cli; | |
1601 | struct ptlrpc_request *req; | |
1602 | struct obd_quotactl *body; | |
1603 | int rc; | |
d7e09d03 PT |
1604 | |
1605 | req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), | |
1606 | &RQF_MDS_QUOTACHECK, LUSTRE_MDS_VERSION, | |
1607 | MDS_QUOTACHECK); | |
34e3ff96 | 1608 | if (!req) |
0a3bdb00 | 1609 | return -ENOMEM; |
d7e09d03 PT |
1610 | |
1611 | body = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL); | |
1612 | *body = *oqctl; | |
1613 | ||
1614 | ptlrpc_request_set_replen(req); | |
1615 | ||
1616 | /* the next poll will find -ENODATA, that means quotacheck is | |
1df232ee OD |
1617 | * going on |
1618 | */ | |
d7e09d03 PT |
1619 | cli->cl_qchk_stat = -ENODATA; |
1620 | rc = ptlrpc_queue_wait(req); | |
1621 | if (rc) | |
1622 | cli->cl_qchk_stat = rc; | |
1623 | ptlrpc_req_finished(req); | |
0a3bdb00 | 1624 | return rc; |
d7e09d03 PT |
1625 | } |
1626 | ||
1627 | static int mdc_quota_poll_check(struct obd_export *exp, | |
1628 | struct if_quotacheck *qchk) | |
1629 | { | |
1630 | struct client_obd *cli = &exp->exp_obd->u.cli; | |
1631 | int rc; | |
d7e09d03 PT |
1632 | |
1633 | qchk->obd_uuid = cli->cl_target_uuid; | |
1634 | memcpy(qchk->obd_type, LUSTRE_MDS_NAME, strlen(LUSTRE_MDS_NAME)); | |
1635 | ||
1636 | rc = cli->cl_qchk_stat; | |
1637 | /* the client is not the previous one */ | |
1638 | if (rc == CL_NOT_QUOTACHECKED) | |
1639 | rc = -EINTR; | |
0a3bdb00 | 1640 | return rc; |
d7e09d03 PT |
1641 | } |
1642 | ||
1643 | static int mdc_quotactl(struct obd_device *unused, struct obd_export *exp, | |
1644 | struct obd_quotactl *oqctl) | |
1645 | { | |
1646 | struct ptlrpc_request *req; | |
1647 | struct obd_quotactl *oqc; | |
1648 | int rc; | |
d7e09d03 PT |
1649 | |
1650 | req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), | |
1651 | &RQF_MDS_QUOTACTL, LUSTRE_MDS_VERSION, | |
1652 | MDS_QUOTACTL); | |
34e3ff96 | 1653 | if (!req) |
0a3bdb00 | 1654 | return -ENOMEM; |
d7e09d03 PT |
1655 | |
1656 | oqc = req_capsule_client_get(&req->rq_pill, &RMF_OBD_QUOTACTL); | |
1657 | *oqc = *oqctl; | |
1658 | ||
1659 | ptlrpc_request_set_replen(req); | |
1660 | ptlrpc_at_set_req_timeout(req); | |
1661 | req->rq_no_resend = 1; | |
1662 | ||
1663 | rc = ptlrpc_queue_wait(req); | |
1664 | if (rc) | |
1665 | CERROR("ptlrpc_queue_wait failed, rc: %d\n", rc); | |
1666 | ||
4a87df3e CP |
1667 | if (req->rq_repmsg) { |
1668 | oqc = req_capsule_server_get(&req->rq_pill, &RMF_OBD_QUOTACTL); | |
1669 | if (oqc) { | |
1670 | *oqctl = *oqc; | |
1671 | } else if (!rc) { | |
ffdac6ce | 1672 | CERROR("Can't unpack obd_quotactl\n"); |
4a87df3e CP |
1673 | rc = -EPROTO; |
1674 | } | |
d7e09d03 | 1675 | } else if (!rc) { |
4a87df3e | 1676 | CERROR("Can't unpack obd_quotactl\n"); |
d7e09d03 PT |
1677 | rc = -EPROTO; |
1678 | } | |
1679 | ptlrpc_req_finished(req); | |
1680 | ||
0a3bdb00 | 1681 | return rc; |
d7e09d03 PT |
1682 | } |
1683 | ||
1684 | static int mdc_ioc_swap_layouts(struct obd_export *exp, | |
1685 | struct md_op_data *op_data) | |
1686 | { | |
1687 | LIST_HEAD(cancels); | |
1688 | struct ptlrpc_request *req; | |
1689 | int rc, count; | |
1690 | struct mdc_swap_layouts *msl, *payload; | |
d7e09d03 PT |
1691 | |
1692 | msl = op_data->op_data; | |
1693 | ||
1694 | /* When the MDT will get the MDS_SWAP_LAYOUTS RPC the | |
1695 | * first thing it will do is to cancel the 2 layout | |
1696 | * locks hold by this client. | |
1697 | * So the client must cancel its layout locks on the 2 fids | |
1698 | * with the request RPC to avoid extra RPC round trips | |
1699 | */ | |
1700 | count = mdc_resource_get_unused(exp, &op_data->op_fid1, &cancels, | |
1701 | LCK_CR, MDS_INODELOCK_LAYOUT); | |
1702 | count += mdc_resource_get_unused(exp, &op_data->op_fid2, &cancels, | |
1703 | LCK_CR, MDS_INODELOCK_LAYOUT); | |
1704 | ||
1705 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), | |
1706 | &RQF_MDS_SWAP_LAYOUTS); | |
34e3ff96 | 1707 | if (!req) { |
d7e09d03 | 1708 | ldlm_lock_list_put(&cancels, l_bl_ast, count); |
0a3bdb00 | 1709 | return -ENOMEM; |
d7e09d03 PT |
1710 | } |
1711 | ||
d7e09d03 PT |
1712 | rc = mdc_prep_elc_req(exp, req, MDS_SWAP_LAYOUTS, &cancels, count); |
1713 | if (rc) { | |
1714 | ptlrpc_request_free(req); | |
0a3bdb00 | 1715 | return rc; |
d7e09d03 PT |
1716 | } |
1717 | ||
1718 | mdc_swap_layouts_pack(req, op_data); | |
1719 | ||
1720 | payload = req_capsule_client_get(&req->rq_pill, &RMF_SWAP_LAYOUTS); | |
1721 | LASSERT(payload); | |
1722 | ||
1723 | *payload = *msl; | |
1724 | ||
1725 | ptlrpc_request_set_replen(req); | |
1726 | ||
1727 | rc = ptlrpc_queue_wait(req); | |
d7e09d03 | 1728 | |
d7e09d03 PT |
1729 | ptlrpc_req_finished(req); |
1730 | return rc; | |
1731 | } | |
1732 | ||
1733 | static int mdc_iocontrol(unsigned int cmd, struct obd_export *exp, int len, | |
e09bee34 | 1734 | void *karg, void __user *uarg) |
d7e09d03 PT |
1735 | { |
1736 | struct obd_device *obd = exp->exp_obd; | |
1737 | struct obd_ioctl_data *data = karg; | |
1738 | struct obd_import *imp = obd->u.cli.cl_import; | |
d7e09d03 | 1739 | int rc; |
d7e09d03 PT |
1740 | |
1741 | if (!try_module_get(THIS_MODULE)) { | |
19b2056f JN |
1742 | CERROR("%s: cannot get module '%s'\n", obd->obd_name, |
1743 | module_name(THIS_MODULE)); | |
d7e09d03 PT |
1744 | return -EINVAL; |
1745 | } | |
1746 | switch (cmd) { | |
1747 | case OBD_IOC_CHANGELOG_SEND: | |
1748 | rc = mdc_ioc_changelog_send(obd, karg); | |
d5fdc207 | 1749 | goto out; |
d7e09d03 PT |
1750 | case OBD_IOC_CHANGELOG_CLEAR: { |
1751 | struct ioc_changelog *icc = karg; | |
1a4cd3e9 SM |
1752 | struct changelog_setinfo cs = { |
1753 | .cs_recno = icc->icc_recno, | |
1754 | .cs_id = icc->icc_id | |
1755 | }; | |
1756 | ||
d7e09d03 PT |
1757 | rc = obd_set_info_async(NULL, exp, strlen(KEY_CHANGELOG_CLEAR), |
1758 | KEY_CHANGELOG_CLEAR, sizeof(cs), &cs, | |
1759 | NULL); | |
d5fdc207 | 1760 | goto out; |
d7e09d03 PT |
1761 | } |
1762 | case OBD_IOC_FID2PATH: | |
1763 | rc = mdc_ioc_fid2path(exp, karg); | |
d5fdc207 | 1764 | goto out; |
d7e09d03 PT |
1765 | case LL_IOC_HSM_CT_START: |
1766 | rc = mdc_ioc_hsm_ct_start(exp, karg); | |
78eb9092 TL |
1767 | /* ignore if it was already registered on this MDS. */ |
1768 | if (rc == -EEXIST) | |
1769 | rc = 0; | |
d5fdc207 | 1770 | goto out; |
d7e09d03 PT |
1771 | case LL_IOC_HSM_PROGRESS: |
1772 | rc = mdc_ioc_hsm_progress(exp, karg); | |
d5fdc207 | 1773 | goto out; |
d7e09d03 PT |
1774 | case LL_IOC_HSM_STATE_GET: |
1775 | rc = mdc_ioc_hsm_state_get(exp, karg); | |
d5fdc207 | 1776 | goto out; |
d7e09d03 PT |
1777 | case LL_IOC_HSM_STATE_SET: |
1778 | rc = mdc_ioc_hsm_state_set(exp, karg); | |
d5fdc207 | 1779 | goto out; |
d7e09d03 PT |
1780 | case LL_IOC_HSM_ACTION: |
1781 | rc = mdc_ioc_hsm_current_action(exp, karg); | |
d5fdc207 | 1782 | goto out; |
d7e09d03 PT |
1783 | case LL_IOC_HSM_REQUEST: |
1784 | rc = mdc_ioc_hsm_request(exp, karg); | |
d5fdc207 | 1785 | goto out; |
d7e09d03 PT |
1786 | case OBD_IOC_CLIENT_RECOVER: |
1787 | rc = ptlrpc_recover_import(imp, data->ioc_inlbuf1, 0); | |
1788 | if (rc < 0) | |
d5fdc207 JL |
1789 | goto out; |
1790 | rc = 0; | |
1791 | goto out; | |
d7e09d03 PT |
1792 | case IOC_OSC_SET_ACTIVE: |
1793 | rc = ptlrpc_set_import_active(imp, data->ioc_offset); | |
d5fdc207 | 1794 | goto out; |
d7e09d03 PT |
1795 | case OBD_IOC_POLL_QUOTACHECK: |
1796 | rc = mdc_quota_poll_check(exp, (struct if_quotacheck *)karg); | |
d5fdc207 | 1797 | goto out; |
d7e09d03 PT |
1798 | case OBD_IOC_PING_TARGET: |
1799 | rc = ptlrpc_obd_ping(obd); | |
d5fdc207 | 1800 | goto out; |
d7e09d03 PT |
1801 | /* |
1802 | * Normally IOC_OBD_STATFS, OBD_IOC_QUOTACTL iocontrol are handled by | |
1803 | * LMV instead of MDC. But when the cluster is upgraded from 1.8, | |
1804 | * there'd be no LMV layer thus we might be called here. Eventually | |
1805 | * this code should be removed. | |
1806 | * bz20731, LU-592. | |
1807 | */ | |
1808 | case IOC_OBD_STATFS: { | |
1809 | struct obd_statfs stat_buf = {0}; | |
1810 | ||
d5fdc207 JL |
1811 | if (*((__u32 *) data->ioc_inlbuf2) != 0) { |
1812 | rc = -ENODEV; | |
1813 | goto out; | |
1814 | } | |
d7e09d03 PT |
1815 | |
1816 | /* copy UUID */ | |
1817 | if (copy_to_user(data->ioc_pbuf2, obd2cli_tgt(obd), | |
ef4356bf | 1818 | min_t(size_t, data->ioc_plen2, |
22e0bc6a | 1819 | sizeof(struct obd_uuid)))) { |
d5fdc207 JL |
1820 | rc = -EFAULT; |
1821 | goto out; | |
1822 | } | |
d7e09d03 PT |
1823 | |
1824 | rc = mdc_statfs(NULL, obd->obd_self_export, &stat_buf, | |
1825 | cfs_time_shift_64(-OBD_STATFS_CACHE_SECONDS), | |
1826 | 0); | |
1827 | if (rc != 0) | |
d5fdc207 | 1828 | goto out; |
d7e09d03 PT |
1829 | |
1830 | if (copy_to_user(data->ioc_pbuf1, &stat_buf, | |
ef4356bf | 1831 | min_t(size_t, data->ioc_plen1, |
22e0bc6a | 1832 | sizeof(stat_buf)))) { |
d5fdc207 JL |
1833 | rc = -EFAULT; |
1834 | goto out; | |
1835 | } | |
d7e09d03 | 1836 | |
d5fdc207 JL |
1837 | rc = 0; |
1838 | goto out; | |
d7e09d03 PT |
1839 | } |
1840 | case OBD_IOC_QUOTACTL: { | |
1841 | struct if_quotactl *qctl = karg; | |
1842 | struct obd_quotactl *oqctl; | |
1843 | ||
7b81779d | 1844 | oqctl = kzalloc(sizeof(*oqctl), GFP_NOFS); |
bb144d09 | 1845 | if (!oqctl) { |
d5fdc207 JL |
1846 | rc = -ENOMEM; |
1847 | goto out; | |
1848 | } | |
d7e09d03 PT |
1849 | |
1850 | QCTL_COPY(oqctl, qctl); | |
1851 | rc = obd_quotactl(exp, oqctl); | |
1852 | if (rc == 0) { | |
1853 | QCTL_COPY(qctl, oqctl); | |
1854 | qctl->qc_valid = QC_MDTIDX; | |
1855 | qctl->obd_uuid = obd->u.cli.cl_target_uuid; | |
1856 | } | |
c1f3d689 | 1857 | |
7b81779d | 1858 | kfree(oqctl); |
d5fdc207 | 1859 | goto out; |
d7e09d03 | 1860 | } |
c1f3d689 JH |
1861 | case LL_IOC_GET_CONNECT_FLAGS: |
1862 | if (copy_to_user(uarg, exp_connect_flags_ptr(exp), | |
d5fdc207 JL |
1863 | sizeof(*exp_connect_flags_ptr(exp)))) { |
1864 | rc = -EFAULT; | |
1865 | goto out; | |
1866 | } | |
c1f3d689 | 1867 | |
d5fdc207 JL |
1868 | rc = 0; |
1869 | goto out; | |
c1f3d689 | 1870 | case LL_IOC_LOV_SWAP_LAYOUTS: |
d7e09d03 | 1871 | rc = mdc_ioc_swap_layouts(exp, karg); |
d5fdc207 | 1872 | goto out; |
d7e09d03 | 1873 | default: |
c1f3d689 | 1874 | CERROR("unrecognised ioctl: cmd = %#x\n", cmd); |
d5fdc207 JL |
1875 | rc = -ENOTTY; |
1876 | goto out; | |
d7e09d03 PT |
1877 | } |
1878 | out: | |
1879 | module_put(THIS_MODULE); | |
1880 | ||
1881 | return rc; | |
1882 | } | |
1883 | ||
f6219c16 LC |
1884 | static int mdc_get_info_rpc(struct obd_export *exp, |
1885 | u32 keylen, void *key, | |
1886 | int vallen, void *val) | |
d7e09d03 PT |
1887 | { |
1888 | struct obd_import *imp = class_exp2cliimp(exp); | |
1889 | struct ptlrpc_request *req; | |
1890 | char *tmp; | |
1891 | int rc = -EINVAL; | |
d7e09d03 PT |
1892 | |
1893 | req = ptlrpc_request_alloc(imp, &RQF_MDS_GET_INFO); | |
34e3ff96 | 1894 | if (!req) |
0a3bdb00 | 1895 | return -ENOMEM; |
d7e09d03 PT |
1896 | |
1897 | req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_KEY, | |
1898 | RCL_CLIENT, keylen); | |
1899 | req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VALLEN, | |
1900 | RCL_CLIENT, sizeof(__u32)); | |
1901 | ||
1902 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GET_INFO); | |
1903 | if (rc) { | |
1904 | ptlrpc_request_free(req); | |
0a3bdb00 | 1905 | return rc; |
d7e09d03 PT |
1906 | } |
1907 | ||
1908 | tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_KEY); | |
1909 | memcpy(tmp, key, keylen); | |
1910 | tmp = req_capsule_client_get(&req->rq_pill, &RMF_GETINFO_VALLEN); | |
1911 | memcpy(tmp, &vallen, sizeof(__u32)); | |
1912 | ||
1913 | req_capsule_set_size(&req->rq_pill, &RMF_GETINFO_VAL, | |
1914 | RCL_SERVER, vallen); | |
1915 | ptlrpc_request_set_replen(req); | |
1916 | ||
1917 | rc = ptlrpc_queue_wait(req); | |
1918 | /* -EREMOTE means the get_info result is partial, and it needs to | |
1df232ee OD |
1919 | * continue on another MDT, see fid2path part in lmv_iocontrol |
1920 | */ | |
d7e09d03 PT |
1921 | if (rc == 0 || rc == -EREMOTE) { |
1922 | tmp = req_capsule_server_get(&req->rq_pill, &RMF_GETINFO_VAL); | |
1923 | memcpy(val, tmp, vallen); | |
1924 | if (ptlrpc_rep_need_swab(req)) { | |
1925 | if (KEY_IS(KEY_FID2PATH)) | |
1926 | lustre_swab_fid2path(val); | |
1927 | } | |
1928 | } | |
1929 | ptlrpc_req_finished(req); | |
1930 | ||
0a3bdb00 | 1931 | return rc; |
d7e09d03 PT |
1932 | } |
1933 | ||
1934 | static void lustre_swab_hai(struct hsm_action_item *h) | |
1935 | { | |
1936 | __swab32s(&h->hai_len); | |
1937 | __swab32s(&h->hai_action); | |
1938 | lustre_swab_lu_fid(&h->hai_fid); | |
1939 | lustre_swab_lu_fid(&h->hai_dfid); | |
1940 | __swab64s(&h->hai_cookie); | |
1941 | __swab64s(&h->hai_extent.offset); | |
1942 | __swab64s(&h->hai_extent.length); | |
1943 | __swab64s(&h->hai_gid); | |
1944 | } | |
1945 | ||
1946 | static void lustre_swab_hal(struct hsm_action_list *h) | |
1947 | { | |
1948 | struct hsm_action_item *hai; | |
1949 | int i; | |
1950 | ||
1951 | __swab32s(&h->hal_version); | |
1952 | __swab32s(&h->hal_count); | |
1953 | __swab32s(&h->hal_archive_id); | |
1954 | __swab64s(&h->hal_flags); | |
1955 | hai = hai_zero(h); | |
18dfaebf | 1956 | for (i = 0; i < h->hal_count; i++, hai = hai_next(hai)) |
d7e09d03 | 1957 | lustre_swab_hai(hai); |
d7e09d03 PT |
1958 | } |
1959 | ||
1960 | static void lustre_swab_kuch(struct kuc_hdr *l) | |
1961 | { | |
1962 | __swab16s(&l->kuc_magic); | |
1963 | /* __u8 l->kuc_transport */ | |
1964 | __swab16s(&l->kuc_msgtype); | |
1965 | __swab16s(&l->kuc_msglen); | |
1966 | } | |
1967 | ||
1968 | static int mdc_ioc_hsm_ct_start(struct obd_export *exp, | |
1969 | struct lustre_kernelcomm *lk) | |
1970 | { | |
1971 | struct obd_import *imp = class_exp2cliimp(exp); | |
1972 | __u32 archive = lk->lk_data; | |
1973 | int rc = 0; | |
1974 | ||
1975 | if (lk->lk_group != KUC_GRP_HSM) { | |
1976 | CERROR("Bad copytool group %d\n", lk->lk_group); | |
1977 | return -EINVAL; | |
1978 | } | |
1979 | ||
1980 | CDEBUG(D_HSM, "CT start r%d w%d u%d g%d f%#x\n", lk->lk_rfd, lk->lk_wfd, | |
1981 | lk->lk_uid, lk->lk_group, lk->lk_flags); | |
1982 | ||
1983 | if (lk->lk_flags & LK_FLG_STOP) { | |
d7e09d03 | 1984 | /* Unregister with the coordinator */ |
78eb9092 | 1985 | rc = mdc_ioc_hsm_ct_unregister(imp); |
d7e09d03 | 1986 | } else { |
78eb9092 | 1987 | rc = mdc_ioc_hsm_ct_register(imp, archive); |
d7e09d03 PT |
1988 | } |
1989 | ||
1990 | return rc; | |
1991 | } | |
1992 | ||
1993 | /** | |
1994 | * Send a message to any listening copytools | |
1995 | * @param val KUC message (kuc_hdr + hsm_action_list) | |
1996 | * @param len total length of message | |
1997 | */ | |
1998 | static int mdc_hsm_copytool_send(int len, void *val) | |
1999 | { | |
2000 | struct kuc_hdr *lh = (struct kuc_hdr *)val; | |
2001 | struct hsm_action_list *hal = (struct hsm_action_list *)(lh + 1); | |
d7e09d03 PT |
2002 | |
2003 | if (len < sizeof(*lh) + sizeof(*hal)) { | |
2004 | CERROR("Short HSM message %d < %d\n", len, | |
2005 | (int) (sizeof(*lh) + sizeof(*hal))); | |
0a3bdb00 | 2006 | return -EPROTO; |
d7e09d03 PT |
2007 | } |
2008 | if (lh->kuc_magic == __swab16(KUC_MAGIC)) { | |
2009 | lustre_swab_kuch(lh); | |
2010 | lustre_swab_hal(hal); | |
2011 | } else if (lh->kuc_magic != KUC_MAGIC) { | |
2012 | CERROR("Bad magic %x!=%x\n", lh->kuc_magic, KUC_MAGIC); | |
0a3bdb00 | 2013 | return -EPROTO; |
d7e09d03 PT |
2014 | } |
2015 | ||
ee990b33 SM |
2016 | CDEBUG(D_HSM, |
2017 | "Received message mg=%x t=%d m=%d l=%d actions=%d on %s\n", | |
d7e09d03 PT |
2018 | lh->kuc_magic, lh->kuc_transport, lh->kuc_msgtype, |
2019 | lh->kuc_msglen, hal->hal_count, hal->hal_fsname); | |
2020 | ||
2021 | /* Broadcast to HSM listeners */ | |
da2a7272 | 2022 | return libcfs_kkuc_group_put(KUC_GRP_HSM, lh); |
d7e09d03 PT |
2023 | } |
2024 | ||
2025 | /** | |
2026 | * callback function passed to kuc for re-registering each HSM copytool | |
2027 | * running on MDC, after MDT shutdown/recovery. | |
406fc913 | 2028 | * @param data copytool registration data |
d7e09d03 PT |
2029 | * @param cb_arg callback argument (obd_import) |
2030 | */ | |
406fc913 | 2031 | static int mdc_hsm_ct_reregister(void *data, void *cb_arg) |
d7e09d03 | 2032 | { |
406fc913 | 2033 | struct kkuc_ct_data *kcd = data; |
d7e09d03 | 2034 | struct obd_import *imp = (struct obd_import *)cb_arg; |
d7e09d03 PT |
2035 | int rc; |
2036 | ||
406fc913 HD |
2037 | if (!kcd || kcd->kcd_magic != KKUC_CT_DATA_MAGIC) |
2038 | return -EPROTO; | |
2039 | ||
2040 | if (!obd_uuid_equals(&kcd->kcd_uuid, &imp->imp_obd->obd_uuid)) | |
2041 | return 0; | |
2042 | ||
2043 | CDEBUG(D_HA, "%s: recover copytool registration to MDT (archive=%#x)\n", | |
2044 | imp->imp_obd->obd_name, kcd->kcd_archive); | |
2045 | rc = mdc_ioc_hsm_ct_register(imp, kcd->kcd_archive); | |
d7e09d03 PT |
2046 | |
2047 | /* ignore error if the copytool is already registered */ | |
406fc913 | 2048 | return (rc == -EEXIST) ? 0 : rc; |
d7e09d03 PT |
2049 | } |
2050 | ||
f6219c16 LC |
2051 | static int mdc_set_info_async(const struct lu_env *env, |
2052 | struct obd_export *exp, | |
2053 | u32 keylen, void *key, | |
2054 | u32 vallen, void *val, | |
2055 | struct ptlrpc_request_set *set) | |
d7e09d03 PT |
2056 | { |
2057 | struct obd_import *imp = class_exp2cliimp(exp); | |
2058 | int rc; | |
d7e09d03 PT |
2059 | |
2060 | if (KEY_IS(KEY_READ_ONLY)) { | |
2061 | if (vallen != sizeof(int)) | |
0a3bdb00 | 2062 | return -EINVAL; |
d7e09d03 PT |
2063 | |
2064 | spin_lock(&imp->imp_lock); | |
2065 | if (*((int *)val)) { | |
2066 | imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY; | |
2067 | imp->imp_connect_data.ocd_connect_flags |= | |
2068 | OBD_CONNECT_RDONLY; | |
2069 | } else { | |
2070 | imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY; | |
2071 | imp->imp_connect_data.ocd_connect_flags &= | |
2072 | ~OBD_CONNECT_RDONLY; | |
2073 | } | |
2074 | spin_unlock(&imp->imp_lock); | |
2075 | ||
2076 | rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION, | |
2077 | keylen, key, vallen, val, set); | |
0a3bdb00 | 2078 | return rc; |
d7e09d03 PT |
2079 | } |
2080 | if (KEY_IS(KEY_SPTLRPC_CONF)) { | |
2081 | sptlrpc_conf_client_adapt(exp->exp_obd); | |
0a3bdb00 | 2082 | return 0; |
d7e09d03 PT |
2083 | } |
2084 | if (KEY_IS(KEY_FLUSH_CTX)) { | |
2085 | sptlrpc_import_flush_my_ctx(imp); | |
0a3bdb00 | 2086 | return 0; |
d7e09d03 | 2087 | } |
d7e09d03 PT |
2088 | if (KEY_IS(KEY_CHANGELOG_CLEAR)) { |
2089 | rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION, | |
2090 | keylen, key, vallen, val, set); | |
0a3bdb00 | 2091 | return rc; |
d7e09d03 PT |
2092 | } |
2093 | if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) { | |
2094 | rc = mdc_hsm_copytool_send(vallen, val); | |
0a3bdb00 | 2095 | return rc; |
d7e09d03 PT |
2096 | } |
2097 | ||
2098 | CERROR("Unknown key %s\n", (char *)key); | |
0a3bdb00 | 2099 | return -EINVAL; |
d7e09d03 PT |
2100 | } |
2101 | ||
f6219c16 LC |
2102 | static int mdc_get_info(const struct lu_env *env, struct obd_export *exp, |
2103 | __u32 keylen, void *key, __u32 *vallen, void *val, | |
2104 | struct lov_stripe_md *lsm) | |
d7e09d03 PT |
2105 | { |
2106 | int rc = -EINVAL; | |
2107 | ||
2108 | if (KEY_IS(KEY_MAX_EASIZE)) { | |
2109 | int mdsize, *max_easize; | |
2110 | ||
2111 | if (*vallen != sizeof(int)) | |
0a3bdb00 | 2112 | return -EINVAL; |
44779340 | 2113 | mdsize = *(int *)val; |
d7e09d03 PT |
2114 | if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize) |
2115 | exp->exp_obd->u.cli.cl_max_mds_easize = mdsize; | |
2116 | max_easize = val; | |
2117 | *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize; | |
0a3bdb00 | 2118 | return 0; |
44779340 BB |
2119 | } else if (KEY_IS(KEY_DEFAULT_EASIZE)) { |
2120 | int *default_easize; | |
2121 | ||
2122 | if (*vallen != sizeof(int)) | |
2123 | return -EINVAL; | |
2124 | default_easize = val; | |
2125 | *default_easize = exp->exp_obd->u.cli.cl_default_mds_easize; | |
2126 | return 0; | |
d7e09d03 PT |
2127 | } else if (KEY_IS(KEY_CONN_DATA)) { |
2128 | struct obd_import *imp = class_exp2cliimp(exp); | |
2129 | struct obd_connect_data *data = val; | |
2130 | ||
2131 | if (*vallen != sizeof(*data)) | |
0a3bdb00 | 2132 | return -EINVAL; |
d7e09d03 PT |
2133 | |
2134 | *data = imp->imp_connect_data; | |
0a3bdb00 | 2135 | return 0; |
d7e09d03 PT |
2136 | } else if (KEY_IS(KEY_TGT_COUNT)) { |
2137 | *((int *)val) = 1; | |
0a3bdb00 | 2138 | return 0; |
d7e09d03 PT |
2139 | } |
2140 | ||
2141 | rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val); | |
2142 | ||
0a3bdb00 | 2143 | return rc; |
d7e09d03 PT |
2144 | } |
2145 | ||
f6219c16 | 2146 | static int mdc_sync(struct obd_export *exp, const struct lu_fid *fid, |
ef2e0f55 | 2147 | struct ptlrpc_request **request) |
d7e09d03 PT |
2148 | { |
2149 | struct ptlrpc_request *req; | |
2150 | int rc; | |
d7e09d03 PT |
2151 | |
2152 | *request = NULL; | |
2153 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC); | |
34e3ff96 | 2154 | if (!req) |
0a3bdb00 | 2155 | return -ENOMEM; |
d7e09d03 | 2156 | |
d7e09d03 PT |
2157 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC); |
2158 | if (rc) { | |
2159 | ptlrpc_request_free(req); | |
0a3bdb00 | 2160 | return rc; |
d7e09d03 PT |
2161 | } |
2162 | ||
ef2e0f55 | 2163 | mdc_pack_body(req, fid, 0, 0, -1, 0); |
d7e09d03 PT |
2164 | |
2165 | ptlrpc_request_set_replen(req); | |
2166 | ||
2167 | rc = ptlrpc_queue_wait(req); | |
2168 | if (rc) | |
2169 | ptlrpc_req_finished(req); | |
2170 | else | |
2171 | *request = req; | |
0a3bdb00 | 2172 | return rc; |
d7e09d03 PT |
2173 | } |
2174 | ||
2175 | static int mdc_import_event(struct obd_device *obd, struct obd_import *imp, | |
2176 | enum obd_import_event event) | |
2177 | { | |
2178 | int rc = 0; | |
2179 | ||
2180 | LASSERT(imp->imp_obd == obd); | |
2181 | ||
2182 | switch (event) { | |
2183 | case IMP_EVENT_DISCON: { | |
2184 | #if 0 | |
2185 | /* XXX Pass event up to OBDs stack. used only for FLD now */ | |
2186 | rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL); | |
2187 | #endif | |
2188 | break; | |
2189 | } | |
2190 | case IMP_EVENT_INACTIVE: { | |
2191 | struct client_obd *cli = &obd->u.cli; | |
2192 | /* | |
2193 | * Flush current sequence to make client obtain new one | |
2194 | * from server in case of disconnect/reconnect. | |
2195 | */ | |
34e3ff96 | 2196 | if (cli->cl_seq) |
d7e09d03 PT |
2197 | seq_client_flush(cli->cl_seq); |
2198 | ||
2199 | rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL); | |
2200 | break; | |
2201 | } | |
2202 | case IMP_EVENT_INVALIDATE: { | |
2203 | struct ldlm_namespace *ns = obd->obd_namespace; | |
2204 | ||
2205 | ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY); | |
2206 | ||
2207 | break; | |
2208 | } | |
2209 | case IMP_EVENT_ACTIVE: | |
2210 | rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL); | |
78eb9092 | 2211 | /* redo the kuc registration after reconnecting */ |
d7e09d03 | 2212 | if (rc == 0) |
dd40ca46 SB |
2213 | /* re-register HSM agents */ |
2214 | rc = libcfs_kkuc_group_foreach(KUC_GRP_HSM, | |
2215 | mdc_hsm_ct_reregister, | |
2216 | (void *)imp); | |
d7e09d03 PT |
2217 | break; |
2218 | case IMP_EVENT_OCD: | |
2219 | rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL); | |
2220 | break; | |
2221 | case IMP_EVENT_DEACTIVATE: | |
2222 | case IMP_EVENT_ACTIVATE: | |
2223 | break; | |
2224 | default: | |
2225 | CERROR("Unknown import event %x\n", event); | |
2226 | LBUG(); | |
2227 | } | |
0a3bdb00 | 2228 | return rc; |
d7e09d03 PT |
2229 | } |
2230 | ||
2231 | int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid, | |
2232 | struct md_op_data *op_data) | |
2233 | { | |
2234 | struct client_obd *cli = &exp->exp_obd->u.cli; | |
2235 | struct lu_client_seq *seq = cli->cl_seq; | |
29aaf496 | 2236 | |
0a3bdb00 | 2237 | return seq_client_alloc_fid(NULL, seq, fid); |
d7e09d03 PT |
2238 | } |
2239 | ||
f6219c16 | 2240 | static struct obd_uuid *mdc_get_uuid(struct obd_export *exp) |
982ec91f | 2241 | { |
d7e09d03 | 2242 | struct client_obd *cli = &exp->exp_obd->u.cli; |
7436d070 | 2243 | |
d7e09d03 PT |
2244 | return &cli->cl_target_uuid; |
2245 | } | |
2246 | ||
2247 | /** | |
2248 | * Determine whether the lock can be canceled before replaying it during | |
2249 | * recovery, non zero value will be return if the lock can be canceled, | |
2250 | * or zero returned for not | |
2251 | */ | |
2252 | static int mdc_cancel_for_recovery(struct ldlm_lock *lock) | |
2253 | { | |
2254 | if (lock->l_resource->lr_type != LDLM_IBITS) | |
0a3bdb00 | 2255 | return 0; |
d7e09d03 PT |
2256 | |
2257 | /* FIXME: if we ever get into a situation where there are too many | |
2258 | * opened files with open locks on a single node, then we really | |
1df232ee OD |
2259 | * should replay these open locks to reget it |
2260 | */ | |
d7e09d03 | 2261 | if (lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_OPEN) |
0a3bdb00 | 2262 | return 0; |
d7e09d03 | 2263 | |
0a3bdb00 | 2264 | return 1; |
d7e09d03 PT |
2265 | } |
2266 | ||
2267 | static int mdc_resource_inode_free(struct ldlm_resource *res) | |
2268 | { | |
2269 | if (res->lr_lvb_inode) | |
2270 | res->lr_lvb_inode = NULL; | |
2271 | ||
2272 | return 0; | |
2273 | } | |
2274 | ||
f6219c16 | 2275 | static struct ldlm_valblock_ops inode_lvbo = { |
805e517a | 2276 | .lvbo_free = mdc_resource_inode_free, |
d7e09d03 PT |
2277 | }; |
2278 | ||
903af118 JH |
2279 | static int mdc_llog_init(struct obd_device *obd) |
2280 | { | |
2281 | struct obd_llog_group *olg = &obd->obd_olg; | |
2282 | struct llog_ctxt *ctxt; | |
2283 | int rc; | |
2284 | ||
2285 | rc = llog_setup(NULL, obd, olg, LLOG_CHANGELOG_REPL_CTXT, obd, | |
2286 | &llog_client_ops); | |
2287 | if (rc) | |
2288 | return rc; | |
2289 | ||
2290 | ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT); | |
2291 | llog_initiator_connect(ctxt); | |
2292 | llog_ctxt_put(ctxt); | |
2293 | ||
2294 | return 0; | |
2295 | } | |
2296 | ||
2297 | static void mdc_llog_finish(struct obd_device *obd) | |
2298 | { | |
2299 | struct llog_ctxt *ctxt; | |
2300 | ||
2301 | ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT); | |
2302 | if (ctxt) | |
2303 | llog_cleanup(NULL, ctxt); | |
2304 | } | |
2305 | ||
d7e09d03 PT |
2306 | static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg) |
2307 | { | |
2308 | struct client_obd *cli = &obd->u.cli; | |
ea7893bb | 2309 | struct lprocfs_static_vars lvars = { NULL }; |
d7e09d03 | 2310 | int rc; |
d7e09d03 | 2311 | |
7b81779d | 2312 | cli->cl_rpc_lock = kzalloc(sizeof(*cli->cl_rpc_lock), GFP_NOFS); |
d7e09d03 | 2313 | if (!cli->cl_rpc_lock) |
0a3bdb00 | 2314 | return -ENOMEM; |
d7e09d03 PT |
2315 | mdc_init_rpc_lock(cli->cl_rpc_lock); |
2316 | ||
2317 | ptlrpcd_addref(); | |
2318 | ||
7b81779d | 2319 | cli->cl_close_lock = kzalloc(sizeof(*cli->cl_close_lock), GFP_NOFS); |
d5fdc207 JL |
2320 | if (!cli->cl_close_lock) { |
2321 | rc = -ENOMEM; | |
2322 | goto err_rpc_lock; | |
2323 | } | |
d7e09d03 PT |
2324 | mdc_init_rpc_lock(cli->cl_close_lock); |
2325 | ||
2326 | rc = client_obd_setup(obd, cfg); | |
2327 | if (rc) | |
d5fdc207 | 2328 | goto err_close_lock; |
d7e09d03 | 2329 | lprocfs_mdc_init_vars(&lvars); |
9b801302 | 2330 | lprocfs_obd_setup(obd, lvars.obd_vars, lvars.sysfs_vars); |
d7e09d03 PT |
2331 | sptlrpc_lprocfs_cliobd_attach(obd); |
2332 | ptlrpc_lprocfs_register_obd(obd); | |
2333 | ||
2334 | ns_register_cancel(obd->obd_namespace, mdc_cancel_for_recovery); | |
2335 | ||
2336 | obd->obd_namespace->ns_lvbo = &inode_lvbo; | |
2337 | ||
903af118 | 2338 | rc = mdc_llog_init(obd); |
d7e09d03 PT |
2339 | if (rc) { |
2340 | mdc_cleanup(obd); | |
2341 | CERROR("failed to setup llogging subsystems\n"); | |
2342 | } | |
2343 | ||
0a3bdb00 | 2344 | return rc; |
d7e09d03 PT |
2345 | |
2346 | err_close_lock: | |
7b81779d | 2347 | kfree(cli->cl_close_lock); |
d7e09d03 | 2348 | err_rpc_lock: |
7b81779d | 2349 | kfree(cli->cl_rpc_lock); |
d7e09d03 | 2350 | ptlrpcd_decref(); |
0a3bdb00 | 2351 | return rc; |
d7e09d03 PT |
2352 | } |
2353 | ||
2354 | /* Initialize the default and maximum LOV EA and cookie sizes. This allows | |
44779340 BB |
2355 | * us to make MDS RPCs with large enough reply buffers to hold a default |
2356 | * sized EA and cookie without having to calculate this (via a call into the | |
2357 | * LOV + OSCs) each time we make an RPC. The maximum size is also tracked | |
2358 | * but not used to avoid wastefully vmalloc()'ing large reply buffers when | |
2359 | * a large number of stripes is possible. If a larger reply buffer is | |
2360 | * required it will be reallocated in the ptlrpc layer due to overflow. | |
2361 | */ | |
d7e09d03 | 2362 | static int mdc_init_ea_size(struct obd_export *exp, int easize, |
44779340 | 2363 | int def_easize, int cookiesize, int def_cookiesize) |
d7e09d03 PT |
2364 | { |
2365 | struct obd_device *obd = exp->exp_obd; | |
2366 | struct client_obd *cli = &obd->u.cli; | |
d7e09d03 PT |
2367 | |
2368 | if (cli->cl_max_mds_easize < easize) | |
2369 | cli->cl_max_mds_easize = easize; | |
2370 | ||
2371 | if (cli->cl_default_mds_easize < def_easize) | |
2372 | cli->cl_default_mds_easize = def_easize; | |
2373 | ||
2374 | if (cli->cl_max_mds_cookiesize < cookiesize) | |
2375 | cli->cl_max_mds_cookiesize = cookiesize; | |
2376 | ||
44779340 BB |
2377 | if (cli->cl_default_mds_cookiesize < def_cookiesize) |
2378 | cli->cl_default_mds_cookiesize = def_cookiesize; | |
2379 | ||
0a3bdb00 | 2380 | return 0; |
d7e09d03 PT |
2381 | } |
2382 | ||
2383 | static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage) | |
2384 | { | |
d7e09d03 PT |
2385 | switch (stage) { |
2386 | case OBD_CLEANUP_EARLY: | |
2387 | break; | |
2388 | case OBD_CLEANUP_EXPORTS: | |
2389 | /* Failsafe, ok if racy */ | |
2390 | if (obd->obd_type->typ_refcnt <= 1) | |
17328956 | 2391 | libcfs_kkuc_group_rem(0, KUC_GRP_HSM); |
d7e09d03 PT |
2392 | |
2393 | obd_cleanup_client_import(obd); | |
2394 | ptlrpc_lprocfs_unregister_obd(obd); | |
2395 | lprocfs_obd_cleanup(obd); | |
2396 | ||
903af118 | 2397 | mdc_llog_finish(obd); |
d7e09d03 PT |
2398 | break; |
2399 | } | |
eb967126 | 2400 | return 0; |
d7e09d03 PT |
2401 | } |
2402 | ||
2403 | static int mdc_cleanup(struct obd_device *obd) | |
2404 | { | |
2405 | struct client_obd *cli = &obd->u.cli; | |
2406 | ||
7b81779d JL |
2407 | kfree(cli->cl_rpc_lock); |
2408 | kfree(cli->cl_close_lock); | |
d7e09d03 PT |
2409 | |
2410 | ptlrpcd_decref(); | |
2411 | ||
2412 | return client_obd_cleanup(obd); | |
2413 | } | |
2414 | ||
21aef7d9 | 2415 | static int mdc_process_config(struct obd_device *obd, u32 len, void *buf) |
d7e09d03 PT |
2416 | { |
2417 | struct lustre_cfg *lcfg = buf; | |
ea7893bb | 2418 | struct lprocfs_static_vars lvars = { NULL }; |
d7e09d03 PT |
2419 | int rc = 0; |
2420 | ||
2421 | lprocfs_mdc_init_vars(&lvars); | |
2422 | switch (lcfg->lcfg_command) { | |
2423 | default: | |
2424 | rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars, | |
2425 | lcfg, obd); | |
2426 | if (rc > 0) | |
2427 | rc = 0; | |
2428 | break; | |
2429 | } | |
eb44520b | 2430 | return rc; |
d7e09d03 PT |
2431 | } |
2432 | ||
d7e09d03 | 2433 | /* get remote permission for current user on fid */ |
f6219c16 | 2434 | static int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid, |
ef2e0f55 | 2435 | __u32 suppgid, struct ptlrpc_request **request) |
d7e09d03 PT |
2436 | { |
2437 | struct ptlrpc_request *req; | |
2438 | int rc; | |
d7e09d03 PT |
2439 | |
2440 | LASSERT(client_is_remote(exp)); | |
2441 | ||
2442 | *request = NULL; | |
2443 | req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR); | |
34e3ff96 | 2444 | if (!req) |
0a3bdb00 | 2445 | return -ENOMEM; |
d7e09d03 | 2446 | |
d7e09d03 PT |
2447 | rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR); |
2448 | if (rc) { | |
2449 | ptlrpc_request_free(req); | |
0a3bdb00 | 2450 | return rc; |
d7e09d03 PT |
2451 | } |
2452 | ||
ef2e0f55 | 2453 | mdc_pack_body(req, fid, OBD_MD_FLRMTPERM, 0, suppgid, 0); |
d7e09d03 PT |
2454 | |
2455 | req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER, | |
2456 | sizeof(struct mdt_remote_perm)); | |
2457 | ||
2458 | ptlrpc_request_set_replen(req); | |
2459 | ||
2460 | rc = ptlrpc_queue_wait(req); | |
2461 | if (rc) | |
2462 | ptlrpc_req_finished(req); | |
2463 | else | |
2464 | *request = req; | |
0a3bdb00 | 2465 | return rc; |
d7e09d03 PT |
2466 | } |
2467 | ||
f6219c16 | 2468 | static struct obd_ops mdc_obd_ops = { |
a13b1f32 DC |
2469 | .owner = THIS_MODULE, |
2470 | .setup = mdc_setup, | |
2471 | .precleanup = mdc_precleanup, | |
2472 | .cleanup = mdc_cleanup, | |
2473 | .add_conn = client_import_add_conn, | |
2474 | .del_conn = client_import_del_conn, | |
2475 | .connect = client_connect_import, | |
2476 | .disconnect = client_disconnect_export, | |
2477 | .iocontrol = mdc_iocontrol, | |
2478 | .set_info_async = mdc_set_info_async, | |
2479 | .statfs = mdc_statfs, | |
2480 | .fid_init = client_fid_init, | |
2481 | .fid_fini = client_fid_fini, | |
2482 | .fid_alloc = mdc_fid_alloc, | |
2483 | .import_event = mdc_import_event, | |
2484 | .get_info = mdc_get_info, | |
2485 | .process_config = mdc_process_config, | |
2486 | .get_uuid = mdc_get_uuid, | |
2487 | .quotactl = mdc_quotactl, | |
2488 | .quotacheck = mdc_quotacheck | |
d7e09d03 PT |
2489 | }; |
2490 | ||
f6219c16 | 2491 | static struct md_ops mdc_md_ops = { |
df18a80a DC |
2492 | .getstatus = mdc_getstatus, |
2493 | .null_inode = mdc_null_inode, | |
2494 | .find_cbdata = mdc_find_cbdata, | |
2495 | .close = mdc_close, | |
2496 | .create = mdc_create, | |
2497 | .done_writing = mdc_done_writing, | |
2498 | .enqueue = mdc_enqueue, | |
2499 | .getattr = mdc_getattr, | |
2500 | .getattr_name = mdc_getattr_name, | |
2501 | .intent_lock = mdc_intent_lock, | |
2502 | .link = mdc_link, | |
2503 | .is_subdir = mdc_is_subdir, | |
2504 | .rename = mdc_rename, | |
2505 | .setattr = mdc_setattr, | |
2506 | .setxattr = mdc_setxattr, | |
2507 | .getxattr = mdc_getxattr, | |
2508 | .sync = mdc_sync, | |
2509 | .readpage = mdc_readpage, | |
2510 | .unlink = mdc_unlink, | |
2511 | .cancel_unused = mdc_cancel_unused, | |
2512 | .init_ea_size = mdc_init_ea_size, | |
2513 | .set_lock_data = mdc_set_lock_data, | |
2514 | .lock_match = mdc_lock_match, | |
2515 | .get_lustre_md = mdc_get_lustre_md, | |
2516 | .free_lustre_md = mdc_free_lustre_md, | |
2517 | .set_open_replay_data = mdc_set_open_replay_data, | |
2518 | .clear_open_replay_data = mdc_clear_open_replay_data, | |
2519 | .get_remote_perm = mdc_get_remote_perm, | |
2520 | .intent_getattr_async = mdc_intent_getattr_async, | |
2521 | .revalidate_lock = mdc_revalidate_lock | |
d7e09d03 PT |
2522 | }; |
2523 | ||
f6219c16 | 2524 | static int __init mdc_init(void) |
d7e09d03 | 2525 | { |
ea7893bb | 2526 | struct lprocfs_static_vars lvars = { NULL }; |
7436d070 | 2527 | |
d7e09d03 PT |
2528 | lprocfs_mdc_init_vars(&lvars); |
2529 | ||
2962b440 | 2530 | return class_register_type(&mdc_obd_ops, &mdc_md_ops, |
d7e09d03 | 2531 | LUSTRE_MDC_NAME, NULL); |
d7e09d03 PT |
2532 | } |
2533 | ||
2534 | static void /*__exit*/ mdc_exit(void) | |
2535 | { | |
2536 | class_unregister_type(LUSTRE_MDC_NAME); | |
2537 | } | |
2538 | ||
a0455471 | 2539 | MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>"); |
d7e09d03 | 2540 | MODULE_DESCRIPTION("Lustre Metadata Client"); |
5b0e50b9 | 2541 | MODULE_VERSION(LUSTRE_VERSION_STRING); |
d7e09d03 PT |
2542 | MODULE_LICENSE("GPL"); |
2543 | ||
2544 | module_init(mdc_init); | |
2545 | module_exit(mdc_exit); |