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