Whamcloud - gitweb
67240f39247e04f650c190b22813aaa6dd8cfee1
[fs/lustre-release.git] / lustre / osd-zfs / osd_handler.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19  *
20  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21  * CA 95054 USA or visit www.sun.com if you need additional information or
22  * have any questions.
23  *
24  * GPL HEADER END
25  */
26 /*
27  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
28  * Use is subject to license terms.
29  */
30 /*
31  * Copyright (c) 2011, 2012 Whamcloud, Inc.
32  * Use is subject to license terms.
33  *
34  */
35 /*
36  * This file is part of Lustre, http://www.lustre.org/
37  * Lustre is a trademark of Sun Microsystems, Inc.
38  *
39  * lustre/osd-zfs/osd_handler.c
40  * Top-level entry points into osd module
41  *
42  * Author: Alex Zhuravlev <bzzz@whamcloud.com>
43  * Author: Mike Pershin <tappro@whamcloud.com>
44  * Author: Johann Lombardi <johann@whamcloud.com>
45  */
46
47 #ifndef EXPORT_SYMTAB
48 # define EXPORT_SYMTAB
49 #endif
50 #define DEBUG_SUBSYSTEM S_OSD
51
52 #include <lustre_ver.h>
53 #include <libcfs/libcfs.h>
54 #include <obd_support.h>
55 #include <lustre_net.h>
56 #include <obd.h>
57 #include <obd_class.h>
58 #include <lustre_disk.h>
59 #include <lustre_fid.h>
60
61 #include "osd_internal.h"
62
63 #include <sys/dnode.h>
64 #include <sys/dbuf.h>
65 #include <sys/spa.h>
66 #include <sys/stat.h>
67 #include <sys/zap.h>
68 #include <sys/spa_impl.h>
69 #include <sys/zfs_znode.h>
70 #include <sys/dmu_tx.h>
71 #include <sys/dmu_objset.h>
72 #include <sys/dsl_prop.h>
73 #include <sys/sa_impl.h>
74 #include <sys/txg.h>
75
76 struct lu_context_key   osd_key;
77
78 static char *root_tag = "osd_mount, rootdb";
79
80 /* Slab for OSD object allocation */
81 cfs_mem_cache_t *osd_object_kmem;
82
83 static struct lu_kmem_descr osd_caches[] = {
84         {
85                 .ckd_cache = &osd_object_kmem,
86                 .ckd_name  = "zfs_osd_obj",
87                 .ckd_size  = sizeof(struct osd_object)
88         },
89         {
90                 .ckd_cache = NULL
91         }
92 };
93
94 static void arc_prune_func(int64_t bytes, void *private)
95 {
96         struct osd_device *od = private;
97         struct lu_site    *site = &od->od_site;
98         struct lu_env      env;
99         int rc;
100
101         rc = lu_env_init(&env, LCT_SHRINKER);
102         if (rc) {
103                 CERROR("%s: can't initialize shrinker env: rc = %d\n",
104                        od->od_svname, rc);
105                 return;
106         }
107
108         lu_site_purge(&env, site, (bytes >> 10));
109
110         lu_env_fini(&env);
111 }
112
113 /*
114  * Concurrency: doesn't access mutable data
115  */
116 static int osd_root_get(const struct lu_env *env,
117                         struct dt_device *dev, struct lu_fid *f)
118 {
119         lu_local_obj_fid(f, OSD_FS_ROOT_OID);
120         return 0;
121 }
122
123 /*
124  * OSD object methods.
125  */
126
127 /*
128  * Concurrency: shouldn't matter.
129  */
130 static void osd_trans_commit_cb(void *cb_data, int error)
131 {
132         struct osd_thandle      *oh = cb_data;
133         struct thandle          *th = &oh->ot_super;
134         struct lu_device        *lud = &th->th_dev->dd_lu_dev;
135         struct dt_txn_commit_cb *dcb, *tmp;
136
137         ENTRY;
138
139         if (error) {
140                 if (error == ECANCELED)
141                         CWARN("%s: transaction @0x%p was aborted\n",
142                               osd_dt_dev(th->th_dev)->od_svname, th);
143                 else
144                         CERROR("%s: transaction @0x%p commit error: rc = %d\n",
145                                 osd_dt_dev(th->th_dev)->od_svname, th, error);
146         }
147
148         dt_txn_hook_commit(th);
149
150         /* call per-transaction callbacks if any */
151         cfs_list_for_each_entry_safe(dcb, tmp, &oh->ot_dcb_list, dcb_linkage)
152                 dcb->dcb_func(NULL, th, dcb, error);
153
154         lu_device_put(lud);
155         th->th_dev = NULL;
156         lu_context_exit(&th->th_ctx);
157         lu_context_fini(&th->th_ctx);
158         OBD_FREE_PTR(oh);
159
160         EXIT;
161 }
162
163 static int osd_trans_cb_add(struct thandle *th, struct dt_txn_commit_cb *dcb)
164 {
165         struct osd_thandle *oh;
166
167         oh = container_of0(th, struct osd_thandle, ot_super);
168         cfs_list_add(&dcb->dcb_linkage, &oh->ot_dcb_list);
169
170         return 0;
171 }
172
173 /*
174  * Concurrency: shouldn't matter.
175  */
176 static int osd_trans_start(const struct lu_env *env, struct dt_device *d,
177                            struct thandle *th)
178 {
179         struct osd_thandle      *oh;
180         int                     rc;
181         ENTRY;
182
183         oh = container_of0(th, struct osd_thandle, ot_super);
184         LASSERT(oh);
185         LASSERT(oh->ot_tx);
186
187         rc = dt_txn_hook_start(env, d, th);
188         if (rc != 0)
189                 RETURN(rc);
190
191         if (oh->ot_write_commit && OBD_FAIL_CHECK(OBD_FAIL_OST_MAPBLK_ENOSPC))
192                 /* Unlike ldiskfs, ZFS checks for available space and returns
193                  * -ENOSPC when assigning txg */
194                 RETURN(-ENOSPC);
195
196         rc = -dmu_tx_assign(oh->ot_tx, TXG_WAIT);
197         if (unlikely(rc != 0)) {
198                 struct osd_device *osd = osd_dt_dev(d);
199                 /* dmu will call commit callback with error code during abort */
200                 if (!lu_device_is_md(&d->dd_lu_dev) && rc == -ENOSPC)
201                         CERROR("%s: failed to start transaction due to ENOSPC. "
202                                "Metadata overhead is underestimated or "
203                                "grant_ratio is too low.\n",
204                                osd->od_dt_dev.dd_lu_dev.ld_obd->obd_name);
205                 else
206                         CERROR("%s: can't assign tx: rc = %d\n",
207                                osd->od_dt_dev.dd_lu_dev.ld_obd->obd_name, rc);
208         } else {
209                 /* add commit callback */
210                 dmu_tx_callback_register(oh->ot_tx, osd_trans_commit_cb, oh);
211                 oh->ot_assigned = 1;
212                 lu_context_init(&th->th_ctx, th->th_tags);
213                 lu_context_enter(&th->th_ctx);
214                 lu_device_get(&d->dd_lu_dev);
215         }
216
217         RETURN(rc);
218 }
219
220 /*
221  * Concurrency: shouldn't matter.
222  */
223 static int osd_trans_stop(const struct lu_env *env, struct thandle *th)
224 {
225         struct osd_device       *osd = osd_dt_dev(th->th_dev);
226         struct osd_thandle      *oh;
227         uint64_t                 txg;
228         int                      rc;
229         ENTRY;
230
231         oh = container_of0(th, struct osd_thandle, ot_super);
232
233         if (oh->ot_assigned == 0) {
234                 LASSERT(oh->ot_tx);
235                 dmu_tx_abort(oh->ot_tx);
236                 osd_object_sa_dirty_rele(oh);
237                 OBD_FREE_PTR(oh);
238                 RETURN(0);
239         }
240
241         rc = dt_txn_hook_stop(env, th);
242         if (rc != 0)
243                 CDEBUG(D_OTHER, "%s: transaction hook failed: rc = %d\n",
244                        osd->od_svname, rc);
245
246         LASSERT(oh->ot_tx);
247         txg = oh->ot_tx->tx_txg;
248
249         osd_object_sa_dirty_rele(oh);
250         dmu_tx_commit(oh->ot_tx);
251
252         if (th->th_sync)
253                 txg_wait_synced(dmu_objset_pool(osd->od_objset.os), txg);
254
255         RETURN(rc);
256 }
257
258 static struct thandle *osd_trans_create(const struct lu_env *env,
259                                         struct dt_device *dt)
260 {
261         struct osd_device       *osd = osd_dt_dev(dt);
262         struct osd_thandle      *oh;
263         struct thandle          *th;
264         dmu_tx_t                *tx;
265         ENTRY;
266
267         tx = dmu_tx_create(osd->od_objset.os);
268         if (tx == NULL)
269                 RETURN(ERR_PTR(-ENOMEM));
270
271         /* alloc callback data */
272         OBD_ALLOC_PTR(oh);
273         if (oh == NULL) {
274                 dmu_tx_abort(tx);
275                 RETURN(ERR_PTR(-ENOMEM));
276         }
277
278         oh->ot_tx = tx;
279         CFS_INIT_LIST_HEAD(&oh->ot_dcb_list);
280         CFS_INIT_LIST_HEAD(&oh->ot_sa_list);
281         cfs_sema_init(&oh->ot_sa_lock, 1);
282         th = &oh->ot_super;
283         th->th_dev = dt;
284         th->th_result = 0;
285         th->th_tags = LCT_TX_HANDLE;
286         RETURN(th);
287 }
288
289 /*
290  * Concurrency: shouldn't matter.
291  */
292 int osd_statfs(const struct lu_env *env, struct dt_device *d,
293                struct obd_statfs *osfs)
294 {
295         struct osd_device *osd = osd_dt_dev(d);
296         int                rc;
297         ENTRY;
298
299         rc = udmu_objset_statfs(&osd->od_objset, osfs);
300         if (rc)
301                 RETURN(rc);
302         osfs->os_bavail -= min_t(obd_size,
303                                  OSD_GRANT_FOR_LOCAL_OIDS / osfs->os_bsize,
304                                  osfs->os_bavail);
305         RETURN(0);
306 }
307
308 /*
309  * Concurrency: doesn't access mutable data.
310  */
311 static void osd_conf_get(const struct lu_env *env,
312                          const struct dt_device *dev,
313                          struct dt_device_param *param)
314 {
315         /*
316          * XXX should be taken from not-yet-existing fs abstraction layer.
317          */
318         param->ddp_max_name_len  = MAXNAMELEN;
319         param->ddp_max_nlink     = 1 << 31; /* it's 8byte on a disk */
320         param->ddp_block_shift   = 12; /* XXX */
321         param->ddp_mount_type    = LDD_MT_ZFS;
322
323         param->ddp_mntopts        = MNTOPT_USERXATTR | MNTOPT_ACL;
324         param->ddp_max_ea_size    = DXATTR_MAX_ENTRY_SIZE;
325
326         /* for maxbytes, report same value as ZPL */
327         param->ddp_maxbytes      = MAX_LFS_FILESIZE;
328
329         /* Default reserved fraction of the available space that should be kept
330          * for error margin. Unfortunately, there are many factors that can
331          * impact the overhead with zfs, so let's be very cautious for now and
332          * reserve 20% of the available space which is not given out as grant.
333          * This tunable can be changed on a live system via procfs if needed. */
334         param->ddp_grant_reserved = 20;
335
336         /* inodes are dynamically allocated, so we report the per-inode space
337          * consumption to upper layers. This static value is not really accurate
338          * and we should use the same logic as in udmu_objset_statfs() to
339          * estimate the real size consumed by an object */
340         param->ddp_inodespace = OSD_DNODE_EST_COUNT;
341         /* per-fragment overhead to be used by the client code */
342         param->ddp_grant_frag = udmu_blk_insert_cost();
343 }
344
345 /*
346  * Concurrency: shouldn't matter.
347  */
348 static int osd_sync(const struct lu_env *env, struct dt_device *d)
349 {
350         struct osd_device  *osd = osd_dt_dev(d);
351         CDEBUG(D_HA, "syncing OSD %s\n", LUSTRE_OSD_ZFS_NAME);
352         txg_wait_synced(dmu_objset_pool(osd->od_objset.os), 0ULL);
353         return 0;
354 }
355
356 static int osd_commit_async(const struct lu_env *env, struct dt_device *dev)
357 {
358         struct osd_device *osd = osd_dt_dev(dev);
359         tx_state_t        *tx = &dmu_objset_pool(osd->od_objset.os)->dp_tx;
360         uint64_t           txg;
361
362         txg = tx->tx_open_txg + 1;
363         if (tx->tx_quiesce_txg_waiting < txg) {
364                 tx->tx_quiesce_txg_waiting = txg;
365                 cv_broadcast(&tx->tx_quiesce_more_cv);
366         }
367         mutex_exit(&tx->tx_sync_lock);
368
369         return 0;
370 }
371
372 /*
373  * Concurrency: shouldn't matter.
374  */
375 static int osd_ro(const struct lu_env *env, struct dt_device *d)
376 {
377         struct osd_device  *osd = osd_dt_dev(d);
378         ENTRY;
379
380         CERROR("%s: *** setting device %s read-only ***\n",
381                osd->od_svname, LUSTRE_OSD_ZFS_NAME);
382         osd->od_rdonly = 1;
383         spa_freeze(dmu_objset_spa(osd->od_objset.os));
384
385         RETURN(0);
386 }
387
388 /*
389  * Concurrency: serialization provided by callers.
390  */
391 static int osd_init_capa_ctxt(const struct lu_env *env, struct dt_device *d,
392                               int mode, unsigned long timeout, __u32 alg,
393                               struct lustre_capa_key *keys)
394 {
395         struct osd_device *dev = osd_dt_dev(d);
396         ENTRY;
397
398         dev->od_fl_capa = mode;
399         dev->od_capa_timeout = timeout;
400         dev->od_capa_alg = alg;
401         dev->od_capa_keys = keys;
402
403         RETURN(0);
404 }
405
406 static char *osd_label_get(const struct lu_env *env, const struct dt_device *d)
407 {
408         struct osd_device *dev = osd_dt_dev(d);
409         int rc;
410         ENTRY;
411
412         rc = -udmu_userprop_get_str(&dev->od_objset, DMU_OSD_SVNAME,
413                                     dev->od_svname, sizeof(dev->od_svname));
414         if (rc != 0) {
415                 if (rc == -EOVERFLOW)
416                         CWARN("%s: buffer too small\n", dev->od_svname);
417                 RETURN(NULL);
418         }
419
420         RETURN(&dev->od_svname[0]);
421 }
422
423 static struct dt_device_operations osd_dt_ops = {
424         .dt_root_get            = osd_root_get,
425         .dt_statfs              = osd_statfs,
426         .dt_trans_create        = osd_trans_create,
427         .dt_trans_start         = osd_trans_start,
428         .dt_trans_stop          = osd_trans_stop,
429         .dt_trans_cb_add        = osd_trans_cb_add,
430         .dt_conf_get            = osd_conf_get,
431         .dt_sync                = osd_sync,
432         .dt_commit_async        = osd_commit_async,
433         .dt_ro                  = osd_ro,
434         .dt_init_capa_ctxt      = osd_init_capa_ctxt,
435 };
436
437 /*
438  * DMU OSD device type methods
439  */
440 static int osd_type_init(struct lu_device_type *t)
441 {
442         LU_CONTEXT_KEY_INIT(&osd_key);
443         return lu_context_key_register(&osd_key);
444 }
445
446 static void osd_type_fini(struct lu_device_type *t)
447 {
448         lu_context_key_degister(&osd_key);
449 }
450
451 static void *osd_key_init(const struct lu_context *ctx,
452                           struct lu_context_key *key)
453 {
454         struct osd_thread_info *info;
455
456         OBD_ALLOC_PTR(info);
457         if (info != NULL)
458                 info->oti_env = container_of(ctx, struct lu_env, le_ctx);
459         else
460                 info = ERR_PTR(-ENOMEM);
461         return info;
462 }
463
464 static void osd_key_fini(const struct lu_context *ctx,
465                          struct lu_context_key *key, void *data)
466 {
467         struct osd_thread_info *info = data;
468
469         OBD_FREE_PTR(info);
470 }
471
472 static void osd_key_exit(const struct lu_context *ctx,
473                          struct lu_context_key *key, void *data)
474 {
475         struct osd_thread_info *info = data;
476
477         memset(info, 0, sizeof(*info));
478 }
479
480 struct lu_context_key osd_key = {
481         .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD | LCT_MG_THREAD | LCT_LOCAL,
482         .lct_init = osd_key_init,
483         .lct_fini = osd_key_fini,
484         .lct_exit = osd_key_exit
485 };
486
487 static int osd_shutdown(const struct lu_env *env, struct osd_device *o)
488 {
489         ENTRY;
490
491         /* shutdown quota slave instance associated with the device */
492         if (o->od_quota_slave != NULL) {
493                 qsd_fini(env, o->od_quota_slave);
494                 o->od_quota_slave = NULL;
495         }
496
497         RETURN(0);
498 }
499
500 static int osd_mount(const struct lu_env *env,
501                      struct osd_device *o, struct lustre_cfg *cfg)
502 {
503         char                            *dev  = lustre_cfg_string(cfg, 0);
504         struct lustre_mount_info        *lmi;
505         struct lustre_sb_info           *lsi;
506         dmu_buf_t                       *rootdb;
507         char                            *label;
508         int                              rc;
509         ENTRY;
510
511         if (o->od_objset.os != NULL)
512                 RETURN(0);
513
514         lmi = server_get_mount(dev);
515         if (lmi == NULL) {
516                 CERROR("Unknown mount point: '%s'\n", dev);
517                 RETURN(-ENODEV);
518         }
519
520         lsi = s2lsi(lmi->lmi_sb);
521         dev = lsi->lsi_lmd->lmd_dev;
522
523         if (strlen(dev) >= sizeof(o->od_mntdev))
524                 RETURN(-E2BIG);
525
526         strcpy(o->od_mntdev, dev);
527
528         rc = -udmu_objset_open(o->od_mntdev, &o->od_objset);
529         if (rc) {
530                 CERROR("can't open objset %s: %d\n", o->od_mntdev, rc);
531                 RETURN(rc);
532         }
533
534         rc = __osd_obj2dbuf(env, o->od_objset.os, o->od_objset.root,
535                                 &rootdb, root_tag);
536         if (rc) {
537                 CERROR("udmu_obj2dbuf() failed with error %d\n", rc);
538                 udmu_objset_close(&o->od_objset);
539                 RETURN(rc);
540         }
541
542         o->od_root = rootdb->db_object;
543         sa_buf_rele(rootdb, root_tag);
544
545         /* 1. initialize oi before any file create or file open */
546         rc = osd_oi_init(env, o);
547         if (rc)
548                 GOTO(err, rc);
549
550         label = osd_label_get(env, &o->od_dt_dev);
551         if (label == NULL)
552                 GOTO(err, rc = -ENODEV);
553
554         /* Use our own ZAP for inode accounting by default, this can be changed
555          * via procfs to estimate the inode usage from the block usage */
556         o->od_quota_iused_est = 0;
557
558         rc = osd_procfs_init(o, label);
559         if (rc)
560                 GOTO(err, rc);
561
562         o->arc_prune_cb = arc_add_prune_callback(arc_prune_func, o);
563
564 err:
565         RETURN(rc);
566 }
567
568 static void osd_umount(const struct lu_env *env, struct osd_device *o)
569 {
570         ENTRY;
571
572         if (cfs_atomic_read(&o->od_zerocopy_alloc))
573                 CERROR("%s: lost %d allocated page(s)\n", o->od_svname,
574                        cfs_atomic_read(&o->od_zerocopy_alloc));
575         if (cfs_atomic_read(&o->od_zerocopy_loan))
576                 CERROR("%s: lost %d loaned abuf(s)\n", o->od_svname,
577                        cfs_atomic_read(&o->od_zerocopy_loan));
578         if (cfs_atomic_read(&o->od_zerocopy_pin))
579                 CERROR("%s: lost %d pinned dbuf(s)\n", o->od_svname,
580                        cfs_atomic_read(&o->od_zerocopy_pin));
581
582         if (o->od_objset.os != NULL)
583                 udmu_objset_close(&o->od_objset);
584
585         EXIT;
586 }
587
588 static int osd_device_init0(const struct lu_env *env,
589                             struct osd_device *o,
590                             struct lustre_cfg *cfg)
591 {
592         struct lu_device        *l = osd2lu_dev(o);
593         int                      rc;
594
595         /* if the module was re-loaded, env can loose its keys */
596         rc = lu_env_refill((struct lu_env *) env);
597         if (rc)
598                 GOTO(out, rc);
599
600         l->ld_ops = &osd_lu_ops;
601         o->od_dt_dev.dd_ops = &osd_dt_ops;
602
603         o->od_capa_hash = init_capa_hash();
604         if (o->od_capa_hash == NULL)
605                 GOTO(out, rc = -ENOMEM);
606
607 out:
608         RETURN(rc);
609 }
610
611 static struct lu_device *osd_device_alloc(const struct lu_env *env,
612                                           struct lu_device_type *t,
613                                           struct lustre_cfg *cfg)
614 {
615         struct osd_device       *o;
616         int                      rc;
617
618         OBD_ALLOC_PTR(o);
619         if (o == NULL)
620                 return ERR_PTR(-ENOMEM);
621
622         rc = dt_device_init(&o->od_dt_dev, t);
623         if (rc == 0) {
624                 rc = osd_device_init0(env, o, cfg);
625                 if (rc)
626                         dt_device_fini(&o->od_dt_dev);
627         }
628
629         if (unlikely(rc != 0))
630                 OBD_FREE_PTR(o);
631
632         return rc == 0 ? osd2lu_dev(o) : ERR_PTR(rc);
633 }
634
635 static struct lu_device *osd_device_free(const struct lu_env *env,
636                                          struct lu_device *d)
637 {
638         struct osd_device *o = osd_dev(d);
639         ENTRY;
640
641         cleanup_capa_hash(o->od_capa_hash);
642         /* XXX: make osd top device in order to release reference */
643         /*d->ld_site->ls_top_dev = d;
644         lu_site_purge(env, d->ld_site, -1);
645         lu_site_fini(&o->od_site);*/
646         dt_device_fini(&o->od_dt_dev);
647         OBD_FREE_PTR(o);
648
649         RETURN (NULL);
650 }
651
652 static struct lu_device *osd_device_fini(const struct lu_env *env,
653                                          struct lu_device *d)
654 {
655         struct osd_device        *o = osd_dev(d);
656         struct lustre_mount_info *lmi;
657         int rc;
658         ENTRY;
659
660
661         osd_oi_fini(env, o);
662
663         if (o->od_objset.os) {
664                 arc_remove_prune_callback(o->arc_prune_cb);
665                 o->arc_prune_cb = NULL;
666                 osd_sync(env, lu2dt_dev(d));
667                 txg_wait_callbacks(spa_get_dsl(dmu_objset_spa(o->od_objset.os)));
668         }
669
670         rc = osd_procfs_fini(o);
671         if (rc) {
672                 CERROR("proc fini error %d\n", rc);
673                 RETURN(ERR_PTR(rc));
674         }
675
676         if (o->od_objset.os)
677                 osd_umount(env, o);
678
679         lmi = server_get_mount_2(o->od_svname);
680         LASSERT(lmi);
681         server_put_mount(lmi->lmi_name, lmi->lmi_mnt);
682
683         RETURN(NULL);
684 }
685
686 static int osd_device_init(const struct lu_env *env, struct lu_device *d,
687                            const char *name, struct lu_device *next)
688 {
689         return 0;
690 }
691
692 /*
693  * To be removed, setup is performed by osd_device_{init,alloc} and
694  * cleanup is performed by osd_device_{fini,free).
695  */
696 static int osd_process_config(const struct lu_env *env,
697                               struct lu_device *d, struct lustre_cfg *cfg)
698 {
699         struct osd_device       *o = osd_dev(d);
700         int                      err;
701         ENTRY;
702
703         switch(cfg->lcfg_command) {
704         case LCFG_SETUP:
705                 err = osd_mount(env, o, cfg);
706                 break;
707         case LCFG_CLEANUP:
708                 err = osd_shutdown(env, o);
709                 break;
710         default:
711                 err = -ENOTTY;
712         }
713
714         RETURN(err);
715 }
716
717 static int osd_recovery_complete(const struct lu_env *env, struct lu_device *d)
718 {
719         ENTRY;
720         RETURN(0);
721 }
722
723 static int osd_prepare(const struct lu_env *env, struct lu_device *pdev,
724                        struct lu_device *dev)
725 {
726         struct osd_device       *osd = osd_dev(dev);
727         int                      rc = 0;
728         ENTRY;
729
730         /* initialize quota slave instance */
731         osd->od_quota_slave = qsd_init(env, osd->od_svname, &osd->od_dt_dev,
732                                        osd->od_proc_entry);
733         if (IS_ERR(osd->od_quota_slave)) {
734                 rc = PTR_ERR(osd->od_quota_slave);
735                 osd->od_quota_slave = NULL;
736         }
737
738         RETURN(rc);
739 }
740
741 struct lu_device_operations osd_lu_ops = {
742         .ldo_object_alloc       = osd_object_alloc,
743         .ldo_process_config     = osd_process_config,
744         .ldo_recovery_complete  = osd_recovery_complete,
745         .ldo_prepare            = osd_prepare,
746 };
747
748 static void osd_type_start(struct lu_device_type *t)
749 {
750 }
751
752 static void osd_type_stop(struct lu_device_type *t)
753 {
754 }
755
756 static struct lu_device_type_operations osd_device_type_ops = {
757         .ldto_init              = osd_type_init,
758         .ldto_fini              = osd_type_fini,
759
760         .ldto_start             = osd_type_start,
761         .ldto_stop              = osd_type_stop,
762
763         .ldto_device_alloc      = osd_device_alloc,
764         .ldto_device_free       = osd_device_free,
765
766         .ldto_device_init       = osd_device_init,
767         .ldto_device_fini       = osd_device_fini
768 };
769
770 static struct lu_device_type osd_device_type = {
771         .ldt_tags     = LU_DEVICE_DT,
772         .ldt_name     = LUSTRE_OSD_ZFS_NAME,
773         .ldt_ops      = &osd_device_type_ops,
774         .ldt_ctx_tags = LCT_LOCAL
775 };
776
777
778 static struct obd_ops osd_obd_device_ops = {
779         .o_owner       = THIS_MODULE,
780 };
781
782 int __init osd_init(void)
783 {
784         int rc;
785
786         rc = osd_options_init();
787         if (rc)
788                 return rc;
789
790         rc = lu_kmem_init(osd_caches);
791         if (rc)
792                 return rc;
793
794         rc = class_register_type(&osd_obd_device_ops, NULL,
795                                  lprocfs_osd_module_vars,
796                                  LUSTRE_OSD_ZFS_NAME, &osd_device_type);
797         if (rc)
798                 lu_kmem_fini(osd_caches);
799         return rc;
800 }
801
802 void __exit osd_exit(void)
803 {
804         class_unregister_type(LUSTRE_OSD_ZFS_NAME);
805         lu_kmem_fini(osd_caches);
806 }
807
808 extern unsigned int osd_oi_count;
809 CFS_MODULE_PARM(osd_oi_count, "i", int, 0444,
810                 "Number of Object Index containers to be created, "
811                 "it's only valid for new filesystem.");
812
813 MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
814 MODULE_DESCRIPTION("Lustre Object Storage Device ("LUSTRE_OSD_ZFS_NAME")");
815 MODULE_LICENSE("GPL");
816
817 cfs_module(osd, LUSTRE_VERSION_STRING, osd_init, osd_exit);