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