4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA
24 * Copyright (c) 2012 Intel, Inc.
25 * Use is subject to license terms.
27 * lustre/osp/osp_ost.c
29 * OSP on OST for communicating with MDT0
31 * Author: <di.wang@whamcloud.com>
34 # define EXPORT_SYMTAB
36 #define DEBUG_SUBSYSTEM S_OST
38 #include <obd_class.h>
39 #include <lustre_param.h>
40 #include <lustre_log.h>
42 #include "osp_internal.h"
44 static int osp_name2fsname(char *ospname, char *fsname)
48 LASSERT(ospname != NULL);
49 LASSERT(fsname != NULL);
50 if (!is_osp_on_ost(ospname))
53 sprintf(fsname, "-%s-", LUSTRE_OSP_NAME);
55 ptr = strstr(ospname, fsname);
57 strncpy(fsname, ospname, ptr - ospname);
58 fsname[ptr - ospname] = '\0';
63 static int osp_setup_for_ost(const struct lu_env *env, struct osp_device *osp,
66 struct lustre_cfg_bufs *bufs = NULL;
67 struct lustre_cfg *lcfg = NULL;
68 char *ospname = osp->opd_obd->obd_name;
70 char *server_uuid = NULL;
72 struct obd_import *imp;
80 OBD_ALLOC(fsname, strlen(ospname));
82 GOTO(out, rc = -ENOMEM);
84 rc = osp_name2fsname(ospname, fsname);
86 CERROR("%s: name change error: rc %d\n", ospname, rc);
90 OBD_ALLOC(server_uuid, strlen(fsname) + 15);
91 if (server_uuid == NULL)
92 GOTO(out, rc = -ENOMEM);
94 sprintf(server_uuid, "%s-MDT0000_UUID", fsname);
95 lustre_cfg_bufs_reset(bufs, ospname);
96 lustre_cfg_bufs_set_string(bufs, 1, server_uuid);
97 lustre_cfg_bufs_set_string(bufs, 2, nidstring);
98 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
100 GOTO(out, rc = -ENOMEM);
102 rc = client_obd_setup(osp->opd_obd, lcfg);
104 CERROR("%s: client obd setup error: rc = %d\n",
105 osp->opd_obd->obd_name, rc);
109 imp = osp->opd_obd->u.cli.cl_import;
110 rc = ptlrpc_init_import(imp);
114 ll_generate_random_uuid(uuid);
115 class_uuid_unparse(uuid, &osp->opd_cluuid);
119 if (server_uuid != NULL)
120 OBD_FREE(server_uuid, strlen(fsname) + 15);
122 OBD_FREE(fsname, strlen(ospname));
124 lustre_cfg_free(lcfg);
126 client_obd_cleanup(osp->opd_obd);
130 int osp_fini_for_ost(struct osp_device *osp)
132 if (osp->opd_exp != NULL)
133 class_disconnect(osp->opd_exp);
137 int osp_init_for_ost(const struct lu_env *env, struct osp_device *osp,
138 struct lu_device_type *ldt, struct lustre_cfg *cfg)
140 struct lprocfs_static_vars lvars = { 0 };
144 osp->opd_obd = class_name2obd(lustre_cfg_string(cfg, 0));
145 if (osp->opd_obd == NULL) {
146 CERROR("Cannot find obd with name %s\n",
147 lustre_cfg_string(cfg, 0));
151 osp->opd_dt_dev.dd_lu_dev.ld_ops = &osp_lu_ops;
152 osp->opd_dt_dev.dd_ops = &osp_dt_ops;
153 osp->opd_obd->obd_lu_dev = &osp->opd_dt_dev.dd_lu_dev;
155 rc = ptlrpcd_addref();
157 CERROR("%s: ptlrpcd addref error: rc =%d\n",
158 osp->opd_obd->obd_name, rc);
162 rc = osp_setup_for_ost(env, osp, lustre_cfg_string(cfg, 1));
164 CERROR("%s: osp_setup_for_ost error: rc =%d\n",
165 osp->opd_obd->obd_name, rc);
170 lprocfs_osp_init_vars(&lvars);
171 if (lprocfs_obd_setup(osp->opd_obd, lvars.obd_vars) == 0)
172 ptlrpc_lprocfs_register_obd(osp->opd_obd);