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);
59 while (*(--ptr) != '-') {
64 strncpy(fsname, ospname, ptr - ospname);
65 fsname[ptr - ospname] = '\0';
70 static int osp_setup_for_ost(const struct lu_env *env, struct osp_device *osp,
73 struct lustre_cfg_bufs *bufs = NULL;
74 struct lustre_cfg *lcfg = NULL;
75 char *ospname = osp->opd_obd->obd_name;
77 char *server_uuid = NULL;
79 struct obd_import *imp;
87 OBD_ALLOC(fsname, strlen(ospname));
89 GOTO(out, rc = -ENOMEM);
91 rc = osp_name2fsname(ospname, fsname);
93 CERROR("%s: name change error: rc %d\n", ospname, rc);
97 OBD_ALLOC(server_uuid, strlen(fsname) + 15);
98 if (server_uuid == NULL)
99 GOTO(out, rc = -ENOMEM);
101 sprintf(server_uuid, "%s-MDT0000_UUID", fsname);
102 lustre_cfg_bufs_reset(bufs, ospname);
103 lustre_cfg_bufs_set_string(bufs, 1, server_uuid);
104 lustre_cfg_bufs_set_string(bufs, 2, nidstring);
105 lcfg = lustre_cfg_new(LCFG_SETUP, bufs);
107 GOTO(out, rc = -ENOMEM);
109 rc = client_obd_setup(osp->opd_obd, lcfg);
111 CERROR("%s: client obd setup error: rc = %d\n",
112 osp->opd_obd->obd_name, rc);
116 imp = osp->opd_obd->u.cli.cl_import;
117 rc = ptlrpc_init_import(imp);
121 ll_generate_random_uuid(uuid);
122 class_uuid_unparse(uuid, &osp->opd_cluuid);
126 if (server_uuid != NULL)
127 OBD_FREE(server_uuid, strlen(fsname) + 15);
129 OBD_FREE(fsname, strlen(ospname));
131 lustre_cfg_free(lcfg);
133 client_obd_cleanup(osp->opd_obd);
137 int osp_fini_for_ost(struct osp_device *osp)
139 if (osp->opd_exp != NULL)
140 class_disconnect(osp->opd_exp);
144 int osp_init_for_ost(const struct lu_env *env, struct osp_device *osp,
145 struct lu_device_type *ldt, struct lustre_cfg *cfg)
147 struct lprocfs_static_vars lvars = { 0 };
151 osp->opd_obd = class_name2obd(lustre_cfg_string(cfg, 0));
152 if (osp->opd_obd == NULL) {
153 CERROR("Cannot find obd with name %s\n",
154 lustre_cfg_string(cfg, 0));
158 osp->opd_dt_dev.dd_lu_dev.ld_ops = &osp_lu_ops;
159 osp->opd_dt_dev.dd_ops = &osp_dt_ops;
160 osp->opd_obd->obd_lu_dev = &osp->opd_dt_dev.dd_lu_dev;
162 rc = ptlrpcd_addref();
164 CERROR("%s: ptlrpcd addref error: rc =%d\n",
165 osp->opd_obd->obd_name, rc);
169 rc = osp_setup_for_ost(env, osp, lustre_cfg_string(cfg, 1));
171 CERROR("%s: osp_setup_for_ost error: rc =%d\n",
172 osp->opd_obd->obd_name, rc);
177 lprocfs_osp_init_vars(&lvars);
178 if (lprocfs_obd_setup(osp->opd_obd, lvars.obd_vars) == 0)
179 ptlrpc_lprocfs_register_obd(osp->opd_obd);