Version:  2.0.40 2.2.26 2.4.37 3.9 3.10 3.11 3.12 3.13 3.14 3.15 3.16 3.17 3.18 3.19 4.0 4.1 4.2 4.3 4.4 4.5 4.6

Linux/drivers/staging/lustre/lustre/mdc/mdc_request.c

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

This page was automatically generated by LXR 0.3.1 (source).  •  Linux is a registered trademark of Linus Torvalds  •  Contact us