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