Whamcloud - gitweb
- unland b_fid to HEAD
[fs/lustre-release.git] / lustre / lmv / lmv_obd.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2002, 2003 Cluster File Systems, Inc.
5  *
6  *   This file is part of Lustre, http://www.lustre.org.
7  *
8  *   Lustre is free software; you can redistribute it and/or
9  *   modify it under the terms of version 2 of the GNU General Public
10  *   License as published by the Free Software Foundation.
11  *
12  *   Lustre is distributed in the hope that it will be useful,
13  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *   GNU General Public License for more details.
16  *
17  *   You should have received a copy of the GNU General Public License
18  *   along with Lustre; if not, write to the Free Software
19  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21
22 #ifndef EXPORT_SYMTAB
23 # define EXPORT_SYMTAB
24 #endif
25 #define DEBUG_SUBSYSTEM S_LMV
26 #ifdef __KERNEL__
27 #include <linux/slab.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <linux/pagemap.h>
32 #include <asm/div64.h>
33 #include <linux/seq_file.h>
34 #else
35 #include <liblustre.h>
36 #endif
37 #include <linux/ext2_fs.h>
38
39 #include <linux/obd_support.h>
40 #include <linux/lustre_lib.h>
41 #include <linux/lustre_net.h>
42 #include <linux/lustre_idl.h>
43 #include <linux/lustre_dlm.h>
44 #include <linux/lustre_mds.h>
45 #include <linux/obd_class.h>
46 #include <linux/obd_ost.h>
47 #include <linux/lprocfs_status.h>
48 #include <linux/lustre_fsfilt.h>
49 #include <linux/obd_lmv.h>
50 #include "lmv_internal.h"
51
52 /* Error codes:
53  *
54  *  -EINVAL  : UUID can't be found in the LMV's target list
55  *  -ENOTCONN: The UUID is found, but the target connection is bad (!)
56  *  -EBADF   : The UUID is found, but the OBD of the wrong type (!)
57  */
58 static int lmv_set_mdc_active(struct lmv_obd *lmv, struct obd_uuid *uuid,
59                               int activate)
60 {
61         struct obd_device *obd;
62         struct lmv_tgt_desc *tgt;
63         int i, rc = 0;
64         ENTRY;
65
66         CDEBUG(D_INFO, "Searching in lmv %p for uuid %s (activate=%d)\n",
67                lmv, uuid->uuid, activate);
68
69         spin_lock(&lmv->lmv_lock);
70         for (i = 0, tgt = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgt++) {
71                 if (tgt->ltd_exp == NULL)
72                         continue;
73
74                 CDEBUG(D_INFO, "lmv idx %d is %s conn "LPX64"\n",
75                        i, tgt->uuid.uuid, tgt->ltd_exp->exp_handle.h_cookie);
76                 if (strncmp(uuid->uuid, tgt->uuid.uuid, sizeof uuid->uuid) == 0)
77                         break;
78         }
79
80         if (i == lmv->desc.ld_tgt_count)
81                 GOTO(out, rc = -EINVAL);
82
83         obd = class_exp2obd(tgt->ltd_exp);
84         if (obd == NULL)
85                 GOTO(out, rc = -ENOTCONN);
86
87         CDEBUG(D_INFO, "Found OBD %s=%s device %d (%p) type %s at LMV idx %d\n",
88                obd->obd_name, obd->obd_uuid.uuid, obd->obd_minor, obd,
89                obd->obd_type->typ_name, i);
90         LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0);
91
92         if (tgt->active == activate) {
93                 CDEBUG(D_INFO, "OBD %p already %sactive!\n", obd,
94                        activate ? "" : "in");
95                 GOTO(out, rc);
96         }
97
98         CDEBUG(D_INFO, "Marking OBD %p %sactive\n", obd, activate ? "" : "in");
99
100         tgt->active = activate;
101         if (activate)
102                 lmv->desc.ld_active_tgt_count++;
103         else
104                 lmv->desc.ld_active_tgt_count--;
105
106         EXIT;
107  out:
108         spin_unlock(&lmv->lmv_lock);
109         return rc;
110 }
111
112 static int lmv_notify(struct obd_device *obd, struct obd_device *watched,
113                       int active, void *data)
114 {
115         int rc;
116         struct obd_uuid *uuid;
117
118         if (strcmp(watched->obd_type->typ_name, LUSTRE_MDC_NAME)) {
119                 CERROR("unexpected notification of %s %s!\n",
120                        watched->obd_type->typ_name,
121                        watched->obd_name);
122                 return -EINVAL;
123         }
124         uuid = &watched->u.cli.cl_import->imp_target_uuid;
125
126         /* Set MDC as active before notifying the observer, so the
127          * observer can use the MDC normally.  
128          */
129         rc = lmv_set_mdc_active(&obd->u.lmv, uuid, active);
130         if (rc) {
131                 CERROR("%sactivation of %s failed: %d\n",
132                        active ? "" : "de", uuid->uuid, rc);
133                 RETURN(rc);
134         }
135
136         if (obd->obd_observer)
137                 /* Pass the notification up the chain. */
138                 rc = obd_notify(obd->obd_observer, watched, active, data);
139
140         RETURN(rc);
141 }
142
143 int lmv_attach(struct obd_device *dev, obd_count len, void *data)
144 {
145         struct lprocfs_static_vars lvars;
146         int rc;
147         ENTRY;
148
149         lprocfs_init_vars(lmv, &lvars);
150         rc = lprocfs_obd_attach(dev, lvars.obd_vars);
151         if (rc == 0) {
152 #ifdef __KERNEL__
153                 struct proc_dir_entry *entry;
154                 
155                 entry = create_proc_entry("target_obd_status", 0444, 
156                                            dev->obd_proc_entry);
157                 if (entry == NULL)
158                         RETURN(-ENOMEM);
159                 entry->proc_fops = &lmv_proc_target_fops; 
160                 entry->data = dev;
161 #endif
162        }
163         RETURN (rc);
164 }
165
166 int lmv_detach(struct obd_device *dev)
167 {
168         return lprocfs_obd_detach(dev);
169 }
170
171 /* This is fake connect function. Its purpose is to initialize lmv and 
172  * say caller that everything is okay. Real connection will be performed
173  * later. */
174 static int lmv_connect(struct lustre_handle *conn, struct obd_device *obd,
175                        struct obd_uuid *cluuid, unsigned long connect_flags)
176 {
177         struct lmv_obd *lmv = &obd->u.lmv;
178         struct obd_export *exp;
179         struct proc_dir_entry *lmv_proc_dir;
180         int rc;
181         ENTRY;
182
183         rc = class_connect(conn, obd, cluuid);
184         if (rc) {
185                 CERROR("class_connection() returned %d\n", rc);
186                 RETURN(rc);
187         }
188
189         exp = class_conn2export(conn);
190         /* We don't want to actually do the underlying connections more than
191          * once, so keep track. */
192         lmv->refcount++;
193         if (lmv->refcount > 1) {
194                 class_export_put(exp);
195                 RETURN(0);
196         }
197
198         lmv->cluuid = *cluuid;
199         lmv->connect_flags = connect_flags;
200         lmv->connected = 0;
201         lmv->exp = exp;
202         sema_init(&lmv->init_sem, 1);
203
204         lmv_proc_dir = lprocfs_register("target_obds", obd->obd_proc_entry,
205                                         NULL, NULL);
206         if (IS_ERR(lmv_proc_dir)) {
207                 CERROR("could not register /proc/fs/lustre/%s/%s/target_obds.",
208                        obd->obd_type->typ_name, obd->obd_name);
209                 lmv_proc_dir = NULL;
210         }
211
212
213         RETURN(0);
214 }
215
216 void lmv_set_timeouts(struct obd_device *obd)
217 {
218         struct lmv_tgt_desc *tgts;
219         struct lmv_obd *lmv;
220         int i;
221
222         lmv = &obd->u.lmv;
223         if (lmv->server_timeout == 0)
224                 return;
225
226         if (lmv->connected == 0)
227                 return;
228
229         for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
230                 if (tgts->ltd_exp == NULL)
231                         continue;
232                 obd_set_info(tgts->ltd_exp, strlen("inter_mds"),
233                              "inter_mds", 0, NULL);
234         }
235 }
236
237 /* Performs a check if passed obd is connected. If no - connect it. */
238 #define MAX_STRING_SIZE 128
239 int lmv_check_connect(struct obd_device *obd)
240 {
241         struct lmv_obd *lmv = &obd->u.lmv;
242         struct obd_uuid *cluuid;
243         struct lmv_tgt_desc *tgts;
244         struct proc_dir_entry *lmv_proc_dir;
245         struct obd_export *exp;
246         int rc, rc2, i;
247
248         if (lmv->connected)
249                 return 0;
250
251         down(&lmv->init_sem);
252         if (lmv->connected) {
253                 up(&lmv->init_sem);
254                 return 0;
255         }
256
257         cluuid = &lmv->cluuid;
258         exp = lmv->exp;
259         
260         CDEBUG(D_OTHER, "time to connect %s to %s\n",
261                cluuid->uuid, obd->obd_name);
262
263         for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
264                 struct obd_device *tgt_obd;
265                 struct obd_uuid lmv_osc_uuid = { "LMV_OSC_UUID" };
266                 struct lustre_handle conn = {0, };
267
268                 LASSERT(tgts != NULL);
269
270                 tgt_obd = class_find_client_obd(&tgts->uuid, LUSTRE_MDC_NAME, 
271                                                 &obd->obd_uuid);
272                 if (!tgt_obd) {
273                         CERROR("Target %s not attached\n", tgts->uuid.uuid);
274                         GOTO(out_disc, rc = -EINVAL);
275                 }
276
277                 /* for MDS: don't connect to yourself */
278                 if (obd_uuid_equals(&tgts->uuid, cluuid)) {
279                         CDEBUG(D_OTHER, "don't connect back to %s\n",
280                                cluuid->uuid);
281                         tgts->ltd_exp = NULL;
282                         continue;
283                 }
284
285                 CDEBUG(D_OTHER, "connect to %s(%s) - %s, %s FOR %s\n",
286                         tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
287                         tgts->uuid.uuid, obd->obd_uuid.uuid,
288                         cluuid->uuid);
289
290                 if (!tgt_obd->obd_set_up) {
291                         CERROR("Target %s not set up\n", tgts->uuid.uuid);
292                         GOTO(out_disc, rc = -EINVAL);
293                 }
294
295                 rc = obd_connect(&conn, tgt_obd, &lmv_osc_uuid,
296                                  lmv->connect_flags);
297                 if (rc) {
298                         CERROR("Target %s connect error %d\n",
299                                 tgts->uuid.uuid, rc);
300                         GOTO(out_disc, rc);
301                 }
302                 tgts->ltd_exp = class_conn2export(&conn);
303
304                 obd_init_ea_size(tgts->ltd_exp, lmv->max_easize,
305                                  lmv->max_cookiesize);
306
307                 rc = obd_register_observer(tgt_obd, obd);
308                 if (rc) {
309                         CERROR("Target %s register_observer error %d\n",
310                                tgts->uuid.uuid, rc);
311                         obd_disconnect(tgts->ltd_exp, 0);
312                         GOTO(out_disc, rc);
313                 }
314
315                 lmv->desc.ld_active_tgt_count++;
316                 tgts->active = 1;
317
318                 CDEBUG(D_OTHER, "connected to %s(%s) successfully (%d)\n",
319                         tgt_obd->obd_name, tgt_obd->obd_uuid.uuid,
320                         atomic_read(&obd->obd_refcount));
321
322                 lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
323                 if (lmv_proc_dir) {
324                         struct obd_device *mdc_obd = class_conn2obd(&conn);
325                         struct proc_dir_entry *mdc_symlink;
326                         char name[MAX_STRING_SIZE + 1];
327
328                         LASSERT(mdc_obd != NULL);
329                         LASSERT(mdc_obd->obd_type != NULL);
330                         LASSERT(mdc_obd->obd_type->typ_name != NULL);
331                         name[MAX_STRING_SIZE] = '\0';
332                         snprintf(name, MAX_STRING_SIZE, "../../../%s/%s",
333                                  mdc_obd->obd_type->typ_name,
334                                  mdc_obd->obd_name);
335                         mdc_symlink = proc_symlink(mdc_obd->obd_name,
336                                                    lmv_proc_dir, name);
337                         if (mdc_symlink == NULL) {
338                                 CERROR("could not register LMV target "
339                                        "/proc/fs/lustre/%s/%s/target_obds/%s.",
340                                        obd->obd_type->typ_name, obd->obd_name,
341                                        mdc_obd->obd_name);
342                                 lprocfs_remove(lmv_proc_dir);
343                                 lmv_proc_dir = NULL;
344                         }
345                 }
346         }
347
348         lmv_set_timeouts(obd);
349         class_export_put(exp);
350         lmv->connected = 1;
351         up(&lmv->init_sem);
352         return 0;
353
354  out_disc:
355         while (i-- > 0) {
356                 struct obd_uuid uuid;
357                 --tgts;
358                 --lmv->desc.ld_active_tgt_count;
359                 tgts->active = 0;
360                 /* save for CERROR below; (we know it's terminated) */
361                 uuid = tgts->uuid;
362                 rc2 = obd_disconnect(tgts->ltd_exp, 0);
363                 if (rc2)
364                         CERROR("error: LMV target %s disconnect on MDT idx %d: "
365                                "error %d\n", uuid.uuid, i, rc2);
366         }
367         class_disconnect(exp, 0);
368         up(&lmv->init_sem);
369         RETURN (rc);
370 }
371
372 static int lmv_disconnect(struct obd_export *exp, int flags)
373 {
374         struct obd_device *obd = class_exp2obd(exp);
375         struct lmv_obd *lmv = &obd->u.lmv;
376         struct proc_dir_entry *lmv_proc_dir;
377         int rc, i;
378         ENTRY;
379
380         if (!lmv->tgts)
381                 goto out_local;
382
383         /* Only disconnect the underlying layers on the final disconnect. */
384         lmv->refcount--;
385         if (lmv->refcount != 0)
386                 goto out_local;
387
388         lmv_proc_dir = lprocfs_srch(obd->obd_proc_entry, "target_obds");
389
390         for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
391                 struct obd_device *mdc_obd; 
392                 
393                 if (lmv->tgts[i].ltd_exp == NULL)
394                         continue;
395
396                 mdc_obd = class_exp2obd(lmv->tgts[i].ltd_exp);
397                 if (lmv_proc_dir) {
398                         struct proc_dir_entry *mdc_symlink;
399
400                         mdc_symlink = lprocfs_srch(lmv_proc_dir, mdc_obd->obd_name);
401                         if (mdc_symlink) {
402                                 lprocfs_remove(mdc_symlink);
403                         } else {
404                                 CERROR("/proc/fs/lustre/%s/%s/target_obds/%s missing\n",
405                                        obd->obd_type->typ_name, obd->obd_name,
406                                        mdc_obd->obd_name);
407                         }
408                 }
409                 if (obd->obd_no_recov) {
410                         /* Pass it on to our clients.
411                          * XXX This should be an argument to disconnect,
412                          * XXX not a back-door flag on the OBD.  Ah well.
413                          */
414                         struct obd_device *mdc_obd;
415                         mdc_obd = class_exp2obd(lmv->tgts[i].ltd_exp);
416                         if (mdc_obd)
417                                 mdc_obd->obd_no_recov = 1;
418                 }
419                 CDEBUG(D_OTHER, "disconnected from %s(%s) successfully\n",
420                         lmv->tgts[i].ltd_exp->exp_obd->obd_name,
421                         lmv->tgts[i].ltd_exp->exp_obd->obd_uuid.uuid);
422
423                 obd_register_observer(lmv->tgts[i].ltd_exp->exp_obd, NULL);
424
425                 rc = obd_disconnect(lmv->tgts[i].ltd_exp, flags);
426                 if (rc) {
427                         if (lmv->tgts[i].active) {
428                                 CERROR("Target %s disconnect error %d\n",
429                                        lmv->tgts[i].uuid.uuid, rc);
430                         }
431                         rc = 0;
432                 }
433                 if (lmv->tgts[i].active) {
434                         lmv->desc.ld_active_tgt_count--;
435                         lmv->tgts[i].active = 0;
436                 }
437                 lmv->tgts[i].ltd_exp = NULL;
438         }
439
440         if (lmv_proc_dir) {
441                 lprocfs_remove(lmv_proc_dir);
442         } else {
443                 CERROR("/proc/fs/lustre/%s/%s/target_obds missing\n",
444                        obd->obd_type->typ_name, obd->obd_name);
445         }
446
447
448 out_local:
449         /* this is the case when no real connection is established by
450          * lmv_check_connect(). */
451         if (!lmv->connected)
452                 class_export_put(exp);
453         rc = class_disconnect(exp, 0);
454         if (lmv->refcount == 0)
455                 lmv->connected = 0;
456         RETURN(rc);
457 }
458
459 static int lmv_iocontrol(unsigned int cmd, struct obd_export *exp,
460                          int len, void *karg, void *uarg)
461 {
462         struct obd_device *obddev = class_exp2obd(exp);
463         struct lmv_obd *lmv = &obddev->u.lmv;
464         int i, rc = 0, set = 0;
465
466         ENTRY;
467
468         if (lmv->desc.ld_tgt_count == 0)
469                 RETURN(-ENOTTY);
470         
471         for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
472                 int err;
473
474                 if (lmv->tgts[i].ltd_exp == NULL) {
475                         CWARN("%s: NULL export for %d\n", obddev->obd_name, i);
476                         continue;
477                 }
478
479                 err = obd_iocontrol(cmd, lmv->tgts[i].ltd_exp, len, karg, uarg);
480                 if (err) {
481                         if (lmv->tgts[i].active) {
482                                 CERROR("error: iocontrol MDC %s on MDT"
483                                        "idx %d: err = %d\n",
484                                        lmv->tgts[i].uuid.uuid, i, err);
485                                 if (!rc)
486                                         rc = err;
487                         }
488                 } else
489                         set = 1;
490         }
491         if (!set && !rc)
492                 rc = -EIO;
493
494         RETURN(rc);
495 }
496
497 static int lmv_setup(struct obd_device *obd, obd_count len, void *buf)
498 {
499         int i, rc = 0;
500         struct lmv_desc *desc;
501         struct obd_uuid *uuids;
502         struct lmv_tgt_desc *tgts;
503         struct obd_device *tgt_obd;
504         struct lustre_cfg *lcfg = buf;
505         struct lmv_obd *lmv = &obd->u.lmv;
506         ENTRY;
507
508         if (lcfg->lcfg_inllen1 < 1) {
509                 CERROR("LMV setup requires a descriptor\n");
510                 RETURN(-EINVAL);
511         }
512
513         if (lcfg->lcfg_inllen2 < 1) {
514                 CERROR("LMV setup requires an OST UUID list\n");
515                 RETURN(-EINVAL);
516         }
517
518         desc = (struct lmv_desc *)lcfg->lcfg_inlbuf1;
519         if (sizeof(*desc) > lcfg->lcfg_inllen1) {
520                 CERROR("descriptor size wrong: %d > %d\n",
521                        (int)sizeof(*desc), lcfg->lcfg_inllen1);
522                 RETURN(-EINVAL);
523         }
524
525         uuids = (struct obd_uuid *)lcfg->lcfg_inlbuf2;
526         if (sizeof(*uuids) * desc->ld_tgt_count != lcfg->lcfg_inllen2) {
527                 CERROR("UUID array size wrong: %u * %u != %u\n",
528                        sizeof(*uuids), desc->ld_tgt_count, lcfg->lcfg_inllen2);
529                 RETURN(-EINVAL);
530         }
531
532         lmv->bufsize = sizeof(struct lmv_tgt_desc) * desc->ld_tgt_count;
533         OBD_ALLOC(lmv->tgts, lmv->bufsize);
534         if (lmv->tgts == NULL) {
535                 CERROR("Out of memory\n");
536                 RETURN(-ENOMEM);
537         }
538
539         lmv->desc = *desc;
540         spin_lock_init(&lmv->lmv_lock);
541         
542         for (i = 0, tgts = lmv->tgts; i < desc->ld_tgt_count; i++, tgts++)
543                 tgts->uuid = uuids[i];
544         
545         lmv->max_cookiesize = 0;
546
547         lmv->max_easize = sizeof(struct ll_fid) *
548                 desc->ld_tgt_count + sizeof(struct mea);
549         
550         rc = lmv_setup_mgr(obd);
551         if (rc) {
552                 CERROR("Can't setup LMV object manager, "
553                        "error %d.\n", rc);
554                 OBD_FREE(lmv->tgts, lmv->bufsize);
555         }
556
557         tgt_obd = class_find_client_obd(&lmv->tgts->uuid, LUSTRE_MDC_NAME, 
558                                         &obd->obd_uuid);
559         if (!tgt_obd) {
560                 CERROR("Target %s not attached\n", lmv->tgts->uuid.uuid);
561                 RETURN(-EINVAL);
562         }
563
564         RETURN(rc);
565 }
566
567 static int lmv_statfs(struct obd_device *obd, struct obd_statfs *osfs,
568                       unsigned long max_age)
569 {
570         struct lmv_obd *lmv = &obd->u.lmv;
571         struct obd_statfs temp;
572         int rc = 0, i;
573         ENTRY;
574         
575         rc = lmv_check_connect(obd);
576         if (rc)
577                 RETURN(rc);
578                 
579         for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
580                 if (lmv->tgts[i].ltd_exp == NULL) {
581                         CWARN("%s: NULL export for %d\n", obd->obd_name, i);
582                         continue;
583                 }
584
585                 rc = obd_statfs(lmv->tgts[i].ltd_exp->exp_obd, &temp, max_age);
586                 if (rc) {
587                         CERROR("can't stat MDS #%d (%s)\n", i,
588                                lmv->tgts[i].ltd_exp->exp_obd->obd_name);
589                         RETURN(rc);
590                 }
591                 if (i == 0) {
592                         memcpy(osfs, &temp, sizeof(temp));
593                 } else {
594                         osfs->os_bavail += temp.os_bavail;
595                         osfs->os_blocks += temp.os_blocks;
596                         osfs->os_ffree += temp.os_ffree;
597                         osfs->os_files += temp.os_files;
598                 }
599         }
600         RETURN(rc);
601 }
602
603 static int lmv_cleanup(struct obd_device *obd, int flags) 
604 {
605         struct lmv_obd *lmv = &obd->u.lmv;
606         ENTRY;
607         lmv_cleanup_mgr(obd);
608         OBD_FREE(lmv->tgts, lmv->bufsize);
609         RETURN(0);
610 }
611
612 static int lmv_getstatus(struct obd_export *exp, struct ll_fid *fid)
613 {
614         struct obd_device *obd = exp->exp_obd;
615         struct lmv_obd *lmv = &obd->u.lmv;
616         int rc;
617         ENTRY;
618         rc = lmv_check_connect(obd);
619         if (rc)
620                 RETURN(rc);
621         rc = md_getstatus(lmv->tgts[0].ltd_exp, fid);
622         fid->mds = 0;
623         RETURN(rc);
624 }
625
626 static int lmv_getattr(struct obd_export *exp, struct ll_fid *fid,
627                        unsigned long valid, unsigned int ea_size,
628                        struct ptlrpc_request **request)
629 {
630         struct obd_device *obd = exp->exp_obd;
631         struct lmv_obd *lmv = &obd->u.lmv;
632         int rc, i = fid->mds;
633         struct lmv_obj *obj;
634         ENTRY;
635
636         rc = lmv_check_connect(obd);
637         if (rc)
638                 RETURN(rc);
639
640         LASSERT(i < lmv->desc.ld_tgt_count);
641
642         rc = md_getattr(lmv->tgts[i].ltd_exp, fid, valid,
643                         ea_size, request);
644         if (rc)
645                 RETURN(rc);
646         
647         obj = lmv_grab_obj(obd, fid);
648         
649         CDEBUG(D_OTHER, "GETATTR for %lu/%lu/%lu %s\n",
650                (unsigned long)fid->mds, (unsigned long)fid->id,
651                (unsigned long)fid->generation, obj ? "(splitted)" : "");
652
653         /* if object is splitted, then we loop over all the slaves and gather
654          * size attribute. In ideal world we would have to gather also mds field
655          * from all slaves, as object is spread over the cluster and this is
656          * definitely interesting information and it is not good to loss it,
657          * but...*/
658         if (obj) {
659                 struct mds_body *body;
660
661                 if (*request == NULL) {
662                         lmv_put_obj(obj);
663                         RETURN(rc);
664                 }
665                         
666                 body = lustre_msg_buf((*request)->rq_repmsg, 0,
667                                       sizeof(*body));
668                 LASSERT(body != NULL);
669
670                 lmv_lock_obj(obj);
671         
672                 for (i = 0; i < obj->objcount; i++) {
673
674                         if (lmv->tgts[i].ltd_exp == NULL) {
675                                 CWARN("%s: NULL export for %d\n",
676                                       obd->obd_name, i);
677                                 continue;
678                         }
679
680                         /* skip master obj. */
681                         if (fid_equal(&obj->fid, &obj->objs[i].fid))
682                                 continue;
683                         
684                         body->size += obj->objs[i].size;
685                 }
686
687                 lmv_unlock_obj(obj);
688                 lmv_put_obj(obj);
689         }
690         
691         RETURN(rc);
692 }
693
694 static int lmv_change_cbdata(struct obd_export *exp, struct ll_fid *fid, 
695                              ldlm_iterator_t it, void *data)
696 {
697         struct obd_device *obd = exp->exp_obd;
698         struct lmv_obd *lmv = &obd->u.lmv;
699         int rc = 0;
700         ENTRY;
701         
702         rc = lmv_check_connect(obd);
703         if (rc)
704                 RETURN(rc);
705         
706         CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu\n", (unsigned long)fid->mds,
707                (unsigned long)fid->id, (unsigned long)fid->generation);
708         
709         LASSERT(fid->mds < lmv->desc.ld_tgt_count);
710
711         rc = md_change_cbdata(lmv->tgts[fid->mds].ltd_exp,
712                               fid, it, data);
713         
714         RETURN(rc);
715 }
716
717 static int lmv_change_cbdata_name(struct obd_export *exp, struct ll_fid *pfid,
718                                   char *name, int len, struct ll_fid *cfid,
719                                   ldlm_iterator_t it, void *data)
720 {
721         struct obd_device *obd = exp->exp_obd;
722         struct lmv_obd *lmv = &obd->u.lmv;
723         struct lmv_obj *obj;
724         int rc = 0, mds;
725         ENTRY;
726
727         rc = lmv_check_connect(obd);
728         if (rc)
729                 RETURN(rc);
730
731         LASSERT(pfid->mds < lmv->desc.ld_tgt_count);
732         LASSERT(cfid->mds < lmv->desc.ld_tgt_count);
733         
734         CDEBUG(D_OTHER, "CBDATA for %lu/%lu/%lu:%*s -> %lu/%lu/%lu\n",
735                (unsigned long)pfid->mds, (unsigned long)pfid->id,
736                (unsigned long)pfid->generation, len, name,
737                (unsigned long)cfid->mds, (unsigned long)cfid->id,
738                (unsigned long)cfid->generation);
739
740         /* this is default mds for directory name belongs to. */
741         mds = pfid->mds;
742         obj = lmv_grab_obj(obd, pfid);
743         if (obj) {
744                 /* directory is splitted. look for right mds for this name. */
745                 mds = raw_name2idx(obj->hashtype, obj->objcount, name, len);
746                 mds = obj->objs[mds].fid.mds;
747                 lmv_put_obj(obj);
748         }
749         rc = md_change_cbdata(lmv->tgts[mds].ltd_exp, cfid, it, data);
750         RETURN(rc);
751 }
752
753 static int lmv_valid_attrs(struct obd_export *exp, struct ll_fid *fid) 
754 {
755         struct obd_device *obd = exp->exp_obd;
756         struct lmv_obd *lmv = &obd->u.lmv;
757         int rc = 0;
758         ENTRY;
759         rc = lmv_check_connect(obd);
760         if (rc)
761                 RETURN(rc);
762         CDEBUG(D_OTHER, "validate %lu/%lu/%lu\n", (unsigned long) fid->mds,
763                (unsigned long) fid->id, (unsigned long) fid->generation);
764         LASSERT(fid->mds < lmv->desc.ld_tgt_count);
765         rc = md_valid_attrs(lmv->tgts[fid->mds].ltd_exp, fid);
766         RETURN(rc);
767 }
768
769 int lmv_close(struct obd_export *exp, struct obdo *obdo,
770                   struct obd_client_handle *och,
771                   struct ptlrpc_request **request)
772 {
773         struct obd_device *obd = exp->exp_obd;
774         struct lmv_obd *lmv = &obd->u.lmv;
775         int rc, i = obdo->o_mds;
776         ENTRY;
777         rc = lmv_check_connect(obd);
778         if (rc)
779                 RETURN(rc);
780         LASSERT(i < lmv->desc.ld_tgt_count);
781         CDEBUG(D_OTHER, "CLOSE %lu/%lu/%lu\n", (unsigned long) obdo->o_mds,
782                (unsigned long) obdo->o_id, (unsigned long) obdo->o_generation);
783         rc = md_close(lmv->tgts[i].ltd_exp, obdo, och, request);
784         RETURN(rc);
785 }
786
787 int lmv_get_mea_and_update_object(struct obd_export *exp, struct ll_fid *fid)
788 {
789         struct obd_device *obd = exp->exp_obd;
790         struct lmv_obd *lmv = &obd->u.lmv;
791         struct ptlrpc_request *req = NULL;
792         struct lmv_obj *obj;
793         struct lustre_md md;
794         unsigned long valid;
795         int mealen, rc;
796
797         md.mea = NULL;
798         mealen = MEA_SIZE_LMV(lmv);
799         
800         valid = OBD_MD_FLEASIZE | OBD_MD_FLDIREA;
801
802         /* time to update mea of parent fid */
803         rc = md_getattr(lmv->tgts[fid->mds].ltd_exp, fid,
804                         valid, mealen, &req);
805         if (rc) {
806                 CERROR("md_getattr() failed, error %d\n", rc);
807                 GOTO(cleanup, rc);
808         }
809
810         rc = mdc_req2lustre_md(exp, req, 0, NULL, &md);
811         if (rc) {
812                 CERROR("mdc_req2lustre_md() failed, error %d\n", rc);
813                 GOTO(cleanup, rc);
814         }
815
816         if (md.mea == NULL)
817                 GOTO(cleanup, rc = -ENODATA);
818
819         obj = lmv_create_obj(exp, fid, md.mea);
820         if (IS_ERR(obj))
821                 rc = PTR_ERR(obj);
822         
823         lmv_put_obj(obj);
824         obd_free_memmd(exp, (struct lov_stripe_md **)&md.mea);
825
826 cleanup:
827         if (req)
828                 ptlrpc_req_finished(req);
829         RETURN(rc);
830 }
831
832 int lmv_create(struct obd_export *exp, struct mdc_op_data *op_data,
833                const void *data, int datalen, int mode, __u32 uid,
834                __u32 gid, __u64 rdev, struct ptlrpc_request **request)
835 {
836         struct obd_device *obd = exp->exp_obd;
837         struct lmv_obd *lmv = &obd->u.lmv;
838         struct mds_body *body;
839         struct lmv_obj *obj;
840         int rc, mds, loop = 0;
841         ENTRY;
842
843         rc = lmv_check_connect(obd);
844         if (rc)
845                 RETURN(rc);
846
847         if (!lmv->desc.ld_active_tgt_count)
848                 RETURN(-EIO);
849 repeat:
850         LASSERT(++loop <= 2);
851         obj = lmv_grab_obj(obd, &op_data->fid1);
852         if (obj) {
853                 mds = raw_name2idx(obj->hashtype, obj->objcount, op_data->name,
854                                    op_data->namelen);
855                 op_data->fid1 = obj->objs[mds].fid;
856                 lmv_put_obj(obj);
857         }
858
859         CDEBUG(D_OTHER, "CREATE '%*s' on %lu/%lu/%lu\n", op_data->namelen,
860                op_data->name, (unsigned long)op_data->fid1.mds,
861                (unsigned long)op_data->fid1.id,
862                (unsigned long)op_data->fid1.generation);
863         
864         rc = md_create(lmv->tgts[op_data->fid1.mds].ltd_exp, op_data, data,
865                        datalen, mode, uid, gid, rdev, request);
866         if (rc == 0) {
867                 if (*request == NULL)
868                         RETURN(rc);
869
870                 body = lustre_msg_buf((*request)->rq_repmsg, 0,
871                                       sizeof(*body));
872                 LASSERT(body != NULL);
873                 
874                 CDEBUG(D_OTHER, "created. id = %lu, generation = %lu, "
875                        "mds = %d\n", (unsigned long)body->fid1.id,
876                        (unsigned long)body->fid1.generation, op_data->fid1.mds);
877                 
878                 LASSERT(body->valid & OBD_MD_MDS ||
879                         body->mds == op_data->fid1.mds);
880         } else if (rc == -ERESTART) {
881                 /* directory got splitted. time to update local object and
882                  * repeat the request with proper MDS */
883                 rc = lmv_get_mea_and_update_object(exp, &op_data->fid1);
884                 if (rc == 0) {
885                         ptlrpc_req_finished(*request);
886                         goto repeat;
887                 }
888         }
889         RETURN(rc);
890 }
891
892 int lmv_done_writing(struct obd_export *exp, struct obdo *obdo)
893 {
894         struct obd_device *obd = exp->exp_obd;
895         struct lmv_obd *lmv = &obd->u.lmv;
896         int rc;
897         ENTRY;
898         rc = lmv_check_connect(obd);
899         if (rc)
900                 RETURN(rc);
901
902         /* FIXME: choose right MDC here */
903         CWARN("this method isn't implemented yet\n");
904         rc = md_done_writing(lmv->tgts[0].ltd_exp, obdo);
905         RETURN(rc);
906 }
907
908 int lmv_enqueue_slaves(struct obd_export *exp, int locktype,
909                        struct lookup_intent *it, int lockmode,
910                        struct mdc_op_data *data, struct lustre_handle *lockh,
911                        void *lmm, int lmmsize, ldlm_completion_callback cb_completion,
912                        ldlm_blocking_callback cb_blocking, void *cb_data)
913 {
914         struct obd_device *obd = exp->exp_obd;
915         struct lmv_obd *lmv = &obd->u.lmv;
916         struct mea *mea = data->mea1;
917         struct mdc_op_data data2;
918         int i, rc, mds;
919         ENTRY;
920
921         LASSERT(mea != NULL);
922         for (i = 0; i < mea->mea_count; i++) {
923                 memset(&data2, 0, sizeof(data2));
924                 data2.fid1 = mea->mea_fids[i];
925                 mds = data2.fid1.mds;
926                 
927                 if (lmv->tgts[mds].ltd_exp == NULL)
928                         continue;
929
930                 rc = md_enqueue(lmv->tgts[mds].ltd_exp, locktype, it, lockmode,
931                                 &data2, lockh + i, lmm, lmmsize, cb_completion,
932                                 cb_blocking, cb_data);
933                 
934                 CDEBUG(D_OTHER, "take lock on slave %lu/%lu/%lu -> %d/%d\n",
935                        (unsigned long)mea->mea_fids[i].mds,
936                        (unsigned long)mea->mea_fids[i].id,
937                        (unsigned long)mea->mea_fids[i].generation,
938                        rc, it->d.lustre.it_status);
939                 if (rc)
940                         GOTO(cleanup, rc);
941                 if (it->d.lustre.it_data) {
942                         struct ptlrpc_request *req;
943                         req = (struct ptlrpc_request *) it->d.lustre.it_data;
944                         ptlrpc_req_finished(req);
945                 }
946                 
947                 if (it->d.lustre.it_status)
948                         GOTO(cleanup, rc = it->d.lustre.it_status);
949         }
950         RETURN(0);
951         
952 cleanup:
953         /* drop all taken locks */
954         while (--i >= 0) {
955                 if (lockh[i].cookie)
956                         ldlm_lock_decref(lockh + i, lockmode);
957                 lockh[i].cookie = 0;
958         }
959         RETURN(rc);
960 }
961
962 int lmv_enqueue(struct obd_export *exp, int lock_type,
963                 struct lookup_intent *it, int lock_mode,
964                 struct mdc_op_data *data, struct lustre_handle *lockh,
965                 void *lmm, int lmmsize, ldlm_completion_callback cb_completion,
966                 ldlm_blocking_callback cb_blocking, void *cb_data)
967 {
968         struct obd_device *obd = exp->exp_obd;
969         struct lmv_obd *lmv = &obd->u.lmv;
970         struct lmv_obj *obj;
971         int rc, mds;
972         ENTRY;
973
974         rc = lmv_check_connect(obd);
975         if (rc)
976                 RETURN(rc);
977
978         if (it->it_op == IT_UNLINK) {
979                 rc = lmv_enqueue_slaves(exp, lock_type, it, lock_mode,
980                                         data, lockh, lmm, lmmsize,
981                                         cb_completion, cb_blocking, cb_data);
982                 RETURN(rc);
983         }
984
985         if (data->namelen) {
986                 obj = lmv_grab_obj(obd, &data->fid1);
987                 if (obj) {
988                         /* directory is splitted. look for right mds for this
989                          * name */
990                         mds = raw_name2idx(obj->hashtype, obj->objcount,
991                                            (char *)data->name, data->namelen);
992                         data->fid1 = obj->objs[mds].fid;
993                         lmv_put_obj(obj);
994                 }
995         }
996         CDEBUG(D_OTHER, "ENQUEUE '%s' on %lu/%lu\n", LL_IT2STR(it),
997                (unsigned long)data->fid1.id, (unsigned long)data->fid1.generation);
998         
999         rc = md_enqueue(lmv->tgts[data->fid1.mds].ltd_exp, lock_type, it,
1000                         lock_mode, data, lockh, lmm, lmmsize, cb_completion,
1001                         cb_blocking, cb_data);
1002
1003         RETURN(rc);
1004 }
1005
1006 int lmv_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1007                      char *filename, int namelen, unsigned long valid,
1008                      unsigned int ea_size, struct ptlrpc_request **request)
1009 {
1010         struct obd_device *obd = exp->exp_obd;
1011         struct lmv_obd *lmv = &obd->u.lmv;
1012         struct ll_fid rfid = *fid;
1013         int rc, mds = fid->mds, loop = 0;
1014         struct mds_body *body;
1015         struct lmv_obj *obj;
1016         ENTRY;
1017         rc = lmv_check_connect(obd);
1018         if (rc)
1019                 RETURN(rc);
1020 repeat:
1021         LASSERT(++loop <= 2);
1022         obj = lmv_grab_obj(obd, fid);
1023         if (obj) {
1024                 /* directory is splitted. look for right mds for this name */
1025                 mds = raw_name2idx(obj->hashtype, obj->objcount, filename, namelen - 1);
1026                 rfid = obj->objs[mds].fid;
1027                 lmv_put_obj(obj);
1028         }
1029         
1030         CDEBUG(D_OTHER, "getattr_name for %*s on %lu/%lu/%lu -> %lu/%lu/%lu\n",
1031                namelen, filename, (unsigned long)fid->mds,
1032                (unsigned long)fid->id, (unsigned long)fid->generation,
1033                (unsigned long)rfid.mds, (unsigned long)rfid.id,
1034                (unsigned long)rfid.generation);
1035
1036         rc = md_getattr_name(lmv->tgts[rfid.mds].ltd_exp, &rfid, filename,
1037                              namelen, valid, ea_size, request);
1038         if (rc == 0) {
1039                 /* this could be cross-node reference. in this case all we have
1040                  * right now is mds/ino/generation triple. we'd like to find
1041                  * other attributes */
1042                 body = lustre_msg_buf((*request)->rq_repmsg, 0, sizeof(*body));
1043                 LASSERT(body != NULL);
1044                 if (body->valid & OBD_MD_MDS) {
1045                         struct ptlrpc_request *req = NULL;
1046                         rfid = body->fid1;
1047                         CDEBUG(D_OTHER, "request attrs for %lu/%lu/%lu\n",
1048                                (unsigned long) rfid.mds,
1049                                (unsigned long) rfid.id,
1050                                (unsigned long) rfid.generation);
1051                         rc = md_getattr_name(lmv->tgts[rfid.mds].ltd_exp, &rfid,
1052                                              NULL, 1, valid, ea_size, &req);
1053                         ptlrpc_req_finished(*request);
1054                         *request = req;
1055                 }
1056         } else if (rc == -ERESTART) {
1057                 /* directory got splitted. time to update local object and
1058                  * repeat the request with proper MDS */
1059                 rc = lmv_get_mea_and_update_object(exp, &rfid);
1060                 if (rc == 0) {
1061                         ptlrpc_req_finished(*request);
1062                         goto repeat;
1063                 }
1064         }
1065         RETURN(rc);
1066 }
1067
1068
1069 /*
1070  * llite passes fid of an target inode in data->fid1 and fid of directory in
1071  * data->fid2
1072  */
1073 int lmv_link(struct obd_export *exp, struct mdc_op_data *data,
1074              struct ptlrpc_request **request)
1075 {
1076         struct obd_device *obd = exp->exp_obd;
1077         struct lmv_obd *lmv = &obd->u.lmv;
1078         struct lmv_obj *obj;
1079         int rc;
1080         ENTRY;
1081         
1082         rc = lmv_check_connect(obd);
1083         if (rc)
1084                 RETURN(rc);
1085
1086         if (data->namelen != 0) {
1087                 /* usual link request */
1088                 obj = lmv_grab_obj(obd, &data->fid1);
1089                 if (obj) {
1090                         rc = raw_name2idx(obj->hashtype, obj->objcount, data->name,
1091                                           data->namelen);
1092                         data->fid1 = obj->objs[rc].fid;
1093                         lmv_put_obj(obj);
1094                 }
1095                 
1096                 CDEBUG(D_OTHER,"link %lu/%lu/%lu:%*s to %lu/%lu/%lu mds %lu\n",
1097                        (unsigned long)data->fid2.mds,
1098                        (unsigned long)data->fid2.id,
1099                        (unsigned long)data->fid2.generation,
1100                        data->namelen, data->name,
1101                        (unsigned long)data->fid1.mds,
1102                        (unsigned long)data->fid1.id,
1103                        (unsigned long)data->fid1.generation,
1104                        (unsigned long)data->fid1.mds);
1105         } else {
1106                 /* request from MDS to acquire i_links for inode by fid1 */
1107                 CDEBUG(D_OTHER, "inc i_nlinks for %lu/%lu/%lu\n",
1108                        (unsigned long)data->fid1.mds,
1109                        (unsigned long)data->fid1.id,
1110                        (unsigned long)data->fid1.generation);
1111         }
1112                         
1113         rc = md_link(lmv->tgts[data->fid1.mds].ltd_exp, data, request);
1114         RETURN(rc);
1115 }
1116
1117 int lmv_rename(struct obd_export *exp, struct mdc_op_data *data,
1118                const char *old, int oldlen, const char *new, int newlen,
1119                struct ptlrpc_request **request)
1120 {
1121         struct obd_device *obd = exp->exp_obd;
1122         struct lmv_obd *lmv = &obd->u.lmv;
1123         struct lmv_obj *obj;
1124         int rc, mds;
1125         ENTRY;
1126
1127         CDEBUG(D_OTHER, "rename %*s in %lu/%lu/%lu to %*s in %lu/%lu/%lu\n",
1128                oldlen, old, (unsigned long)data->fid1.mds,
1129                (unsigned long)data->fid1.id,
1130                (unsigned long)data->fid1.generation,
1131                newlen, new, (unsigned long) data->fid2.mds,
1132                (unsigned long) data->fid2.id,
1133                (unsigned long) data->fid2.generation);
1134         
1135         if (!fid_equal(&data->fid1, &data->fid2))
1136                 CDEBUG(D_OTHER, "cross-node rename %lu/%lu/%lu:%*s to %lu/%lu/%lu:%*s\n",
1137                       (unsigned long)data->fid1.mds,
1138                       (unsigned long)data->fid1.id,
1139                       (unsigned long)data->fid1.generation, oldlen, old,
1140                       (unsigned long)data->fid2.mds,
1141                       (unsigned long)data->fid2.id,
1142                       (unsigned long)data->fid2.generation, newlen, new);
1143
1144         rc = lmv_check_connect(obd);
1145         if (rc)
1146                 RETURN(rc);
1147
1148         if (oldlen == 0) {
1149                 /* MDS with old dir entry is asking another MDS to create name
1150                  * there */
1151                 CDEBUG(D_OTHER,
1152                        "create %*s(%d/%d) in %lu/%lu/%lu pointing to %lu/%lu/%lu\n",
1153                        newlen, new, oldlen, newlen,
1154                        (unsigned long)data->fid2.mds,
1155                        (unsigned long)data->fid2.id,
1156                        (unsigned long)data->fid2.generation,
1157                        (unsigned long)data->fid1.mds,
1158                        (unsigned long)data->fid1.id,
1159                        (unsigned long)data->fid1.generation);
1160                 mds = data->fid2.mds;
1161                 goto request;
1162         }
1163
1164         obj = lmv_grab_obj(obd, &data->fid1);
1165         if (obj) {
1166                 /* directory is already splitted, so we have to forward request
1167                  * to the right MDS */
1168                 mds = raw_name2idx(obj->hashtype, obj->objcount, (char *)old, oldlen);
1169                 data->fid1 = obj->objs[mds].fid;
1170                 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
1171                        (unsigned long)obj->objs[mds].fid.mds,
1172                        (unsigned long)obj->objs[mds].fid.id,
1173                        (unsigned long)obj->objs[mds].fid.generation);
1174                 lmv_put_obj(obj);
1175         }
1176
1177         obj = lmv_grab_obj(obd, &data->fid2);
1178         if (obj) {
1179                 /* directory is already splitted, so we have to forward request
1180                  * to the right MDS */
1181                 mds = raw_name2idx(obj->hashtype, obj->objcount, (char *)new, newlen);
1182                 data->fid2 = obj->objs[mds].fid;
1183                 CDEBUG(D_OTHER, "forward to MDS #%u (%lu/%lu/%lu)\n", mds,
1184                        (unsigned long)obj->objs[mds].fid.mds,
1185                        (unsigned long)obj->objs[mds].fid.id,
1186                        (unsigned long)obj->objs[mds].fid.generation);
1187                 lmv_put_obj(obj);
1188         }
1189         
1190         mds = data->fid1.mds;
1191
1192 request:
1193         rc = md_rename(lmv->tgts[mds].ltd_exp, data, old, oldlen,
1194                        new, newlen, request); 
1195         RETURN(rc);
1196 }
1197
1198 int lmv_setattr(struct obd_export *exp, struct mdc_op_data *data,
1199                 struct iattr *iattr, void *ea, int ealen, void *ea2,
1200                 int ea2len, struct ptlrpc_request **request)
1201 {
1202         struct obd_device *obd = exp->exp_obd;
1203         struct lmv_obd *lmv = &obd->u.lmv;
1204         struct ptlrpc_request *req;
1205         struct mds_body *body;
1206         struct lmv_obj *obj;
1207         int rc = 0, i;
1208         ENTRY;
1209
1210         rc = lmv_check_connect(obd);
1211         if (rc)
1212                 RETURN(rc);
1213
1214         obj = lmv_grab_obj(obd, &data->fid1);
1215         
1216         CDEBUG(D_OTHER, "SETATTR for %lu/%lu/%lu, valid 0x%x%s\n",
1217                (unsigned long)data->fid1.mds, (unsigned long)data->fid1.id,
1218                (unsigned long)data->fid1.generation, iattr->ia_valid,
1219                obj ? ", splitted" : "");
1220         
1221         if (obj) {
1222                 for (i = 0; i < obj->objcount; i++) {
1223                         data->fid1 = obj->objs[i].fid;
1224                         
1225                         rc = md_setattr(lmv->tgts[data->fid1.mds].ltd_exp, data,
1226                                         iattr, ea, ealen, ea2, ea2len, &req);
1227
1228                         if (fid_equal(&obj->fid, &obj->objs[i].fid)) {
1229                                 /* this is master object and this request should
1230                                  * be returned back to llite */
1231                                 *request = req;
1232                         } else {
1233                                 ptlrpc_req_finished(req);
1234                         }
1235
1236                         if (rc)
1237                                 break;
1238                 }
1239                 lmv_put_obj(obj);
1240         } else {
1241                 LASSERT(data->fid1.mds < lmv->desc.ld_tgt_count);
1242                 rc = md_setattr(lmv->tgts[data->fid1.mds].ltd_exp, data,
1243                                 iattr, ea, ealen, ea2, ea2len, request); 
1244                 if (rc == 0) {
1245                         body = lustre_msg_buf((*request)->rq_repmsg, 0,
1246                                               sizeof(*body));
1247                         LASSERT(body != NULL);
1248                         LASSERT(body->mds == data->fid1.mds);
1249                 }
1250         }
1251         RETURN(rc);
1252 }
1253
1254 int lmv_sync(struct obd_export *exp, struct ll_fid *fid,
1255              struct ptlrpc_request **request)
1256 {
1257         struct obd_device *obd = exp->exp_obd;
1258         struct lmv_obd *lmv = &obd->u.lmv;
1259         int rc;
1260         ENTRY;
1261
1262         rc = lmv_check_connect(obd);
1263         if (rc)
1264                 RETURN(rc);
1265
1266         rc = md_sync(lmv->tgts[fid->mds].ltd_exp, fid, request); 
1267         RETURN(rc);
1268 }
1269
1270 int lmv_dirobj_blocking_ast(struct ldlm_lock *lock, struct ldlm_lock_desc *desc,
1271                             void *data, int flag)
1272 {
1273         struct lustre_handle lockh;
1274         struct lmv_obj *obj;
1275         int rc;
1276         ENTRY;
1277
1278         switch (flag) {
1279         case LDLM_CB_BLOCKING:
1280                 ldlm_lock2handle(lock, &lockh);
1281                 rc = ldlm_cli_cancel(&lockh);
1282                 if (rc < 0) {
1283                         CDEBUG(D_INODE, "ldlm_cli_cancel: %d\n", rc);
1284                         RETURN(rc);
1285                 }
1286                 break;
1287         case LDLM_CB_CANCELING:
1288                 /* time to drop cached attrs for dirobj */
1289                 obj = lock->l_ast_data;
1290                 if (obj) {
1291                         CDEBUG(D_OTHER, "cancel %s on "LPU64"/"LPU64
1292                                ", master %u/"LPU64"/%u\n",
1293                                lock->l_resource->lr_name.name[3] == 1 ?
1294                                         "LOOKUP" : "UPDATE",
1295                                lock->l_resource->lr_name.name[0],
1296                                lock->l_resource->lr_name.name[1], obj->fid.mds,
1297                                obj->fid.id, obj->fid.generation);
1298                         lmv_put_obj(obj);
1299                 }
1300                 break;
1301         default:
1302                 LBUG();
1303         }
1304         RETURN(0);
1305 }
1306
1307 void lmv_remove_dots(struct page *page)
1308 {
1309         char *kaddr = page_address(page);
1310         unsigned limit = PAGE_CACHE_SIZE;
1311         unsigned offs, rec_len;
1312         struct ext2_dir_entry_2 *p;
1313
1314         for (offs = 0; offs <= limit - EXT2_DIR_REC_LEN(1); offs += rec_len) {
1315                 p = (struct ext2_dir_entry_2 *)(kaddr + offs);
1316                 rec_len = le16_to_cpu(p->rec_len);
1317
1318                 if ((p->name_len == 1 && p->name[0] == '.') ||
1319                     (p->name_len == 2 && p->name[0] == '.' && p->name[1] == '.'))
1320                         p->inode = 0;
1321         }
1322 }
1323
1324 int lmv_readpage(struct obd_export *exp, struct ll_fid *mdc_fid,
1325                  __u64 offset, struct page *page,
1326                  struct ptlrpc_request **request)
1327 {
1328         struct obd_device *obd = exp->exp_obd;
1329         struct lmv_obd *lmv = &obd->u.lmv;
1330         struct ll_fid rfid = *mdc_fid;
1331         struct lmv_obj *obj;
1332         int rc, i;
1333         ENTRY;
1334
1335         rc = lmv_check_connect(obd);
1336         if (rc)
1337                 RETURN(rc);
1338
1339         LASSERT(mdc_fid->mds < lmv->desc.ld_tgt_count);
1340         CDEBUG(D_OTHER, "READPAGE at %llu from %lu/%lu/%lu\n",
1341                offset, (unsigned long) rfid.mds,
1342                (unsigned long) rfid.id,
1343                (unsigned long) rfid.generation);
1344
1345         obj = lmv_grab_obj(obd, mdc_fid);
1346         if (obj) {
1347                 lmv_lock_obj(obj);
1348
1349                 /* find dirobj containing page with requested offset. */
1350                 for (i = 0; i < obj->objcount; i++) {
1351                         if (offset < obj->objs[i].size)
1352                                 break;
1353                         offset -= obj->objs[i].size;
1354                 }
1355                 rfid = obj->objs[i].fid;
1356                 
1357                 lmv_unlock_obj(obj);
1358                 lmv_put_obj(obj);
1359                 
1360                 CDEBUG(D_OTHER, "forward to %lu/%lu/%lu with offset %lu\n",
1361                        (unsigned long)rfid.mds, (unsigned long)rfid.id,
1362                        (unsigned long)rfid.generation, (unsigned long)offset);
1363         }
1364         rc = md_readpage(lmv->tgts[rfid.mds].ltd_exp, &rfid, offset,
1365                          page, request);
1366         
1367         if (rc == 0 && !fid_equal(&rfid, mdc_fid))
1368                 /* this page isn't from master object. To avoid "." and ".." 
1369                  * duplication in directory, we have to remove them from all
1370                  * slave objects */
1371                 lmv_remove_dots(page);
1372         
1373         RETURN(rc);
1374 }
1375
1376 int lmv_unlink_slaves(struct obd_export *exp, struct mdc_op_data *data,
1377                       struct ptlrpc_request **req)
1378 {
1379         struct obd_device *obd = exp->exp_obd;
1380         struct lmv_obd *lmv = &obd->u.lmv;
1381         struct mea *mea = data->mea1;
1382         struct mdc_op_data data2;
1383         int i, rc = 0, mds;
1384         ENTRY;
1385
1386         LASSERT(mea != NULL);
1387         for (i = 0; i < mea->mea_count; i++) {
1388                 memset(&data2, 0, sizeof(data2));
1389                 data2.fid1 = mea->mea_fids[i];
1390                 data2.create_mode = MDS_MODE_DONT_LOCK | S_IFDIR;
1391                 mds = data2.fid1.mds;
1392
1393                 if (lmv->tgts[mds].ltd_exp == NULL)
1394                         continue;
1395
1396                 rc = md_unlink(lmv->tgts[mds].ltd_exp, &data2, req);
1397                 CDEBUG(D_OTHER, "unlink slave %lu/%lu/%lu -> %d\n",
1398                        (unsigned long) mea->mea_fids[i].mds,
1399                        (unsigned long) mea->mea_fids[i].id,
1400                        (unsigned long) mea->mea_fids[i].generation, rc);
1401                 if (*req) {
1402                         ptlrpc_req_finished(*req);
1403                         *req = NULL;
1404                 }
1405                 if (rc)
1406                         break;
1407         }
1408         RETURN(rc);
1409 }
1410
1411 int lmv_delete_object(struct obd_export *exp, struct ll_fid *fid)
1412 {
1413         ENTRY;
1414
1415         if (!lmv_delete_obj(exp, fid)) {
1416                 CDEBUG(D_OTHER, "Object %lu/%lu/%lu is not found.\n",
1417                        (unsigned long)fid->mds, (unsigned long)fid->id,
1418                        (unsigned long)fid->generation);
1419         }
1420         
1421         RETURN(0);
1422 }
1423
1424 int lmv_unlink(struct obd_export *exp, struct mdc_op_data *data,
1425                struct ptlrpc_request **request)
1426 {
1427         struct obd_device *obd = exp->exp_obd;
1428         struct lmv_obd *lmv = &obd->u.lmv;
1429         int rc, i = 0;
1430         ENTRY;
1431         
1432         rc = lmv_check_connect(obd);
1433         if (rc)
1434                 RETURN(rc);
1435
1436         if (data->namelen == 0 && data->mea1 != NULL) {
1437                 /* mds asks to remove slave objects */
1438                 rc = lmv_unlink_slaves(exp, data, request);
1439                 RETURN(rc);
1440         } else if (data->namelen != 0) {
1441                 struct lmv_obj *obj;
1442                 
1443                 obj = lmv_grab_obj(obd, &data->fid1);
1444                 if (obj) {
1445                         i = raw_name2idx(obj->hashtype, obj->objcount, data->name,
1446                                          data->namelen);
1447                         data->fid1 = obj->objs[i].fid;
1448                         lmv_put_obj(obj);
1449                 }
1450                 CDEBUG(D_OTHER, "unlink '%*s' in %lu/%lu/%lu -> %u\n",
1451                        data->namelen, data->name,
1452                        (unsigned long) data->fid1.mds,
1453                        (unsigned long) data->fid1.id,
1454                        (unsigned long) data->fid1.generation, i);
1455         } else {
1456                 CDEBUG(D_OTHER, "drop i_nlink on %lu/%lu/%lu\n",
1457                        (unsigned long) data->fid1.mds,
1458                        (unsigned long) data->fid1.id,
1459                        (unsigned long) data->fid1.generation);
1460         }
1461         rc = md_unlink(lmv->tgts[data->fid1.mds].ltd_exp, data, request); 
1462         RETURN(rc);
1463 }
1464
1465 struct obd_device *lmv_get_real_obd(struct obd_export *exp,
1466                                     char *name, int len)
1467 {
1468         struct obd_device *obd = exp->exp_obd;
1469         struct lmv_obd *lmv = &obd->u.lmv;
1470         int rc;
1471         ENTRY;
1472
1473         rc = lmv_check_connect(obd);
1474         if (rc)
1475                 RETURN(ERR_PTR(rc));
1476 #warning "we need well-desgined readdir() implementation to remove this mess"
1477         obd = lmv->tgts[0].ltd_exp->exp_obd;
1478         EXIT;
1479         return obd;
1480 }
1481
1482 int lmv_init_ea_size(struct obd_export *exp, int easize, int cookiesize)
1483 {
1484         struct obd_device *obd = exp->exp_obd;
1485         struct lmv_obd *lmv = &obd->u.lmv;
1486         int i, rc = 0, change = 0;
1487         ENTRY;
1488
1489         if (lmv->max_easize < easize) {
1490                 lmv->max_easize = easize;
1491                 change = 1;
1492         }
1493         if (lmv->max_cookiesize < cookiesize) {
1494                 lmv->max_cookiesize = cookiesize;
1495                 change = 1;
1496         }
1497         if (change == 0)
1498                 RETURN(0);
1499         
1500         if (lmv->connected == 0)
1501                 RETURN(0);
1502
1503         for (i = 0; i < lmv->desc.ld_tgt_count; i++) {
1504                 if (lmv->tgts[i].ltd_exp == NULL) {
1505                         CWARN("%s: NULL export for %d\n", obd->obd_name, i);
1506                         continue;
1507                 }
1508
1509                 rc = obd_init_ea_size(lmv->tgts[i].ltd_exp, easize, cookiesize);
1510                 if (rc) {
1511                         CERROR("obd_init_ea_size() failed on MDT target %d, "
1512                                "error %d.\n", i, rc);
1513                         break;
1514                 }
1515         }
1516         RETURN(rc);
1517 }
1518
1519 int lmv_obd_create_single(struct obd_export *exp, struct obdo *oa,
1520                           struct lov_stripe_md **ea, struct obd_trans_info *oti)
1521 {
1522         struct obd_device *obd = exp->exp_obd;
1523         struct lmv_obd *lmv = &obd->u.lmv;
1524         struct lov_stripe_md obj_md;
1525         struct lov_stripe_md *obj_mdp = &obj_md;
1526         int rc = 0;
1527         ENTRY;
1528
1529         LASSERT(ea == NULL);
1530         LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
1531
1532         rc = obd_create(lmv->tgts[oa->o_mds].ltd_exp, oa, &obj_mdp, oti);
1533
1534         RETURN(rc);
1535 }
1536
1537 /*
1538  * to be called from MDS only
1539  */
1540 int lmv_obd_create(struct obd_export *exp, struct obdo *oa,
1541                    struct lov_stripe_md **ea, struct obd_trans_info *oti)
1542 {
1543         struct obd_device *obd = exp->exp_obd;
1544         struct lmv_obd *lmv = &obd->u.lmv;
1545         int i, c, rc = 0;
1546         struct mea *mea;
1547         struct ll_fid mfid;
1548         int lcount;
1549         ENTRY;
1550
1551         rc = lmv_check_connect(obd);
1552         if (rc)
1553                 RETURN(rc);
1554
1555         LASSERT(oa != NULL);
1556         
1557         if (ea == NULL) {
1558                 rc = lmv_obd_create_single(exp, oa, NULL, oti);
1559                 RETURN(rc);
1560         }
1561
1562         if (*ea == NULL) {
1563                 rc = obd_alloc_diskmd(exp, (struct lov_mds_md **)ea);
1564                 if (rc < 0) {
1565                         CERROR("obd_alloc_diskmd() failed, error %d\n",
1566                                rc);
1567                         RETURN(rc);
1568                 }
1569                 
1570                 if (*ea == NULL)
1571                         RETURN(-EINVAL);
1572         }
1573
1574         rc = 0;
1575         mfid.id = oa->o_id;
1576         mfid.generation = oa->o_generation;
1577         
1578         mea = (struct mea *)*ea;
1579         if (!mea->mea_count || mea->mea_count > lmv->desc.ld_tgt_count)
1580                 mea->mea_count = lmv->desc.ld_tgt_count;
1581         mea->mea_magic = MEA_MAGIC_ALL_CHARS;
1582
1583         mea->mea_master = -1;
1584         lcount = lmv->desc.ld_tgt_count;
1585         for (i = 0, c = 0; c < mea->mea_count && i < lcount; i++) {
1586                 struct lov_stripe_md obj_md;
1587                 struct lov_stripe_md *obj_mdp = &obj_md;
1588                
1589                 if (lmv->tgts[i].ltd_exp == NULL) {
1590                         /* this is master MDS */
1591                         mea->mea_fids[c].id = mfid.id;
1592                         mea->mea_fids[c].generation = mfid.generation;
1593                         mea->mea_fids[c].mds = i;
1594                         mea->mea_master = i;
1595                         c++;
1596                         continue;
1597                 }
1598
1599                 /* "master" MDS should always be part of stripped dir, so scan
1600                    for it. */
1601                 if (mea->mea_master == -1 && c == mea->mea_count - 1)
1602                         continue;
1603
1604                 oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLTYPE | OBD_MD_FLMODE
1605                         | OBD_MD_FLUID | OBD_MD_FLGID | OBD_MD_FLID;
1606
1607                 rc = obd_create(lmv->tgts[c].ltd_exp, oa, &obj_mdp, oti);
1608                 if (rc) {
1609                         CERROR("obd_create() failed on MDT target %d, "
1610                                "error %d\n", c, rc);
1611                         RETURN(rc);
1612                 }
1613
1614                 mea->mea_fids[c].id = oa->o_id;
1615                 mea->mea_fids[c].generation = oa->o_generation;
1616                 mea->mea_fids[c].mds = i;
1617                 c++;
1618                 CDEBUG(D_OTHER, "dirobj at mds %d: "LPU64"/%u\n",
1619                        i, oa->o_id, oa->o_generation);
1620         }
1621         LASSERT(c == mea->mea_count);
1622         CDEBUG(D_OTHER, "%d dirobjects created\n", (int) mea->mea_count);
1623
1624         RETURN(rc);
1625 }
1626
1627 static int lmv_llog_init(struct obd_device *obd, struct obd_llogs *llogs, 
1628                          struct obd_device *tgt, int count,
1629                          struct llog_catid *logid)
1630 {
1631         struct llog_ctxt *ctxt;
1632         int rc;
1633         ENTRY;
1634
1635         rc = obd_llog_setup(obd, llogs, LLOG_CONFIG_REPL_CTXT, tgt, 0, NULL,
1636                             &llog_client_ops);
1637         if (rc == 0) {
1638                 ctxt = llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT);
1639                 ctxt->loc_imp = tgt->u.cli.cl_import;
1640         }
1641
1642         RETURN(rc);
1643 }
1644
1645 static int lmv_llog_finish(struct obd_device *obd,
1646                            struct obd_llogs *llogs, int count)
1647 {
1648         int rc;
1649         ENTRY;
1650
1651         rc = obd_llog_cleanup(llog_get_context(llogs, LLOG_CONFIG_REPL_CTXT));
1652         RETURN(rc);
1653 }
1654
1655 static int lmv_get_info(struct obd_export *exp, __u32 keylen,
1656                         void *key, __u32 *vallen, void *val)
1657 {
1658         struct obd_device *obd;
1659         struct lmv_obd *lmv;
1660         ENTRY;
1661
1662         obd = class_exp2obd(exp);
1663         if (obd == NULL) {
1664                 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1665                        exp->exp_handle.h_cookie);
1666                 RETURN(-EINVAL);
1667         }
1668
1669         lmv = &obd->u.lmv;
1670         if (keylen == 6 && memcmp(key, "mdsize", 6) == 0) {
1671                 __u32 *mdsize = val;
1672                 *vallen = sizeof(__u32);
1673                 *mdsize = sizeof(struct ll_fid) * lmv->desc.ld_tgt_count
1674                                 + sizeof(struct mea);
1675                 RETURN(0);
1676         } else if (keylen == 6 && memcmp(key, "mdsnum", 6) == 0) {
1677                 struct obd_uuid *cluuid = &lmv->cluuid;
1678                 struct lmv_tgt_desc *tgts;
1679                 __u32 *mdsnum = val;
1680                 int i;
1681
1682                 for (i = 0, tgts = lmv->tgts; i < lmv->desc.ld_tgt_count; i++, tgts++) {
1683                         if (obd_uuid_equals(&tgts->uuid, cluuid)) {
1684                                 *vallen = sizeof(__u32);
1685                                 *mdsnum = i;
1686                                 RETURN(0);
1687                         }
1688                 }
1689                 LASSERT(0);
1690         }
1691
1692         CDEBUG(D_IOCTL, "invalid key\n");
1693         RETURN(-EINVAL);
1694 }
1695
1696 int lmv_set_info(struct obd_export *exp, obd_count keylen,
1697                  void *key, obd_count vallen, void *val)
1698 {
1699         struct obd_device *obd;
1700         struct lmv_obd *lmv;
1701         ENTRY;
1702
1703         obd = class_exp2obd(exp);
1704         if (obd == NULL) {
1705                 CDEBUG(D_IOCTL, "invalid client cookie "LPX64"\n",
1706                        exp->exp_handle.h_cookie);
1707                 RETURN(-EINVAL);
1708         }
1709         lmv = &obd->u.lmv;
1710
1711         if (keylen >= strlen("inter_mds") && strcmp(key, "inter_mds") == 0) {
1712                 lmv->server_timeout = 1;
1713                 lmv_set_timeouts(obd);
1714                 RETURN(0);
1715         }
1716         
1717         RETURN(-EINVAL);
1718 }
1719
1720 int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
1721                struct lov_stripe_md *lsm)
1722 {
1723         struct obd_device *obd = class_exp2obd(exp);
1724         struct lmv_obd *lmv = &obd->u.lmv;
1725         int mea_size;
1726         ENTRY;
1727
1728         mea_size = sizeof(struct ll_fid) * 
1729                 lmv->desc.ld_tgt_count + sizeof(struct mea);
1730         if (!lmmp)
1731                 RETURN(mea_size);
1732
1733         if (*lmmp && !lsm) {
1734                 OBD_FREE(*lmmp, mea_size);
1735                 *lmmp = NULL;
1736                 RETURN(0);
1737         }
1738
1739         if (*lmmp == NULL) {
1740                 OBD_ALLOC(*lmmp, mea_size);
1741                 if (*lmmp == NULL)
1742                         RETURN(-ENOMEM);
1743         }
1744
1745         if (!lsm)
1746                 RETURN(mea_size);
1747
1748 #warning "MEA packing/convertation must be here! -bzzz"
1749         memcpy(*lmmp, lsm, mea_size);
1750         RETURN(mea_size);
1751 }
1752
1753 int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **mem_tgt,
1754                  struct lov_mds_md *disk_src, int mdsize)
1755 {
1756         struct obd_device *obd = class_exp2obd(exp);
1757         struct lmv_obd *lmv = &obd->u.lmv;
1758         struct mea **tmea = (struct mea **) mem_tgt;
1759         struct mea *mea = (void *) disk_src;
1760         int mea_size;
1761         ENTRY;
1762
1763         mea_size = sizeof(struct ll_fid) * 
1764                 lmv->desc.ld_tgt_count + sizeof(struct mea);
1765         if (mem_tgt == NULL)
1766                 return mea_size;
1767
1768         if (*mem_tgt != NULL && disk_src == NULL) {
1769                 OBD_FREE(*tmea, mea_size);
1770                 RETURN(0);
1771         }
1772
1773         LASSERT(mea_size == mdsize);
1774
1775         OBD_ALLOC(*tmea, mea_size);
1776         if (*tmea == NULL)
1777                 RETURN(-ENOMEM);
1778
1779         if (!disk_src)
1780                 RETURN(mea_size);
1781
1782 #warning "MEA unpacking/convertation must be here! -bzzz"
1783         memcpy(*tmea, mea, mdsize);
1784         RETURN(mea_size);
1785 }
1786
1787 int lmv_brw(int rw, struct obd_export *exp, struct obdo *oa,
1788             struct lov_stripe_md *ea, obd_count oa_bufs,
1789             struct brw_page *pgarr, struct obd_trans_info *oti)
1790 {
1791         struct obd_device *obd = exp->exp_obd;
1792         struct lmv_obd *lmv = &obd->u.lmv;
1793         struct mea *mea = (struct mea *) ea;
1794         int err;
1795       
1796         LASSERT(oa != NULL);
1797         LASSERT(ea != NULL);
1798         LASSERT(pgarr != NULL);
1799         LASSERT(oa->o_mds < lmv->desc.ld_tgt_count);
1800
1801         oa->o_gr = mea->mea_fids[oa->o_mds].generation;
1802         oa->o_id = mea->mea_fids[oa->o_mds].id;
1803         oa->o_valid =  OBD_MD_FLID | OBD_MD_FLGROUP;
1804         err = obd_brw(rw, lmv->tgts[oa->o_mds].ltd_exp, oa,
1805                       NULL, oa_bufs, pgarr, oti);
1806         RETURN(err);
1807 }
1808
1809 struct obd_ops lmv_obd_ops = {
1810         .o_owner                = THIS_MODULE,
1811         .o_attach               = lmv_attach,
1812         .o_detach               = lmv_detach,
1813         .o_setup                = lmv_setup,
1814         .o_cleanup              = lmv_cleanup,
1815         .o_connect              = lmv_connect,
1816         .o_disconnect           = lmv_disconnect,
1817         .o_statfs               = lmv_statfs,
1818         .o_llog_init            = lmv_llog_init,
1819         .o_llog_finish          = lmv_llog_finish,
1820         .o_get_info             = lmv_get_info,
1821         .o_set_info             = lmv_set_info,
1822         .o_create               = lmv_obd_create,
1823         .o_packmd               = lmv_packmd,
1824         .o_unpackmd             = lmv_unpackmd,
1825         .o_brw                  = lmv_brw,
1826         .o_init_ea_size         = lmv_init_ea_size,
1827         .o_notify               = lmv_notify,
1828         .o_iocontrol            = lmv_iocontrol,
1829 };
1830
1831 struct md_ops lmv_md_ops = {
1832         .m_getstatus            = lmv_getstatus,
1833         .m_getattr              = lmv_getattr,
1834         .m_change_cbdata        = lmv_change_cbdata,
1835         .m_change_cbdata_name   = lmv_change_cbdata_name,
1836         .m_close                = lmv_close,
1837         .m_create               = lmv_create,
1838         .m_done_writing         = lmv_done_writing,
1839         .m_enqueue              = lmv_enqueue,
1840         .m_getattr_name         = lmv_getattr_name,
1841         .m_intent_lock          = lmv_intent_lock,
1842         .m_link                 = lmv_link,
1843         .m_rename               = lmv_rename,
1844         .m_setattr              = lmv_setattr,
1845         .m_sync                 = lmv_sync,
1846         .m_readpage             = lmv_readpage,
1847         .m_unlink               = lmv_unlink,
1848         .m_get_real_obd         = lmv_get_real_obd,
1849         .m_valid_attrs          = lmv_valid_attrs,
1850         .m_delete_object        = lmv_delete_object,
1851 };
1852
1853 int __init lmv_init(void)
1854 {
1855         struct lprocfs_static_vars lvars;
1856         int rc;
1857
1858         lprocfs_init_vars(lmv, &lvars);
1859         rc = class_register_type(&lmv_obd_ops, &lmv_md_ops,
1860                                  lvars.module_vars, OBD_LMV_DEVICENAME);
1861         RETURN(rc);
1862 }
1863
1864 #ifdef __KERNEL__
1865 static void lmv_exit(void)
1866 {
1867         class_unregister_type(OBD_LMV_DEVICENAME);
1868 }
1869
1870 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1871 MODULE_DESCRIPTION("Lustre Logical Metadata Volume OBD driver");
1872 MODULE_LICENSE("GPL");
1873
1874 module_init(lmv_init);
1875 module_exit(lmv_exit);
1876 #endif