Version:  2.0.40 2.2.26 2.4.37 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 4.7

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

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