Whamcloud - gitweb
LU-1146 build: batch update copyright messages
[fs/lustre-release.git] / lustre / mdc / mdc_request.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  *
32  * Copyright (c) 2011, 2012, Whamcloud, Inc.
33  */
34 /*
35  * This file is part of Lustre, http://www.lustre.org/
36  * Lustre is a trademark of Sun Microsystems, Inc.
37  */
38
39 #ifndef EXPORT_SYMTAB
40 # define EXPORT_SYMTAB
41 #endif
42 #define DEBUG_SUBSYSTEM S_MDC
43
44 #ifdef __KERNEL__
45 # include <linux/module.h>
46 # include <linux/pagemap.h>
47 # include <linux/miscdevice.h>
48 # include <linux/init.h>
49 #else
50 # include <liblustre.h>
51 #endif
52
53 #include <lustre_acl.h>
54 #include <obd_class.h>
55 #include <lustre_dlm.h>
56 #include <lustre_fid.h>
57 #include <md_object.h>
58 #include <lprocfs_status.h>
59 #include <lustre_param.h>
60 #include "mdc_internal.h"
61 #include <lustre/lustre_idl.h>
62
63 #define REQUEST_MINOR 244
64
65 struct mdc_renew_capa_args {
66         struct obd_capa        *ra_oc;
67         renew_capa_cb_t         ra_cb;
68 };
69
70 static int mdc_cleanup(struct obd_device *obd);
71
72 int mdc_unpack_capa(struct obd_export *exp, struct ptlrpc_request *req,
73                     const struct req_msg_field *field, struct obd_capa **oc)
74 {
75         struct lustre_capa *capa;
76         struct obd_capa *c;
77         ENTRY;
78
79         /* swabbed already in mdc_enqueue */
80         capa = req_capsule_server_get(&req->rq_pill, field);
81         if (capa == NULL)
82                 RETURN(-EPROTO);
83
84         c = alloc_capa(CAPA_SITE_CLIENT);
85         if (IS_ERR(c)) {
86                 CDEBUG(D_INFO, "alloc capa failed!\n");
87                 RETURN(PTR_ERR(c));
88         } else {
89                 c->c_capa = *capa;
90                 *oc = c;
91                 RETURN(0);
92         }
93 }
94
95 /* Helper that implements most of mdc_getstatus and signal_completed_replay. */
96 /* XXX this should become mdc_get_info("key"), sending MDS_GET_INFO RPC */
97 static int send_getstatus(struct obd_import *imp, struct lu_fid *rootfid,
98                           struct obd_capa **pc, int level, int msg_flags)
99 {
100         struct ptlrpc_request *req;
101         struct mdt_body       *body;
102         int                    rc;
103         ENTRY;
104
105         req = ptlrpc_request_alloc_pack(imp, &RQF_MDS_GETSTATUS,
106                                         LUSTRE_MDS_VERSION, MDS_GETSTATUS);
107         if (req == NULL)
108                 RETURN(-ENOMEM);
109
110         mdc_pack_body(req, NULL, NULL, 0, 0, -1, 0);
111         lustre_msg_add_flags(req->rq_reqmsg, msg_flags);
112         req->rq_send_state = level;
113
114         ptlrpc_request_set_replen(req);
115
116         rc = ptlrpc_queue_wait(req);
117         if (rc)
118                 GOTO(out, rc);
119
120         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
121         if (body == NULL)
122                 GOTO(out, rc = -EPROTO);
123
124         if (body->valid & OBD_MD_FLMDSCAPA) {
125                 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, pc);
126                 if (rc)
127                         GOTO(out, rc);
128         }
129
130         *rootfid = body->fid1;
131         CDEBUG(D_NET,
132                "root fid="DFID", last_committed="LPU64"\n",
133                PFID(rootfid),
134                lustre_msg_get_last_committed(req->rq_repmsg));
135         EXIT;
136 out:
137         ptlrpc_req_finished(req);
138         return rc;
139 }
140
141 /* This should be mdc_get_info("rootfid") */
142 int mdc_getstatus(struct obd_export *exp, struct lu_fid *rootfid,
143                   struct obd_capa **pc)
144 {
145         return send_getstatus(class_exp2cliimp(exp), rootfid, pc,
146                               LUSTRE_IMP_FULL, 0);
147 }
148
149 /*
150  * This function now is known to always saying that it will receive 4 buffers
151  * from server. Even for cases when acl_size and md_size is zero, RPC header
152  * will contain 4 fields and RPC itself will contain zero size fields. This is
153  * because mdt_getattr*() _always_ returns 4 fields, but if acl is not needed
154  * and thus zero, it shrinks it, making zero size. The same story about
155  * md_size. And this is course of problem when client waits for smaller number
156  * of fields. This issue will be fixed later when client gets aware of RPC
157  * layouts.  --umka
158  */
159 static int mdc_getattr_common(struct obd_export *exp,
160                               struct ptlrpc_request *req)
161 {
162         struct req_capsule *pill = &req->rq_pill;
163         struct mdt_body    *body;
164         void               *eadata;
165         int                 rc;
166         ENTRY;
167
168         /* Request message already built. */
169         rc = ptlrpc_queue_wait(req);
170         if (rc != 0)
171                 RETURN(rc);
172
173         /* sanity check for the reply */
174         body = req_capsule_server_get(pill, &RMF_MDT_BODY);
175         if (body == NULL)
176                 RETURN(-EPROTO);
177
178         CDEBUG(D_NET, "mode: %o\n", body->mode);
179
180         if (body->eadatasize != 0) {
181                 mdc_update_max_ea_from_body(exp, body);
182
183                 eadata = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
184                                                       body->eadatasize);
185                 if (eadata == NULL)
186                         RETURN(-EPROTO);
187         }
188
189         if (body->valid & OBD_MD_FLRMTPERM) {
190                 struct mdt_remote_perm *perm;
191
192                 LASSERT(client_is_remote(exp));
193                 perm = req_capsule_server_swab_get(pill, &RMF_ACL,
194                                                 lustre_swab_mdt_remote_perm);
195                 if (perm == NULL)
196                         RETURN(-EPROTO);
197         }
198
199         if (body->valid & OBD_MD_FLMDSCAPA) {
200                 struct lustre_capa *capa;
201                 capa = req_capsule_server_get(pill, &RMF_CAPA1);
202                 if (capa == NULL)
203                         RETURN(-EPROTO);
204         }
205
206         RETURN(0);
207 }
208
209 int mdc_getattr(struct obd_export *exp, struct md_op_data *op_data,
210                 struct ptlrpc_request **request)
211 {
212         struct ptlrpc_request *req;
213         int                    rc;
214         ENTRY;
215
216         *request = NULL;
217         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
218         if (req == NULL)
219                 RETURN(-ENOMEM);
220
221         mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
222
223         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
224         if (rc) {
225                 ptlrpc_request_free(req);
226                 RETURN(rc);
227         }
228
229         mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
230                       op_data->op_valid, op_data->op_mode, -1, 0);
231
232         req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
233                              op_data->op_mode);
234         if (op_data->op_valid & OBD_MD_FLRMTPERM) {
235                 LASSERT(client_is_remote(exp));
236                 req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
237                                      sizeof(struct mdt_remote_perm));
238         }
239         ptlrpc_request_set_replen(req);
240
241         rc = mdc_getattr_common(exp, req);
242         if (rc)
243                 ptlrpc_req_finished(req);
244         else
245                 *request = req;
246         RETURN(rc);
247 }
248
249 int mdc_getattr_name(struct obd_export *exp, struct md_op_data *op_data,
250                      struct ptlrpc_request **request)
251 {
252         struct ptlrpc_request *req;
253         int                    rc;
254         ENTRY;
255
256         *request = NULL;
257         req = ptlrpc_request_alloc(class_exp2cliimp(exp),
258                                    &RQF_MDS_GETATTR_NAME);
259         if (req == NULL)
260                 RETURN(-ENOMEM);
261
262         mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
263         req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
264                              op_data->op_namelen + 1);
265
266         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR_NAME);
267         if (rc) {
268                 ptlrpc_request_free(req);
269                 RETURN(rc);
270         }
271
272         mdc_pack_body(req, &op_data->op_fid1, op_data->op_capa1,
273                       op_data->op_valid, op_data->op_mode,
274                       op_data->op_suppgids[0], 0);
275
276         if (op_data->op_name) {
277                 char *name = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
278                 LASSERT(strnlen(op_data->op_name, op_data->op_namelen) ==
279                                 op_data->op_namelen);
280                 memcpy(name, op_data->op_name, op_data->op_namelen);
281         }
282
283         req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
284                              op_data->op_mode);
285         ptlrpc_request_set_replen(req);
286
287         rc = mdc_getattr_common(exp, req);
288         if (rc)
289                 ptlrpc_req_finished(req);
290         else
291                 *request = req;
292         RETURN(rc);
293 }
294
295 static int mdc_is_subdir(struct obd_export *exp,
296                          const struct lu_fid *pfid,
297                          const struct lu_fid *cfid,
298                          struct ptlrpc_request **request)
299 {
300         struct ptlrpc_request  *req;
301         int                     rc;
302
303         ENTRY;
304
305         *request = NULL;
306         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp),
307                                         &RQF_MDS_IS_SUBDIR, LUSTRE_MDS_VERSION,
308                                         MDS_IS_SUBDIR);
309         if (req == NULL)
310                 RETURN(-ENOMEM);
311
312         mdc_is_subdir_pack(req, pfid, cfid, 0);
313         ptlrpc_request_set_replen(req);
314
315         rc = ptlrpc_queue_wait(req);
316         if (rc && rc != -EREMOTE)
317                 ptlrpc_req_finished(req);
318         else
319                 *request = req;
320         RETURN(rc);
321 }
322
323 static int mdc_xattr_common(struct obd_export *exp,const struct req_format *fmt,
324                             const struct lu_fid *fid,
325                             struct obd_capa *oc, int opcode, obd_valid valid,
326                             const char *xattr_name, const char *input,
327                             int input_size, int output_size, int flags,
328                             __u32 suppgid, struct ptlrpc_request **request)
329 {
330         struct ptlrpc_request *req;
331         int   xattr_namelen = 0;
332         char *tmp;
333         int   rc;
334         ENTRY;
335
336         *request = NULL;
337         req = ptlrpc_request_alloc(class_exp2cliimp(exp), fmt);
338         if (req == NULL)
339                 RETURN(-ENOMEM);
340
341         mdc_set_capa_size(req, &RMF_CAPA1, oc);
342         if (xattr_name) {
343                 xattr_namelen = strlen(xattr_name) + 1;
344                 req_capsule_set_size(&req->rq_pill, &RMF_NAME, RCL_CLIENT,
345                                      xattr_namelen);
346         }
347         if (input_size) {
348                 LASSERT(input);
349                 req_capsule_set_size(&req->rq_pill, &RMF_EADATA, RCL_CLIENT,
350                                      input_size);
351         }
352
353         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, opcode);
354         if (rc) {
355                 ptlrpc_request_free(req);
356                 RETURN(rc);
357         }
358
359         if (opcode == MDS_REINT) {
360                 struct mdt_rec_setxattr *rec;
361
362                 CLASSERT(sizeof(struct mdt_rec_setxattr) ==
363                          sizeof(struct mdt_rec_reint));
364                 rec = req_capsule_client_get(&req->rq_pill, &RMF_REC_REINT);
365                 rec->sx_opcode = REINT_SETXATTR;
366                 /* TODO:
367                  *  cfs_curproc_fs{u,g}id() should replace
368                  *  current->fs{u,g}id for portability.
369                  */
370                 rec->sx_fsuid  = cfs_curproc_fsuid();
371                 rec->sx_fsgid  = cfs_curproc_fsgid();
372                 rec->sx_cap    = cfs_curproc_cap_pack();
373                 rec->sx_suppgid1 = suppgid;
374                 rec->sx_suppgid2 = -1;
375                 rec->sx_fid    = *fid;
376                 rec->sx_valid  = valid | OBD_MD_FLCTIME;
377                 rec->sx_time   = cfs_time_current_sec();
378                 rec->sx_size   = output_size;
379                 rec->sx_flags  = flags;
380
381                 mdc_pack_capa(req, &RMF_CAPA1, oc);
382         } else {
383                 mdc_pack_body(req, fid, oc, valid, output_size, suppgid, flags);
384         }
385
386         if (xattr_name) {
387                 tmp = req_capsule_client_get(&req->rq_pill, &RMF_NAME);
388                 memcpy(tmp, xattr_name, xattr_namelen);
389         }
390         if (input_size) {
391                 tmp = req_capsule_client_get(&req->rq_pill, &RMF_EADATA);
392                 memcpy(tmp, input, input_size);
393         }
394
395         if (req_capsule_has_field(&req->rq_pill, &RMF_EADATA, RCL_SERVER))
396                 req_capsule_set_size(&req->rq_pill, &RMF_EADATA,
397                                      RCL_SERVER, output_size);
398         ptlrpc_request_set_replen(req);
399
400         /* make rpc */
401         if (opcode == MDS_REINT)
402                 mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
403
404         rc = ptlrpc_queue_wait(req);
405
406         if (opcode == MDS_REINT)
407                 mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
408
409         if (rc)
410                 ptlrpc_req_finished(req);
411         else
412                 *request = req;
413         RETURN(rc);
414 }
415
416 int mdc_setxattr(struct obd_export *exp, const struct lu_fid *fid,
417                  struct obd_capa *oc, obd_valid valid, const char *xattr_name,
418                  const char *input, int input_size, int output_size,
419                  int flags, __u32 suppgid, struct ptlrpc_request **request)
420 {
421         return mdc_xattr_common(exp, &RQF_MDS_REINT_SETXATTR,
422                                 fid, oc, MDS_REINT, valid, xattr_name,
423                                 input, input_size, output_size, flags,
424                                 suppgid, request);
425 }
426
427 int mdc_getxattr(struct obd_export *exp, const struct lu_fid *fid,
428                  struct obd_capa *oc, obd_valid valid, const char *xattr_name,
429                  const char *input, int input_size, int output_size,
430                  int flags, struct ptlrpc_request **request)
431 {
432         return mdc_xattr_common(exp, &RQF_MDS_GETXATTR,
433                                 fid, oc, MDS_GETXATTR, valid, xattr_name,
434                                 input, input_size, output_size, flags,
435                                 -1, request);
436 }
437
438 #ifdef CONFIG_FS_POSIX_ACL
439 static int mdc_unpack_acl(struct ptlrpc_request *req, struct lustre_md *md)
440 {
441         struct req_capsule     *pill = &req->rq_pill;
442         struct mdt_body        *body = md->body;
443         struct posix_acl       *acl;
444         void                   *buf;
445         int                     rc;
446         ENTRY;
447
448         if (!body->aclsize)
449                 RETURN(0);
450
451         buf = req_capsule_server_sized_get(pill, &RMF_ACL, body->aclsize);
452
453         if (!buf)
454                 RETURN(-EPROTO);
455
456         acl = posix_acl_from_xattr(buf, body->aclsize);
457         if (IS_ERR(acl)) {
458                 rc = PTR_ERR(acl);
459                 CERROR("convert xattr to acl: %d\n", rc);
460                 RETURN(rc);
461         }
462
463         rc = posix_acl_valid(acl);
464         if (rc) {
465                 CERROR("validate acl: %d\n", rc);
466                 posix_acl_release(acl);
467                 RETURN(rc);
468         }
469
470         md->posix_acl = acl;
471         RETURN(0);
472 }
473 #else
474 #define mdc_unpack_acl(req, md) 0
475 #endif
476
477 int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
478                       struct obd_export *dt_exp, struct obd_export *md_exp,
479                       struct lustre_md *md)
480 {
481         struct req_capsule *pill = &req->rq_pill;
482         int rc;
483         ENTRY;
484
485         LASSERT(md);
486         memset(md, 0, sizeof(*md));
487
488         md->body = req_capsule_server_get(pill, &RMF_MDT_BODY);
489         LASSERT(md->body != NULL);
490
491         if (md->body->valid & OBD_MD_FLEASIZE) {
492                 int lmmsize;
493                 struct lov_mds_md *lmm;
494
495                 if (!S_ISREG(md->body->mode)) {
496                         CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, should be a "
497                                "regular file, but is not\n");
498                         GOTO(out, rc = -EPROTO);
499                 }
500
501                 if (md->body->eadatasize == 0) {
502                         CDEBUG(D_INFO, "OBD_MD_FLEASIZE set, "
503                                "but eadatasize 0\n");
504                         GOTO(out, rc = -EPROTO);
505                 }
506                 lmmsize = md->body->eadatasize;
507                 lmm = req_capsule_server_sized_get(pill, &RMF_MDT_MD, lmmsize);
508                 if (!lmm)
509                         GOTO(out, rc = -EPROTO);
510
511                 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
512                 if (rc < 0)
513                         GOTO(out, rc);
514
515                 if (rc < sizeof(*md->lsm)) {
516                         CDEBUG(D_INFO, "lsm size too small: "
517                                "rc < sizeof (*md->lsm) (%d < %d)\n",
518                                rc, (int)sizeof(*md->lsm));
519                         GOTO(out, rc = -EPROTO);
520                 }
521
522         } else if (md->body->valid & OBD_MD_FLDIREA) {
523                 int lmvsize;
524                 struct lov_mds_md *lmv;
525
526                 if(!S_ISDIR(md->body->mode)) {
527                         CDEBUG(D_INFO, "OBD_MD_FLDIREA set, should be a "
528                                "directory, but is not\n");
529                         GOTO(out, rc = -EPROTO);
530                 }
531
532                 if (md->body->eadatasize == 0) {
533                         CDEBUG(D_INFO, "OBD_MD_FLDIREA is set, "
534                                "but eadatasize 0\n");
535                         RETURN(-EPROTO);
536                 }
537                 if (md->body->valid & OBD_MD_MEA) {
538                         lmvsize = md->body->eadatasize;
539                         lmv = req_capsule_server_sized_get(pill, &RMF_MDT_MD,
540                                                            lmvsize);
541                         if (!lmv)
542                                 GOTO(out, rc = -EPROTO);
543
544                         rc = obd_unpackmd(md_exp, (void *)&md->mea, lmv,
545                                           lmvsize);
546                         if (rc < 0)
547                                 GOTO(out, rc);
548
549                         if (rc < sizeof(*md->mea)) {
550                                 CDEBUG(D_INFO, "size too small:  "
551                                        "rc < sizeof(*md->mea) (%d < %d)\n",
552                                         rc, (int)sizeof(*md->mea));
553                                 GOTO(out, rc = -EPROTO);
554                         }
555                 }
556         }
557         rc = 0;
558
559         if (md->body->valid & OBD_MD_FLRMTPERM) {
560                 /* remote permission */
561                 LASSERT(client_is_remote(exp));
562                 md->remote_perm = req_capsule_server_swab_get(pill, &RMF_ACL,
563                                                 lustre_swab_mdt_remote_perm);
564                 if (!md->remote_perm)
565                         GOTO(out, rc = -EPROTO);
566         }
567         else if (md->body->valid & OBD_MD_FLACL) {
568                 /* for ACL, it's possible that FLACL is set but aclsize is zero.
569                  * only when aclsize != 0 there's an actual segment for ACL
570                  * in reply buffer.
571                  */
572                 if (md->body->aclsize) {
573                         rc = mdc_unpack_acl(req, md);
574                         if (rc)
575                                 GOTO(out, rc);
576 #ifdef CONFIG_FS_POSIX_ACL
577                 } else {
578                         md->posix_acl = NULL;
579 #endif
580                 }
581         }
582         if (md->body->valid & OBD_MD_FLMDSCAPA) {
583                 struct obd_capa *oc = NULL;
584
585                 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA1, &oc);
586                 if (rc)
587                         GOTO(out, rc);
588                 md->mds_capa = oc;
589         }
590
591         if (md->body->valid & OBD_MD_FLOSSCAPA) {
592                 struct obd_capa *oc = NULL;
593
594                 rc = mdc_unpack_capa(NULL, req, &RMF_CAPA2, &oc);
595                 if (rc)
596                         GOTO(out, rc);
597                 md->oss_capa = oc;
598         }
599
600         EXIT;
601 out:
602         if (rc) {
603                 if (md->oss_capa) {
604                         capa_put(md->oss_capa);
605                         md->oss_capa = NULL;
606                 }
607                 if (md->mds_capa) {
608                         capa_put(md->mds_capa);
609                         md->mds_capa = NULL;
610                 }
611 #ifdef CONFIG_FS_POSIX_ACL
612                 posix_acl_release(md->posix_acl);
613 #endif
614                 if (md->lsm)
615                         obd_free_memmd(dt_exp, &md->lsm);
616         }
617         return rc;
618 }
619
620 int mdc_free_lustre_md(struct obd_export *exp, struct lustre_md *md)
621 {
622         ENTRY;
623         RETURN(0);
624 }
625
626 /**
627  * Handles both OPEN and SETATTR RPCs for OPEN-CLOSE and SETATTR-DONE_WRITING
628  * RPC chains.
629  */
630 void mdc_replay_open(struct ptlrpc_request *req)
631 {
632         struct md_open_data *mod = req->rq_cb_data;
633         struct ptlrpc_request *close_req;
634         struct obd_client_handle *och;
635         struct lustre_handle old;
636         struct mdt_body *body;
637         ENTRY;
638
639         if (mod == NULL) {
640                 DEBUG_REQ(D_ERROR, req,
641                           "Can't properly replay without open data.");
642                 EXIT;
643                 return;
644         }
645
646         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
647         LASSERT(body != NULL);
648
649         och = mod->mod_och;
650         if (och != NULL) {
651                 struct lustre_handle *file_fh;
652
653                 LASSERT(och->och_magic == OBD_CLIENT_HANDLE_MAGIC);
654
655                 file_fh = &och->och_fh;
656                 CDEBUG(D_HA, "updating handle from "LPX64" to "LPX64"\n",
657                        file_fh->cookie, body->handle.cookie);
658                 old = *file_fh;
659                 *file_fh = body->handle;
660         }
661         close_req = mod->mod_close_req;
662         if (close_req != NULL) {
663                 __u32 opc = lustre_msg_get_opc(close_req->rq_reqmsg);
664                 struct mdt_ioepoch *epoch;
665
666                 LASSERT(opc == MDS_CLOSE || opc == MDS_DONE_WRITING);
667                 epoch = req_capsule_client_get(&close_req->rq_pill,
668                                                &RMF_MDT_EPOCH);
669                 LASSERT(epoch);
670
671                 if (och != NULL)
672                         LASSERT(!memcmp(&old, &epoch->handle, sizeof(old)));
673                 DEBUG_REQ(D_HA, close_req, "updating close body with new fh");
674                 epoch->handle = body->handle;
675         }
676         EXIT;
677 }
678
679 void mdc_commit_open(struct ptlrpc_request *req)
680 {
681         struct md_open_data *mod = req->rq_cb_data;
682         if (mod == NULL)
683                 return;
684
685         /**
686          * No need to touch md_open_data::mod_och, it holds a reference on
687          * \var mod and will zero references to each other, \var mod will be
688          * freed after that when md_open_data::mod_och will put the reference.
689          */
690
691         /**
692          * Do not let open request to disappear as it still may be needed
693          * for close rpc to happen (it may happen on evict only, otherwise
694          * ptlrpc_request::rq_replay does not let mdc_commit_open() to be
695          * called), just mark this rpc as committed to distinguish these 2
696          * cases, see mdc_close() for details. The open request reference will
697          * be put along with freeing \var mod.
698          */
699         ptlrpc_request_addref(req);
700         cfs_spin_lock(&req->rq_lock);
701         req->rq_committed = 1;
702         cfs_spin_unlock(&req->rq_lock);
703         req->rq_cb_data = NULL;
704         obd_mod_put(mod);
705 }
706
707 int mdc_set_open_replay_data(struct obd_export *exp,
708                              struct obd_client_handle *och,
709                              struct ptlrpc_request *open_req)
710 {
711         struct md_open_data   *mod;
712         struct mdt_rec_create *rec;
713         struct mdt_body       *body;
714         struct obd_import     *imp = open_req->rq_import;
715         ENTRY;
716
717         if (!open_req->rq_replay)
718                 RETURN(0);
719
720         rec = req_capsule_client_get(&open_req->rq_pill, &RMF_REC_REINT);
721         body = req_capsule_server_get(&open_req->rq_pill, &RMF_MDT_BODY);
722         LASSERT(rec != NULL);
723         /* Incoming message in my byte order (it's been swabbed). */
724         /* Outgoing messages always in my byte order. */
725         LASSERT(body != NULL);
726
727         /* Only if the import is replayable, we set replay_open data */
728         if (och && imp->imp_replayable) {
729                 mod = obd_mod_alloc();
730                 if (mod == NULL) {
731                         DEBUG_REQ(D_ERROR, open_req,
732                                   "Can't allocate md_open_data");
733                         RETURN(0);
734                 }
735
736                 /**
737                  * Take a reference on \var mod, to be freed on mdc_close().
738                  * It protects \var mod from being freed on eviction (commit
739                  * callback is called despite rq_replay flag).
740                  * Another reference for \var och.
741                  */
742                 obd_mod_get(mod);
743                 obd_mod_get(mod);
744
745                 cfs_spin_lock(&open_req->rq_lock);
746                 och->och_mod = mod;
747                 mod->mod_och = och;
748                 mod->mod_open_req = open_req;
749                 open_req->rq_cb_data = mod;
750                 open_req->rq_commit_cb = mdc_commit_open;
751                 cfs_spin_unlock(&open_req->rq_lock);
752         }
753
754         rec->cr_fid2 = body->fid1;
755         rec->cr_ioepoch = body->ioepoch;
756         rec->cr_old_handle.cookie = body->handle.cookie;
757         open_req->rq_replay_cb = mdc_replay_open;
758         if (!fid_is_sane(&body->fid1)) {
759                 DEBUG_REQ(D_ERROR, open_req, "Saving replay request with "
760                           "insane fid");
761                 LBUG();
762         }
763
764         DEBUG_REQ(D_RPCTRACE, open_req, "Set up open replay data");
765         RETURN(0);
766 }
767
768 int mdc_clear_open_replay_data(struct obd_export *exp,
769                                struct obd_client_handle *och)
770 {
771         struct md_open_data *mod = och->och_mod;
772         ENTRY;
773
774         /**
775          * It is possible to not have \var mod in a case of eviction between
776          * lookup and ll_file_open().
777          **/
778         if (mod == NULL)
779                 RETURN(0);
780
781         LASSERT(mod != LP_POISON);
782
783         mod->mod_och = NULL;
784         och->och_mod = NULL;
785         obd_mod_put(mod);
786
787         RETURN(0);
788 }
789
790 /* Prepares the request for the replay by the given reply */
791 static void mdc_close_handle_reply(struct ptlrpc_request *req,
792                                    struct md_op_data *op_data, int rc) {
793         struct mdt_body  *repbody;
794         struct mdt_ioepoch *epoch;
795
796         if (req && rc == -EAGAIN) {
797                 repbody = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
798                 epoch = req_capsule_client_get(&req->rq_pill, &RMF_MDT_EPOCH);
799
800                 epoch->flags |= MF_SOM_AU;
801                 if (repbody->valid & OBD_MD_FLGETATTRLOCK)
802                         op_data->op_flags |= MF_GETATTR_LOCK;
803         }
804 }
805
806 int mdc_close(struct obd_export *exp, struct md_op_data *op_data,
807               struct md_open_data *mod, struct ptlrpc_request **request)
808 {
809         struct obd_device     *obd = class_exp2obd(exp);
810         struct ptlrpc_request *req;
811         int                    rc;
812         ENTRY;
813
814         *request = NULL;
815         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_CLOSE);
816         if (req == NULL)
817                 RETURN(-ENOMEM);
818
819         mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
820
821         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_CLOSE);
822         if (rc) {
823                 ptlrpc_request_free(req);
824                 RETURN(rc);
825         }
826
827         /* To avoid a livelock (bug 7034), we need to send CLOSE RPCs to a
828          * portal whose threads are not taking any DLM locks and are therefore
829          * always progressing */
830         req->rq_request_portal = MDS_READPAGE_PORTAL;
831         ptlrpc_at_set_req_timeout(req);
832
833         /* Ensure that this close's handle is fixed up during replay. */
834         if (likely(mod != NULL)) {
835                 LASSERTF(mod->mod_open_req != NULL &&
836                          mod->mod_open_req->rq_type != LI_POISON,
837                          "POISONED open %p!\n", mod->mod_open_req);
838
839                 mod->mod_close_req = req;
840
841                 DEBUG_REQ(D_HA, mod->mod_open_req, "matched open");
842                 /* We no longer want to preserve this open for replay even
843                  * though the open was committed. b=3632, b=3633 */
844                 cfs_spin_lock(&mod->mod_open_req->rq_lock);
845                 mod->mod_open_req->rq_replay = 0;
846                 cfs_spin_unlock(&mod->mod_open_req->rq_lock);
847         } else {
848                  CDEBUG(D_HA, "couldn't find open req; expecting close error\n");
849         }
850
851         mdc_close_pack(req, op_data);
852
853         req_capsule_set_size(&req->rq_pill, &RMF_MDT_MD, RCL_SERVER,
854                              obd->u.cli.cl_max_mds_easize);
855         req_capsule_set_size(&req->rq_pill, &RMF_LOGCOOKIES, RCL_SERVER,
856                              obd->u.cli.cl_max_mds_cookiesize);
857
858         ptlrpc_request_set_replen(req);
859
860         mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
861         rc = ptlrpc_queue_wait(req);
862         mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
863
864         if (req->rq_repmsg == NULL) {
865                 CDEBUG(D_RPCTRACE, "request failed to send: %p, %d\n", req,
866                        req->rq_status);
867                 if (rc == 0)
868                         rc = req->rq_status ?: -EIO;
869         } else if (rc == 0 || rc == -EAGAIN) {
870                 struct mdt_body *body;
871
872                 rc = lustre_msg_get_status(req->rq_repmsg);
873                 if (lustre_msg_get_type(req->rq_repmsg) == PTL_RPC_MSG_ERR) {
874                         DEBUG_REQ(D_ERROR, req, "type == PTL_RPC_MSG_ERR, err "
875                                   "= %d", rc);
876                         if (rc > 0)
877                                 rc = -rc;
878                 }
879                 body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
880                 if (body == NULL)
881                         rc = -EPROTO;
882         } else if (rc == -ESTALE) {
883                 /**
884                  * it can be allowed error after 3633 if open was committed and
885                  * server failed before close was sent. Let's check if mod
886                  * exists and return no error in that case
887                  */
888                 if (mod) {
889                         DEBUG_REQ(D_HA, req, "Reset ESTALE = %d", rc);
890                         LASSERT(mod->mod_open_req != NULL);
891                         if (mod->mod_open_req->rq_committed)
892                                 rc = 0;
893                 }
894         }
895
896         if (mod) {
897                 if (rc != 0)
898                         mod->mod_close_req = NULL;
899                 /* Since now, mod is accessed through open_req only,
900                  * thus close req does not keep a reference on mod anymore. */
901                 obd_mod_put(mod);
902         }
903         *request = req;
904         mdc_close_handle_reply(req, op_data, rc);
905         RETURN(rc);
906 }
907
908 int mdc_done_writing(struct obd_export *exp, struct md_op_data *op_data,
909                      struct md_open_data *mod)
910 {
911         struct obd_device     *obd = class_exp2obd(exp);
912         struct ptlrpc_request *req;
913         int                    rc;
914         ENTRY;
915
916         req = ptlrpc_request_alloc(class_exp2cliimp(exp),
917                                    &RQF_MDS_DONE_WRITING);
918         if (req == NULL)
919                 RETURN(-ENOMEM);
920
921         mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
922         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_DONE_WRITING);
923         if (rc) {
924                 ptlrpc_request_free(req);
925                 RETURN(rc);
926         }
927
928         if (mod != NULL) {
929                 LASSERTF(mod->mod_open_req != NULL &&
930                          mod->mod_open_req->rq_type != LI_POISON,
931                          "POISONED setattr %p!\n", mod->mod_open_req);
932
933                 mod->mod_close_req = req;
934                 DEBUG_REQ(D_HA, mod->mod_open_req, "matched setattr");
935                 /* We no longer want to preserve this setattr for replay even
936                  * though the open was committed. b=3632, b=3633 */
937                 cfs_spin_lock(&mod->mod_open_req->rq_lock);
938                 mod->mod_open_req->rq_replay = 0;
939                 cfs_spin_unlock(&mod->mod_open_req->rq_lock);
940         }
941
942         mdc_close_pack(req, op_data);
943         ptlrpc_request_set_replen(req);
944
945         mdc_get_rpc_lock(obd->u.cli.cl_close_lock, NULL);
946         rc = ptlrpc_queue_wait(req);
947         mdc_put_rpc_lock(obd->u.cli.cl_close_lock, NULL);
948
949         if (rc == -ESTALE) {
950                 /**
951                  * it can be allowed error after 3633 if open or setattr were
952                  * committed and server failed before close was sent.
953                  * Let's check if mod exists and return no error in that case
954                  */
955                 if (mod) {
956                         LASSERT(mod->mod_open_req != NULL);
957                         if (mod->mod_open_req->rq_committed)
958                                 rc = 0;
959                 }
960         }
961
962         if (mod) {
963                 if (rc != 0)
964                         mod->mod_close_req = NULL;
965                 /* Since now, mod is accessed through setattr req only,
966                  * thus DW req does not keep a reference on mod anymore. */
967                 obd_mod_put(mod);
968         }
969
970         mdc_close_handle_reply(req, op_data, rc);
971         ptlrpc_req_finished(req);
972         RETURN(rc);
973 }
974
975 #ifdef HAVE_SPLIT_SUPPORT
976 int mdc_sendpage(struct obd_export *exp, const struct lu_fid *fid,
977                  const struct page *page, int offset)
978 {
979         struct ptlrpc_request   *req;
980         struct ptlrpc_bulk_desc *desc;
981         int                      rc;
982         ENTRY;
983
984         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_WRITEPAGE);
985         if (req == NULL)
986                 RETURN(-ENOMEM);
987
988         /* FIXME: capa doesn't support split yet */
989         mdc_set_capa_size(req, &RMF_CAPA1, NULL);
990
991         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_WRITEPAGE);
992         if (rc) {
993                 ptlrpc_request_free(req);
994                 RETURN(rc);
995         }
996
997         req->rq_request_portal = MDS_READPAGE_PORTAL;
998         ptlrpc_at_set_req_timeout(req);
999
1000         desc = ptlrpc_prep_bulk_imp(req, 1, BULK_GET_SOURCE, MDS_BULK_PORTAL);
1001         if (desc == NULL)
1002                 GOTO(out, rc = -ENOMEM);
1003
1004         /* NB req now owns desc and will free it when it gets freed. */
1005         ptlrpc_prep_bulk_page(desc, (struct page *)page, 0, offset);
1006         mdc_readdir_pack(req, 0, offset, fid, NULL);
1007
1008         ptlrpc_request_set_replen(req);
1009         rc = ptlrpc_queue_wait(req);
1010         if (rc)
1011                 GOTO(out, rc);
1012
1013         rc = sptlrpc_cli_unwrap_bulk_write(req, req->rq_bulk);
1014 out:
1015         ptlrpc_req_finished(req);
1016         return rc;
1017 }
1018 EXPORT_SYMBOL(mdc_sendpage);
1019 #endif
1020
1021 int mdc_readpage(struct obd_export *exp, struct md_op_data *op_data,
1022                  struct page **pages, struct ptlrpc_request **request)
1023 {
1024         struct ptlrpc_request   *req;
1025         struct ptlrpc_bulk_desc *desc;
1026         int                      i;
1027         cfs_waitq_t              waitq;
1028         int                      resends = 0;
1029         struct l_wait_info       lwi;
1030         int                      rc;
1031         ENTRY;
1032
1033         *request = NULL;
1034         cfs_waitq_init(&waitq);
1035
1036 restart_bulk:
1037         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_READPAGE);
1038         if (req == NULL)
1039                 RETURN(-ENOMEM);
1040
1041         mdc_set_capa_size(req, &RMF_CAPA1, op_data->op_capa1);
1042
1043         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_READPAGE);
1044         if (rc) {
1045                 ptlrpc_request_free(req);
1046                 RETURN(rc);
1047         }
1048
1049         req->rq_request_portal = MDS_READPAGE_PORTAL;
1050         ptlrpc_at_set_req_timeout(req);
1051
1052         desc = ptlrpc_prep_bulk_imp(req, op_data->op_npages, BULK_PUT_SINK,
1053                                     MDS_BULK_PORTAL);
1054         if (desc == NULL) {
1055                 ptlrpc_request_free(req);
1056                 RETURN(-ENOMEM);
1057         }
1058
1059         /* NB req now owns desc and will free it when it gets freed */
1060         for (i = 0; i < op_data->op_npages; i++)
1061                 ptlrpc_prep_bulk_page(desc, pages[i], 0, CFS_PAGE_SIZE);
1062
1063         mdc_readdir_pack(req, op_data->op_offset,
1064                          CFS_PAGE_SIZE * op_data->op_npages,
1065                          &op_data->op_fid1, op_data->op_capa1);
1066
1067         ptlrpc_request_set_replen(req);
1068         rc = ptlrpc_queue_wait(req);
1069         if (rc) {
1070                 ptlrpc_req_finished(req);
1071                 if (rc != -ETIMEDOUT)
1072                         RETURN(rc);
1073
1074                 resends++;
1075                 if (!client_should_resend(resends, &exp->exp_obd->u.cli)) {
1076                         CERROR("too many resend retries, returning error\n");
1077                         RETURN(-EIO);
1078                 }
1079                 lwi = LWI_TIMEOUT_INTR(cfs_time_seconds(resends), NULL, NULL, NULL);
1080                 l_wait_event(waitq, 0, &lwi);
1081
1082                 goto restart_bulk;
1083         }
1084
1085         rc = sptlrpc_cli_unwrap_bulk_read(req, req->rq_bulk,
1086                                           req->rq_bulk->bd_nob_transferred);
1087         if (rc < 0) {
1088                 ptlrpc_req_finished(req);
1089                 RETURN(rc);
1090         }
1091
1092         if (req->rq_bulk->bd_nob_transferred & ~LU_PAGE_MASK) {
1093                 CERROR("Unexpected # bytes transferred: %d (%ld expected)\n",
1094                         req->rq_bulk->bd_nob_transferred,
1095                         CFS_PAGE_SIZE * op_data->op_npages);
1096                 ptlrpc_req_finished(req);
1097                 RETURN(-EPROTO);
1098         }
1099
1100         *request = req;
1101         RETURN(0);
1102 }
1103
1104 static int mdc_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1105                       __u64 max_age, __u32 flags)
1106 {
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(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(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(obd, &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(struct obd_export *exp,
1725                        obd_count keylen, void *key,
1726                        obd_count vallen, void *val,
1727                        struct ptlrpc_request_set *set)
1728 {
1729         struct obd_import *imp = class_exp2cliimp(exp);
1730         int                rc = -EINVAL;
1731         ENTRY;
1732
1733         if (KEY_IS(KEY_READ_ONLY)) {
1734                 if (vallen != sizeof(int))
1735                         RETURN(-EINVAL);
1736
1737                 cfs_spin_lock(&imp->imp_lock);
1738                 if (*((int *)val)) {
1739                         imp->imp_connect_flags_orig |= OBD_CONNECT_RDONLY;
1740                         imp->imp_connect_data.ocd_connect_flags |= OBD_CONNECT_RDONLY;
1741                 } else {
1742                         imp->imp_connect_flags_orig &= ~OBD_CONNECT_RDONLY;
1743                         imp->imp_connect_data.ocd_connect_flags &= ~OBD_CONNECT_RDONLY;
1744                 }
1745                 cfs_spin_unlock(&imp->imp_lock);
1746
1747                 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
1748                                        keylen, key, vallen, val, set);
1749                 RETURN(rc);
1750         }
1751         if (KEY_IS(KEY_SPTLRPC_CONF)) {
1752                 sptlrpc_conf_client_adapt(exp->exp_obd);
1753                 RETURN(0);
1754         }
1755         if (KEY_IS(KEY_FLUSH_CTX)) {
1756                 sptlrpc_import_flush_my_ctx(imp);
1757                 RETURN(0);
1758         }
1759         if (KEY_IS(KEY_MDS_CONN)) {
1760                 /* mds-mds import */
1761                 cfs_spin_lock(&imp->imp_lock);
1762                 imp->imp_server_timeout = 1;
1763                 cfs_spin_unlock(&imp->imp_lock);
1764                 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
1765                 CDEBUG(D_OTHER, "%s: timeout / 2\n", exp->exp_obd->obd_name);
1766                 RETURN(0);
1767         }
1768         if (KEY_IS(KEY_CHANGELOG_CLEAR)) {
1769                 rc = do_set_info_async(imp, MDS_SET_INFO, LUSTRE_MDS_VERSION,
1770                                        keylen, key, vallen, val, set);
1771                 RETURN(rc);
1772         }
1773         if (KEY_IS(KEY_HSM_COPYTOOL_SEND)) {
1774                 rc = mdc_hsm_copytool_send(vallen, val);
1775                 RETURN(rc);
1776         }
1777
1778         RETURN(rc);
1779 }
1780
1781 int mdc_get_info(struct obd_export *exp, __u32 keylen, void *key,
1782                  __u32 *vallen, void *val, struct lov_stripe_md *lsm)
1783 {
1784         int rc = -EINVAL;
1785
1786         if (KEY_IS(KEY_MAX_EASIZE)) {
1787                 int mdsize, *max_easize;
1788
1789                 if (*vallen != sizeof(int))
1790                         RETURN(-EINVAL);
1791                 mdsize = *(int*)val;
1792                 if (mdsize > exp->exp_obd->u.cli.cl_max_mds_easize)
1793                         exp->exp_obd->u.cli.cl_max_mds_easize = mdsize;
1794                 max_easize = val;
1795                 *max_easize = exp->exp_obd->u.cli.cl_max_mds_easize;
1796                 RETURN(0);
1797         } else if (KEY_IS(KEY_CONN_DATA)) {
1798                 struct obd_import *imp = class_exp2cliimp(exp);
1799                 struct obd_connect_data *data = val;
1800
1801                 if (*vallen != sizeof(*data))
1802                         RETURN(-EINVAL);
1803
1804                 *data = imp->imp_connect_data;
1805                 RETURN(0);
1806         } else if (KEY_IS(KEY_TGT_COUNT)) {
1807                 *((int *)val) = 1;
1808                 RETURN(0);
1809         }
1810
1811         rc = mdc_get_info_rpc(exp, keylen, key, *vallen, val);
1812
1813         RETURN(rc);
1814 }
1815
1816 static int mdc_pin(struct obd_export *exp, const struct lu_fid *fid,
1817                    struct obd_capa *oc, struct obd_client_handle *handle,
1818                    int flags)
1819 {
1820         struct ptlrpc_request *req;
1821         struct mdt_body       *body;
1822         int                    rc;
1823         ENTRY;
1824
1825         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_PIN);
1826         if (req == NULL)
1827                 RETURN(-ENOMEM);
1828
1829         mdc_set_capa_size(req, &RMF_CAPA1, oc);
1830
1831         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_PIN);
1832         if (rc) {
1833                 ptlrpc_request_free(req);
1834                 RETURN(rc);
1835         }
1836
1837         mdc_pack_body(req, fid, oc, 0, 0, -1, flags);
1838
1839         ptlrpc_request_set_replen(req);
1840
1841         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1842         rc = ptlrpc_queue_wait(req);
1843         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1844         if (rc) {
1845                 CERROR("Pin failed: %d\n", rc);
1846                 GOTO(err_out, rc);
1847         }
1848
1849         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
1850         if (body == NULL)
1851                 GOTO(err_out, rc = -EPROTO);
1852
1853         handle->och_fh = body->handle;
1854         handle->och_magic = OBD_CLIENT_HANDLE_MAGIC;
1855
1856         handle->och_mod = obd_mod_alloc();
1857         if (handle->och_mod == NULL) {
1858                 DEBUG_REQ(D_ERROR, req, "can't allocate md_open_data");
1859                 GOTO(err_out, rc = -ENOMEM);
1860         }
1861         handle->och_mod->mod_open_req = req; /* will be dropped by unpin */
1862
1863         RETURN(0);
1864
1865 err_out:
1866         ptlrpc_req_finished(req);
1867         RETURN(rc);
1868 }
1869
1870 static int mdc_unpin(struct obd_export *exp, struct obd_client_handle *handle,
1871                      int flag)
1872 {
1873         struct ptlrpc_request *req;
1874         struct mdt_body       *body;
1875         int                    rc;
1876         ENTRY;
1877
1878         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_UNPIN,
1879                                         LUSTRE_MDS_VERSION, MDS_UNPIN);
1880         if (req == NULL)
1881                 RETURN(-ENOMEM);
1882
1883         body = req_capsule_client_get(&req->rq_pill, &RMF_MDT_BODY);
1884         body->handle = handle->och_fh;
1885         body->flags = flag;
1886
1887         ptlrpc_request_set_replen(req);
1888
1889         mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1890         rc = ptlrpc_queue_wait(req);
1891         mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL);
1892
1893         if (rc != 0)
1894                 CERROR("Unpin failed: %d\n", rc);
1895
1896         ptlrpc_req_finished(req);
1897         ptlrpc_req_finished(handle->och_mod->mod_open_req);
1898
1899         obd_mod_put(handle->och_mod);
1900         RETURN(rc);
1901 }
1902
1903 int mdc_sync(struct obd_export *exp, const struct lu_fid *fid,
1904              struct obd_capa *oc, struct ptlrpc_request **request)
1905 {
1906         struct ptlrpc_request *req;
1907         int                    rc;
1908         ENTRY;
1909
1910         *request = NULL;
1911         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_SYNC);
1912         if (req == NULL)
1913                 RETURN(-ENOMEM);
1914
1915         mdc_set_capa_size(req, &RMF_CAPA1, oc);
1916
1917         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_SYNC);
1918         if (rc) {
1919                 ptlrpc_request_free(req);
1920                 RETURN(rc);
1921         }
1922
1923         mdc_pack_body(req, fid, oc, 0, 0, -1, 0);
1924
1925         ptlrpc_request_set_replen(req);
1926
1927         rc = ptlrpc_queue_wait(req);
1928         if (rc)
1929                 ptlrpc_req_finished(req);
1930         else
1931                 *request = req;
1932         RETURN(rc);
1933 }
1934
1935 static int mdc_import_event(struct obd_device *obd, struct obd_import *imp,
1936                             enum obd_import_event event)
1937 {
1938         int rc = 0;
1939
1940         LASSERT(imp->imp_obd == obd);
1941
1942         switch (event) {
1943         case IMP_EVENT_DISCON: {
1944 #if 0
1945                 /* XXX Pass event up to OBDs stack. used only for FLD now */
1946                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_DISCON, NULL);
1947 #endif
1948                 break;
1949         }
1950         case IMP_EVENT_INACTIVE: {
1951                 struct client_obd *cli = &obd->u.cli;
1952                 /*
1953                  * Flush current sequence to make client obtain new one
1954                  * from server in case of disconnect/reconnect.
1955                  */
1956                 if (cli->cl_seq != NULL)
1957                         seq_client_flush(cli->cl_seq);
1958
1959                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_INACTIVE, NULL);
1960                 break;
1961         }
1962         case IMP_EVENT_INVALIDATE: {
1963                 struct ldlm_namespace *ns = obd->obd_namespace;
1964
1965                 ldlm_namespace_cleanup(ns, LDLM_FL_LOCAL_ONLY);
1966
1967                 break;
1968         }
1969         case IMP_EVENT_ACTIVE: {
1970                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_ACTIVE, NULL);
1971                 break;
1972         }
1973         case IMP_EVENT_OCD:
1974                 rc = obd_notify_observer(obd, obd, OBD_NOTIFY_OCD, NULL);
1975                 break;
1976         case IMP_EVENT_DEACTIVATE:
1977         case IMP_EVENT_ACTIVATE:
1978                 break;
1979         default:
1980                 CERROR("Unknown import event %x\n", event);
1981                 LBUG();
1982         }
1983         RETURN(rc);
1984 }
1985
1986 static int mdc_fid_init(struct obd_export *exp)
1987 {
1988         struct client_obd *cli = &exp->exp_obd->u.cli;
1989         char *prefix;
1990         int rc;
1991         ENTRY;
1992
1993         OBD_ALLOC_PTR(cli->cl_seq);
1994         if (cli->cl_seq == NULL)
1995                 RETURN(-ENOMEM);
1996
1997         OBD_ALLOC(prefix, MAX_OBD_NAME + 5);
1998         if (prefix == NULL)
1999                 GOTO(out_free_seq, rc = -ENOMEM);
2000
2001         snprintf(prefix, MAX_OBD_NAME + 5, "srv-%s",
2002                  exp->exp_obd->obd_name);
2003
2004         /* Init client side sequence-manager */
2005         rc = seq_client_init(cli->cl_seq, exp,
2006                              LUSTRE_SEQ_METADATA,
2007                              prefix, NULL);
2008         OBD_FREE(prefix, MAX_OBD_NAME + 5);
2009         if (rc)
2010                 GOTO(out_free_seq, rc);
2011
2012         RETURN(rc);
2013 out_free_seq:
2014         OBD_FREE_PTR(cli->cl_seq);
2015         cli->cl_seq = NULL;
2016         return rc;
2017 }
2018
2019 static int mdc_fid_fini(struct obd_export *exp)
2020 {
2021         struct client_obd *cli = &exp->exp_obd->u.cli;
2022         ENTRY;
2023
2024         if (cli->cl_seq != NULL) {
2025                 seq_client_fini(cli->cl_seq);
2026                 OBD_FREE_PTR(cli->cl_seq);
2027                 cli->cl_seq = NULL;
2028         }
2029
2030         RETURN(0);
2031 }
2032
2033 int mdc_fid_alloc(struct obd_export *exp, struct lu_fid *fid,
2034                   struct md_op_data *op_data)
2035 {
2036         struct client_obd *cli = &exp->exp_obd->u.cli;
2037         struct lu_client_seq *seq = cli->cl_seq;
2038         ENTRY;
2039         RETURN(seq_client_alloc_fid(NULL, seq, fid));
2040 }
2041
2042 /* XXX This method is used only to clear current fid seq
2043  * once fld/mds insert failed */
2044 static int mdc_fid_delete(struct obd_export *exp, const struct lu_fid *fid)
2045 {
2046         struct client_obd *cli = &exp->exp_obd->u.cli;
2047
2048         seq_client_flush(cli->cl_seq);
2049         return 0;
2050 }
2051
2052 struct obd_uuid *mdc_get_uuid(struct obd_export *exp) {
2053         struct client_obd *cli = &exp->exp_obd->u.cli;
2054         return &cli->cl_target_uuid;
2055 }
2056
2057 /**
2058  * Determine whether the lock can be canceled before replaying it during
2059  * recovery, non zero value will be return if the lock can be canceled,
2060  * or zero returned for not
2061  */
2062 static int mdc_cancel_for_recovery(struct ldlm_lock *lock)
2063 {
2064         if (lock->l_resource->lr_type != LDLM_IBITS)
2065                 RETURN(0);
2066
2067         /* FIXME: if we ever get into a situation where there are too many
2068          * opened files with open locks on a single node, then we really
2069          * should replay these open locks to reget it */
2070         if (lock->l_policy_data.l_inodebits.bits & MDS_INODELOCK_OPEN)
2071                 RETURN(0);
2072
2073         RETURN(1);
2074 }
2075
2076 static int mdc_setup(struct obd_device *obd, struct lustre_cfg *cfg)
2077 {
2078         struct client_obd *cli = &obd->u.cli;
2079         struct lprocfs_static_vars lvars = { 0 };
2080         int rc;
2081         ENTRY;
2082
2083         OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2084         if (!cli->cl_rpc_lock)
2085                 RETURN(-ENOMEM);
2086         mdc_init_rpc_lock(cli->cl_rpc_lock);
2087
2088         ptlrpcd_addref();
2089
2090         OBD_ALLOC(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2091         if (!cli->cl_close_lock)
2092                 GOTO(err_rpc_lock, rc = -ENOMEM);
2093         mdc_init_rpc_lock(cli->cl_close_lock);
2094
2095         rc = client_obd_setup(obd, cfg);
2096         if (rc)
2097                 GOTO(err_close_lock, rc);
2098         lprocfs_mdc_init_vars(&lvars);
2099         lprocfs_obd_setup(obd, lvars.obd_vars);
2100         sptlrpc_lprocfs_cliobd_attach(obd);
2101         ptlrpc_lprocfs_register_obd(obd);
2102
2103         ns_register_cancel(obd->obd_namespace, mdc_cancel_for_recovery);
2104
2105         rc = obd_llog_init(obd, &obd->obd_olg, obd, NULL);
2106         if (rc) {
2107                 mdc_cleanup(obd);
2108                 CERROR("failed to setup llogging subsystems\n");
2109         }
2110
2111         RETURN(rc);
2112
2113 err_close_lock:
2114         OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2115 err_rpc_lock:
2116         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2117         ptlrpcd_decref();
2118         RETURN(rc);
2119 }
2120
2121 /* Initialize the default and maximum LOV EA and cookie sizes.  This allows
2122  * us to make MDS RPCs with large enough reply buffers to hold the
2123  * maximum-sized (= maximum striped) EA and cookie without having to
2124  * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
2125 static int mdc_init_ea_size(struct obd_export *exp, int easize,
2126                      int def_easize, int cookiesize)
2127 {
2128         struct obd_device *obd = exp->exp_obd;
2129         struct client_obd *cli = &obd->u.cli;
2130         ENTRY;
2131
2132         if (cli->cl_max_mds_easize < easize)
2133                 cli->cl_max_mds_easize = easize;
2134
2135         if (cli->cl_default_mds_easize < def_easize)
2136                 cli->cl_default_mds_easize = def_easize;
2137
2138         if (cli->cl_max_mds_cookiesize < cookiesize)
2139                 cli->cl_max_mds_cookiesize = cookiesize;
2140
2141         RETURN(0);
2142 }
2143
2144 static int mdc_precleanup(struct obd_device *obd, enum obd_cleanup_stage stage)
2145 {
2146         int rc = 0;
2147         ENTRY;
2148
2149         switch (stage) {
2150         case OBD_CLEANUP_EARLY:
2151                 break;
2152         case OBD_CLEANUP_EXPORTS:
2153                 /* Failsafe, ok if racy */
2154                 if (obd->obd_type->typ_refcnt <= 1)
2155                         libcfs_kkuc_group_rem(0, KUC_GRP_HSM);
2156
2157                 obd_cleanup_client_import(obd);
2158                 ptlrpc_lprocfs_unregister_obd(obd);
2159                 lprocfs_obd_cleanup(obd);
2160
2161                 rc = obd_llog_finish(obd, 0);
2162                 if (rc != 0)
2163                         CERROR("failed to cleanup llogging subsystems\n");
2164                 break;
2165         }
2166         RETURN(rc);
2167 }
2168
2169 static int mdc_cleanup(struct obd_device *obd)
2170 {
2171         struct client_obd *cli = &obd->u.cli;
2172
2173         OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
2174         OBD_FREE(cli->cl_close_lock, sizeof (*cli->cl_close_lock));
2175
2176         ptlrpcd_decref();
2177
2178         return client_obd_cleanup(obd);
2179 }
2180
2181
2182 static int mdc_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
2183                          struct obd_device *tgt, int *index)
2184 {
2185         struct llog_ctxt *ctxt;
2186         int rc;
2187         ENTRY;
2188
2189         LASSERT(olg == &obd->obd_olg);
2190
2191         rc = llog_setup(obd, olg, LLOG_LOVEA_REPL_CTXT, tgt, 0, NULL,
2192                         &llog_client_ops);
2193         if (rc)
2194                 RETURN(rc);
2195
2196         ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
2197         llog_initiator_connect(ctxt);
2198         llog_ctxt_put(ctxt);
2199
2200         rc = llog_setup(obd, olg, LLOG_CHANGELOG_REPL_CTXT, tgt, 0, NULL,
2201                         &llog_client_ops);
2202         if (rc == 0) {
2203                 ctxt = llog_group_get_ctxt(olg, LLOG_CHANGELOG_REPL_CTXT);
2204                 llog_initiator_connect(ctxt);
2205                 llog_ctxt_put(ctxt);
2206         }
2207
2208         RETURN(rc);
2209 }
2210
2211 static int mdc_llog_finish(struct obd_device *obd, int count)
2212 {
2213         struct llog_ctxt *ctxt;
2214         int rc = 0;
2215         ENTRY;
2216
2217         ctxt = llog_get_context(obd, LLOG_LOVEA_REPL_CTXT);
2218         if (ctxt)
2219                 rc = llog_cleanup(ctxt);
2220
2221         ctxt = llog_get_context(obd, LLOG_CHANGELOG_REPL_CTXT);
2222         if (ctxt)
2223                 rc = llog_cleanup(ctxt);
2224
2225         RETURN(rc);
2226 }
2227
2228 static int mdc_process_config(struct obd_device *obd, obd_count len, void *buf)
2229 {
2230         struct lustre_cfg *lcfg = buf;
2231         struct lprocfs_static_vars lvars = { 0 };
2232         int rc = 0;
2233
2234         lprocfs_mdc_init_vars(&lvars);
2235         switch (lcfg->lcfg_command) {
2236         default:
2237                 rc = class_process_proc_param(PARAM_MDC, lvars.obd_vars,
2238                                               lcfg, obd);
2239                 if (rc > 0)
2240                         rc = 0;
2241                 break;
2242         }
2243         return(rc);
2244 }
2245
2246
2247 /* get remote permission for current user on fid */
2248 int mdc_get_remote_perm(struct obd_export *exp, const struct lu_fid *fid,
2249                         struct obd_capa *oc, __u32 suppgid,
2250                         struct ptlrpc_request **request)
2251 {
2252         struct ptlrpc_request  *req;
2253         int                    rc;
2254         ENTRY;
2255
2256         LASSERT(client_is_remote(exp));
2257
2258         *request = NULL;
2259         req = ptlrpc_request_alloc(class_exp2cliimp(exp), &RQF_MDS_GETATTR);
2260         if (req == NULL)
2261                 RETURN(-ENOMEM);
2262
2263         mdc_set_capa_size(req, &RMF_CAPA1, oc);
2264
2265         rc = ptlrpc_request_pack(req, LUSTRE_MDS_VERSION, MDS_GETATTR);
2266         if (rc) {
2267                 ptlrpc_request_free(req);
2268                 RETURN(rc);
2269         }
2270
2271         mdc_pack_body(req, fid, oc, OBD_MD_FLRMTPERM, 0, suppgid, 0);
2272
2273         req_capsule_set_size(&req->rq_pill, &RMF_ACL, RCL_SERVER,
2274                              sizeof(struct mdt_remote_perm));
2275
2276         ptlrpc_request_set_replen(req);
2277
2278         rc = ptlrpc_queue_wait(req);
2279         if (rc)
2280                 ptlrpc_req_finished(req);
2281         else
2282                 *request = req;
2283         RETURN(rc);
2284 }
2285
2286 static int mdc_interpret_renew_capa(const struct lu_env *env,
2287                                     struct ptlrpc_request *req, void *args,
2288                                     int status)
2289 {
2290         struct mdc_renew_capa_args *ra = args;
2291         struct mdt_body *body = NULL;
2292         struct lustre_capa *capa;
2293         ENTRY;
2294
2295         if (status)
2296                 GOTO(out, capa = ERR_PTR(status));
2297
2298         body = req_capsule_server_get(&req->rq_pill, &RMF_MDT_BODY);
2299         if (body == NULL)
2300                 GOTO(out, capa = ERR_PTR(-EFAULT));
2301
2302         if ((body->valid & OBD_MD_FLOSSCAPA) == 0)
2303                 GOTO(out, capa = ERR_PTR(-ENOENT));
2304
2305         capa = req_capsule_server_get(&req->rq_pill, &RMF_CAPA2);
2306         if (!capa)
2307                 GOTO(out, capa = ERR_PTR(-EFAULT));
2308         EXIT;
2309 out:
2310         ra->ra_cb(ra->ra_oc, capa);
2311         return 0;
2312 }
2313
2314 static int mdc_renew_capa(struct obd_export *exp, struct obd_capa *oc,
2315                           renew_capa_cb_t cb)
2316 {
2317         struct ptlrpc_request *req;
2318         struct mdc_renew_capa_args *ra;
2319         ENTRY;
2320
2321         req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_MDS_GETATTR,
2322                                         LUSTRE_MDS_VERSION, MDS_GETATTR);
2323         if (req == NULL)
2324                 RETURN(-ENOMEM);
2325
2326         /* NB, OBD_MD_FLOSSCAPA is set here, but it doesn't necessarily mean the
2327          * capa to renew is oss capa.
2328          */
2329         mdc_pack_body(req, &oc->c_capa.lc_fid, oc, OBD_MD_FLOSSCAPA, 0, -1, 0);
2330         ptlrpc_request_set_replen(req);
2331
2332         CLASSERT(sizeof(*ra) <= sizeof(req->rq_async_args));
2333         ra = ptlrpc_req_async_args(req);
2334         ra->ra_oc = oc;
2335         ra->ra_cb = cb;
2336         req->rq_interpret_reply = mdc_interpret_renew_capa;
2337         ptlrpcd_add_req(req, PDL_POLICY_LOCAL, -1);
2338         RETURN(0);
2339 }
2340
2341 static int mdc_connect(const struct lu_env *env,
2342                        struct obd_export **exp,
2343                        struct obd_device *obd, struct obd_uuid *cluuid,
2344                        struct obd_connect_data *data,
2345                        void *localdata)
2346 {
2347         struct obd_import *imp = obd->u.cli.cl_import;
2348
2349         /* mds-mds import features */
2350         if (data && (data->ocd_connect_flags & OBD_CONNECT_MDS_MDS)) {
2351                 cfs_spin_lock(&imp->imp_lock);
2352                 imp->imp_server_timeout = 1;
2353                 cfs_spin_unlock(&imp->imp_lock);
2354                 imp->imp_client->cli_request_portal = MDS_MDS_PORTAL;
2355                 CDEBUG(D_OTHER, "%s: Set 'mds' portal and timeout\n",
2356                        obd->obd_name);
2357         }
2358
2359         return client_connect_import(env, exp, obd, cluuid, data, NULL);
2360 }
2361
2362 struct obd_ops mdc_obd_ops = {
2363         .o_owner            = THIS_MODULE,
2364         .o_setup            = mdc_setup,
2365         .o_precleanup       = mdc_precleanup,
2366         .o_cleanup          = mdc_cleanup,
2367         .o_add_conn         = client_import_add_conn,
2368         .o_del_conn         = client_import_del_conn,
2369         .o_connect          = mdc_connect,
2370         .o_disconnect       = client_disconnect_export,
2371         .o_iocontrol        = mdc_iocontrol,
2372         .o_set_info_async   = mdc_set_info_async,
2373         .o_statfs           = mdc_statfs,
2374         .o_pin              = mdc_pin,
2375         .o_unpin            = mdc_unpin,
2376         .o_fid_init         = mdc_fid_init,
2377         .o_fid_fini         = mdc_fid_fini,
2378         .o_fid_alloc        = mdc_fid_alloc,
2379         .o_fid_delete       = mdc_fid_delete,
2380         .o_import_event     = mdc_import_event,
2381         .o_llog_init        = mdc_llog_init,
2382         .o_llog_finish      = mdc_llog_finish,
2383         .o_get_info         = mdc_get_info,
2384         .o_process_config   = mdc_process_config,
2385         .o_get_uuid         = mdc_get_uuid,
2386         .o_quotactl         = mdc_quotactl,
2387         .o_quotacheck       = mdc_quotacheck
2388 };
2389
2390 struct md_ops mdc_md_ops = {
2391         .m_getstatus        = mdc_getstatus,
2392         .m_change_cbdata    = mdc_change_cbdata,
2393         .m_find_cbdata      = mdc_find_cbdata,
2394         .m_close            = mdc_close,
2395         .m_create           = mdc_create,
2396         .m_done_writing     = mdc_done_writing,
2397         .m_enqueue          = mdc_enqueue,
2398         .m_getattr          = mdc_getattr,
2399         .m_getattr_name     = mdc_getattr_name,
2400         .m_intent_lock      = mdc_intent_lock,
2401         .m_link             = mdc_link,
2402         .m_is_subdir        = mdc_is_subdir,
2403         .m_rename           = mdc_rename,
2404         .m_setattr          = mdc_setattr,
2405         .m_setxattr         = mdc_setxattr,
2406         .m_getxattr         = mdc_getxattr,
2407         .m_sync             = mdc_sync,
2408         .m_readpage         = mdc_readpage,
2409         .m_unlink           = mdc_unlink,
2410         .m_cancel_unused    = mdc_cancel_unused,
2411         .m_init_ea_size     = mdc_init_ea_size,
2412         .m_set_lock_data    = mdc_set_lock_data,
2413         .m_lock_match       = mdc_lock_match,
2414         .m_get_lustre_md    = mdc_get_lustre_md,
2415         .m_free_lustre_md   = mdc_free_lustre_md,
2416         .m_set_open_replay_data = mdc_set_open_replay_data,
2417         .m_clear_open_replay_data = mdc_clear_open_replay_data,
2418         .m_renew_capa       = mdc_renew_capa,
2419         .m_unpack_capa      = mdc_unpack_capa,
2420         .m_get_remote_perm  = mdc_get_remote_perm,
2421         .m_intent_getattr_async = mdc_intent_getattr_async,
2422         .m_revalidate_lock      = mdc_revalidate_lock
2423 };
2424
2425 int __init mdc_init(void)
2426 {
2427         int rc;
2428         struct lprocfs_static_vars lvars = { 0 };
2429         lprocfs_mdc_init_vars(&lvars);
2430
2431         rc = class_register_type(&mdc_obd_ops, &mdc_md_ops, lvars.module_vars,
2432                                  LUSTRE_MDC_NAME, NULL);
2433         RETURN(rc);
2434 }
2435
2436 #ifdef __KERNEL__
2437 static void /*__exit*/ mdc_exit(void)
2438 {
2439         class_unregister_type(LUSTRE_MDC_NAME);
2440 }
2441
2442 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
2443 MODULE_DESCRIPTION("Lustre Metadata Client");
2444 MODULE_LICENSE("GPL");
2445
2446 module_init(mdc_init);
2447 module_exit(mdc_exit);
2448 #endif