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