Whamcloud - gitweb
if client_disconnect_export was called without force flag set,
[fs/lustre-release.git] / lustre / ptlrpc / sec_lproc.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * Copyright (C) 2006 Cluster File Systems, Inc.
5  *   Author: Eric Mei <ericm@clusterfs.com>
6  *
7  *   This file is part of Lustre, http://www.lustre.org.
8  *
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.
12  *
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.
17  *
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.
21  */
22
23 #ifndef EXPORT_SYMTAB
24 #define EXPORT_SYMTAB
25 #endif
26 #define DEBUG_SUBSYSTEM S_SEC
27
28 #include <libcfs/libcfs.h>
29 #ifndef __KERNEL__
30 #include <liblustre.h>
31 #include <libcfs/list.h>
32 #else
33 #include <linux/crypto.h>
34 #endif
35
36 #include <obd.h>
37 #include <obd_class.h>
38 #include <obd_support.h>
39 #include <lustre_net.h>
40 #include <lustre_import.h>
41 #include <lustre_dlm.h>
42 #include <lustre_sec.h>
43
44 #include "ptlrpc_internal.h"
45
46 #ifdef __KERNEL__
47
48 struct proc_dir_entry *sptlrpc_proc_root = NULL;
49 EXPORT_SYMBOL(sptlrpc_proc_root);
50
51 void sec_flags2str(unsigned long flags, char *buf, int bufsize)
52 {
53         buf[0] = '\0';
54
55         if (flags & PTLRPC_SEC_FL_REVERSE)
56                 strncat(buf, "reverse,", bufsize);
57         if (flags & PTLRPC_SEC_FL_ROOTONLY)
58                 strncat(buf, "rootonly,", bufsize);
59         if (flags & PTLRPC_SEC_FL_BULK)
60                 strncat(buf, "bulk,", bufsize);
61         if (buf[0] == '\0')
62                 strncat(buf, "-,", bufsize);
63
64         buf[strlen(buf) - 1] = '\0';
65
66 }
67
68 int sptlrpc_lprocfs_rd(char *page, char **start, off_t off, int count,
69                        int *eof, void *data)
70 {
71         struct obd_device        *obd = data;
72         struct sec_flavor_config *conf = &obd->u.cli.cl_sec_conf;
73         struct ptlrpc_sec        *sec = NULL;
74         char                      flags_str[32];
75         int                       written;
76
77         if (obd == NULL)
78                 return 0;
79
80         LASSERT(strcmp(obd->obd_type->typ_name, LUSTRE_OSC_NAME) == 0 ||
81                 strcmp(obd->obd_type->typ_name, LUSTRE_MDC_NAME) == 0 ||
82                 strcmp(obd->obd_type->typ_name, LUSTRE_MGC_NAME) == 0);
83         LASSERT(conf->sfc_bulk_csum < BULK_CSUM_ALG_MAX);
84         LASSERT(conf->sfc_bulk_priv < BULK_PRIV_ALG_MAX);
85
86         if (obd->u.cli.cl_import)
87                 sec = obd->u.cli.cl_import->imp_sec;
88
89         if (sec == NULL) {
90                 written = snprintf(page, count, "\n");
91                 goto out;
92         }
93
94         sec_flags2str(sec->ps_flags, flags_str, sizeof(flags_str));
95
96         written = snprintf(page, count,
97                         "rpc msg flavor:        %s\n"
98                         "bulk checksum:         %s\n"
99                         "bulk encrypt:          %s\n"
100                         "flags:                 %s\n"
101                         "ctx cache busy         %d\n"
102                         "gc interval            %lu\n"
103                         "gc next                %ld\n",
104                         sptlrpc_flavor2name(sec->ps_flavor),
105                         sptlrpc_bulk_csum_alg2name(conf->sfc_bulk_csum),
106                         sptlrpc_bulk_priv_alg2name(conf->sfc_bulk_priv),
107                         flags_str,
108                         atomic_read(&sec->ps_busy),
109                         sec->ps_gc_interval,
110                         sec->ps_gc_interval ?
111                                 sec->ps_gc_next - cfs_time_current_sec() : 0
112                           );
113
114         if (sec->ps_policy->sp_cops->display) {
115                 written += sec->ps_policy->sp_cops->display(
116                                         sec, page + written, count - written);
117         }
118
119 out:
120         return written;
121 }
122 EXPORT_SYMBOL(sptlrpc_lprocfs_rd);
123
124 static struct lprocfs_vars sptlrpc_lprocfs_vars[] = {
125         { "enc_pool", sptlrpc_proc_read_enc_pool, NULL, NULL },
126         { NULL }
127 };
128
129 int sptlrpc_lproc_init(void)
130 {
131         int     rc;
132
133         LASSERT(sptlrpc_proc_root == NULL);
134
135         sptlrpc_proc_root = lprocfs_register("sptlrpc", proc_lustre_root,
136                                              sptlrpc_lprocfs_vars, NULL);
137         if (IS_ERR(sptlrpc_proc_root)) {
138                 rc = PTR_ERR(sptlrpc_proc_root);
139                 sptlrpc_proc_root = NULL;
140                 return rc;
141         }
142         return 0;
143 }
144
145 void sptlrpc_lproc_fini(void)
146 {
147         if (sptlrpc_proc_root) {
148                 lprocfs_remove(&sptlrpc_proc_root);
149                 sptlrpc_proc_root = NULL;
150         }
151 }
152
153 #else /* !__KERNEL__ */
154
155 int sptlrpc_lproc_init(void)
156 {
157         return 0;
158 }
159
160 void sptlrpc_lproc_fini(void)
161 {
162 }
163
164 #endif