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