1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
5 * Copyright (c) 2001-2003 Cluster File Systems, Inc.
7 * This file is part of Lustre, http://www.lustre.org.
9 * Lustre is free software; you can redistribute it and/or
10 * modify it under the terms of version 2 of the GNU General Public
11 * License as published by the Free Software Foundation.
13 * Lustre is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with Lustre; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 # define EXPORT_SYMTAB
26 #define DEBUG_SUBSYSTEM S_GSS
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/obd_class.h>
31 #include <linux/lustre_gs.h>
33 #include "gks_internal.h"
35 static int gkc_get_key(struct obd_export *exp, struct key_parms *kparms,
36 struct crypto_key *ckey, int op)
38 struct ptlrpc_request *req;
39 struct crypto_key *rep_key;
40 int rc, bufcount = 1, size[3] = {0, 0, 0};
44 size[0] = lustre_secdesc_size();
46 size[bufcount++] = kparms->context_size;
47 if (kparms->perm && kparms->perm_size > 0) {
48 size[bufcount++] = kparms->perm_size;
50 req = ptlrpc_prep_req(class_exp2cliimp(exp), LUSTRE_GKS_VERSION,
51 op, bufcount, size, NULL);
55 lustre_pack_secdesc(req, size[0]);
57 buf = lustre_msg_buf(req->rq_reqmsg, 1, kparms->context_size);
58 memcpy(buf, kparms->context, kparms->context_size);
60 if (kparms->perm && kparms->perm_size) {
61 buf = lustre_msg_buf(req->rq_reqmsg, 2, kparms->perm_size);
62 memcpy(buf, kparms->perm, kparms->perm_size);
65 size[0] = sizeof(struct crypto_key);
66 req->rq_replen = lustre_msg_size(1, size);
68 rc = ptlrpc_queue_wait(req);
70 rep_key = lustre_msg_buf(req->rq_repmsg, 0, sizeof(struct crypto_key));
72 memcpy(ckey, rep_key, sizeof(*rep_key));
74 CDEBUG(D_INFO, "get key %s, mac %s type %d\n", ckey->ck_key, ckey->ck_mac,
76 ptlrpc_req_finished(req);
81 static int gkc_set_info(struct obd_export *exp, obd_count keylen,
82 void *key, obd_count vallen, void *val)
85 if (keylen == strlen("async") && memcmp(key, "async", keylen) == 0) {
86 struct client_obd *cl = &exp->exp_obd->u.cli;
87 if (vallen != sizeof(int))
89 cl->cl_async = *(int *)val;
90 CDEBUG(D_HA, "%s: set async = %d\n",
91 exp->exp_obd->obd_name, cl->cl_async);
97 static int gkc_get_info(struct obd_export *exp, __u32 keylen,
98 void *key, __u32 *vallen, void *val)
100 struct key_parms *kparms = (struct key_parms *)key;
101 struct crypto_key *ckey = (struct crypto_key *)val;
106 LASSERT(*vallen == sizeof(*ckey));
108 switch (kparms->context->kc_command) {
110 case GKS_DECRYPT_KEY:
114 CERROR("Unknow op %d \n", kparms->context->kc_command);
118 rc = gkc_get_key(exp, kparms, ckey, kparms->context->kc_command);
121 static int gkc_setup(struct obd_device *obd, obd_count len, void *buf)
123 struct client_obd *cli = &obd->u.cli;
127 OBD_ALLOC(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
128 if (!cli->cl_rpc_lock)
130 gkc_init_rpc_lock(cli->cl_rpc_lock);
134 rc = client_obd_setup(obd, len, buf);
136 GOTO(err_rpc_lock, rc);
140 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
145 static int gkc_cleanup(struct obd_device *obd, int flags)
147 struct client_obd *cli = &obd->u.cli;
149 OBD_FREE(cli->cl_rpc_lock, sizeof (*cli->cl_rpc_lock));
153 return client_obd_cleanup(obd, 0);
156 static int gkc_attach(struct obd_device *dev, obd_count len, void *data)
158 struct lprocfs_static_vars lvars;
160 lprocfs_init_vars(gkc, &lvars);
161 return lprocfs_obd_attach(dev, lvars.obd_vars);
164 static int gkc_detach(struct obd_device *dev)
166 return lprocfs_obd_detach(dev);
169 static struct obd_ops gkc_obd_ops = {
170 .o_owner = THIS_MODULE,
171 .o_connect = client_connect_import,
172 .o_disconnect = client_disconnect_export,
173 .o_attach = gkc_attach,
174 .o_detach = gkc_detach,
175 .o_setup = gkc_setup,
176 .o_cleanup = gkc_cleanup,
177 .o_get_info = gkc_get_info,
178 .o_set_info = gkc_set_info,
181 static int __init gkc_init(void)
183 struct lprocfs_static_vars lvars;
185 lprocfs_init_vars(gkc, &lvars);
186 class_register_type(&gkc_obd_ops, NULL, lvars.module_vars,
191 static void gkc_exit(void)
193 class_unregister_type(LUSTRE_GKC_NAME);
196 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
197 MODULE_DESCRIPTION("Lustre GS Client (GS)");
198 MODULE_LICENSE("GPL");
200 module_init(gkc_init);
201 module_exit(gkc_exit);