+static int osd_device_init0(const struct lu_env *env,
+ struct osd_device *o,
+ struct lustre_cfg *cfg)
+{
+ struct lu_device *l = osd2lu_dev(o);
+ struct osd_thread_info *info;
+ int rc;
+
+ /* if the module was re-loaded, env can loose its keys */
+ rc = lu_env_refill((struct lu_env *) env);
+ if (rc)
+ GOTO(out, rc);
+ info = osd_oti_get(env);
+ LASSERT(info);
+
+ l->ld_ops = &osd_lu_ops;
+ o->od_dt_dev.dd_ops = &osd_dt_ops;
+
+ cfs_spin_lock_init(&o->od_osfs_lock);
+ cfs_mutex_init(&o->od_otable_mutex);
+ o->od_osfs_age = cfs_time_shift_64(-1000);
+
+ o->od_capa_hash = init_capa_hash();
+ if (o->od_capa_hash == NULL)
+ GOTO(out, rc = -ENOMEM);
+
+ o->od_read_cache = 1;
+ o->od_writethrough_cache = 1;
+
+ rc = osd_mount(env, o, cfg);
+ if (rc)
+ GOTO(out_capa, rc);
+
+ /* setup scrub, including OI files initialization */
+ rc = osd_scrub_setup(env, o);
+ if (rc < 0)
+ GOTO(out_mnt, rc);
+
+ strncpy(o->od_svname, lustre_cfg_string(cfg, 4),
+ sizeof(o->od_svname) - 1);
+
+ if (strstr(o->od_svname, "-OST")) {
+ rc = osd_compat_init(o);
+ if (rc != 0)
+ GOTO(out_mnt, rc);
+ }
+
+ rc = lu_site_init(&o->od_site, l);
+ if (rc)
+ GOTO(out_compat, rc);
+
+ rc = lu_site_init_finish(&o->od_site);
+ if (rc)
+ GOTO(out_compat, rc);
+
+ rc = osd_procfs_init(o, o->od_svname);
+ if (rc != 0) {
+ CERROR("%s: can't initialize procfs: rc = %d\n",
+ o->od_svname, rc);
+ GOTO(out_compat, rc);
+ }
+
+ LASSERT(l->ld_site->ls_linkage.next && l->ld_site->ls_linkage.prev);
+
+ RETURN(0);
+out_compat:
+ osd_compat_fini(o);
+out_mnt:
+ osd_oi_fini(info, o);
+ osd_shutdown(env, o);
+ mntput(o->od_mnt);
+ o->od_mnt = NULL;
+out_capa:
+ cleanup_capa_hash(o->od_capa_hash);
+out:
+ RETURN(rc);
+}
+