]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - drivers/staging/lustre/lustre/obdclass/class_obd.c
staging: lustre: add missing MODULE_AUTHOR for LNet selftest module
[mirror_ubuntu-zesty-kernel.git] / drivers / staging / lustre / lustre / obdclass / class_obd.c
CommitLineData
d7e09d03
PT
1/*
2 * GPL HEADER START
3 *
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
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.
9 *
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).
15 *
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
1dc563a6 30 * Copyright (c) 2011, 2015, Intel Corporation.
d7e09d03
PT
31 */
32/*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 */
36
37#define DEBUG_SUBSYSTEM S_CLASS
e409842a 38# include <linux/atomic.h>
d7e09d03 39
610f7377
GKH
40#include "../include/obd_support.h"
41#include "../include/obd_class.h"
9fdaf8c0 42#include "../../include/linux/lnet/lnetctl.h"
610f7377
GKH
43#include "../include/lustre_debug.h"
44#include "../include/lprocfs_status.h"
d7e09d03 45#include <linux/list.h>
610f7377 46#include "../include/cl_object.h"
d7e09d03
PT
47#include "llog_internal.h"
48
d7e09d03
PT
49struct obd_device *obd_devs[MAX_OBD_DEVICES];
50EXPORT_SYMBOL(obd_devs);
51struct list_head obd_types;
52DEFINE_RWLOCK(obd_dev_lock);
53
406c1c7c 54/* The following are visible and mutable through /sys/fs/lustre. */
d7e09d03
PT
55unsigned int obd_debug_peer_on_timeout;
56EXPORT_SYMBOL(obd_debug_peer_on_timeout);
57unsigned int obd_dump_on_timeout;
58EXPORT_SYMBOL(obd_dump_on_timeout);
59unsigned int obd_dump_on_eviction;
60EXPORT_SYMBOL(obd_dump_on_eviction);
61unsigned int obd_max_dirty_pages = 256;
62EXPORT_SYMBOL(obd_max_dirty_pages);
d7e09d03
PT
63atomic_t obd_dirty_pages;
64EXPORT_SYMBOL(obd_dirty_pages);
65unsigned int obd_timeout = OBD_TIMEOUT_DEFAULT; /* seconds */
66EXPORT_SYMBOL(obd_timeout);
d7e09d03
PT
67unsigned int obd_timeout_set;
68EXPORT_SYMBOL(obd_timeout_set);
406c1c7c 69/* Adaptive timeout defs here instead of ptlrpc module for /sys/fs/ access */
ea28d21a 70unsigned int at_min;
d7e09d03
PT
71EXPORT_SYMBOL(at_min);
72unsigned int at_max = 600;
73EXPORT_SYMBOL(at_max);
74unsigned int at_history = 600;
75EXPORT_SYMBOL(at_history);
76int at_early_margin = 5;
77EXPORT_SYMBOL(at_early_margin);
78int at_extra = 30;
79EXPORT_SYMBOL(at_extra);
80
81atomic_t obd_dirty_transit_pages;
82EXPORT_SYMBOL(obd_dirty_transit_pages);
83
84char obd_jobid_var[JOBSTATS_JOBID_VAR_MAX_LEN + 1] = JOBSTATS_DISABLE;
85EXPORT_SYMBOL(obd_jobid_var);
86
76133e66
OD
87char obd_jobid_node[JOBSTATS_JOBID_SIZE + 1];
88
89/* Get jobid of current process from stored variable or calculate
90 * it from pid and user_id.
d7e09d03 91 *
76133e66
OD
92 * Historically this was also done by reading the environment variable
93 * stored in between the "env_start" & "env_end" of task struct.
94 * This is now deprecated.
d7e09d03
PT
95 */
96int lustre_get_jobid(char *jobid)
97{
d7e09d03
PT
98 memset(jobid, 0, JOBSTATS_JOBID_SIZE);
99 /* Jobstats isn't enabled */
100 if (strcmp(obd_jobid_var, JOBSTATS_DISABLE) == 0)
0a3bdb00 101 return 0;
d7e09d03
PT
102
103 /* Use process name + fsuid as jobid */
104 if (strcmp(obd_jobid_var, JOBSTATS_PROCNAME_UID) == 0) {
105 snprintf(jobid, JOBSTATS_JOBID_SIZE, "%s.%u",
4b1a25f0
PT
106 current_comm(),
107 from_kuid(&init_user_ns, current_fsuid()));
0a3bdb00 108 return 0;
d7e09d03
PT
109 }
110
76133e66
OD
111 /* Whole node dedicated to single job */
112 if (strcmp(obd_jobid_var, JOBSTATS_NODELOCAL) == 0) {
113 strcpy(jobid, obd_jobid_node);
114 return 0;
d7e09d03 115 }
76133e66
OD
116
117 return -ENOENT;
d7e09d03
PT
118}
119EXPORT_SYMBOL(lustre_get_jobid);
120
d7e09d03
PT
121static inline void obd_data2conn(struct lustre_handle *conn,
122 struct obd_ioctl_data *data)
123{
ec83e611 124 memset(conn, 0, sizeof(*conn));
d7e09d03
PT
125 conn->cookie = data->ioc_cookie;
126}
127
128static inline void obd_conn2data(struct obd_ioctl_data *data,
129 struct lustre_handle *conn)
130{
131 data->ioc_cookie = conn->cookie;
132}
133
fb320795 134static int class_resolve_dev_name(__u32 len, const char *name)
d7e09d03
PT
135{
136 int rc;
137 int dev;
138
d7e09d03
PT
139 if (!len || !name) {
140 CERROR("No name passed,!\n");
d212afd9
JL
141 rc = -EINVAL;
142 goto out;
d7e09d03
PT
143 }
144 if (name[len - 1] != 0) {
145 CERROR("Name not nul terminated!\n");
d212afd9
JL
146 rc = -EINVAL;
147 goto out;
d7e09d03
PT
148 }
149
150 CDEBUG(D_IOCTL, "device name %s\n", name);
151 dev = class_name2dev(name);
152 if (dev == -1) {
153 CDEBUG(D_IOCTL, "No device for name %s!\n", name);
d212afd9
JL
154 rc = -EINVAL;
155 goto out;
d7e09d03
PT
156 }
157
158 CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
159 rc = dev;
160
161out:
0a3bdb00 162 return rc;
d7e09d03
PT
163}
164
165int class_handle_ioctl(unsigned int cmd, unsigned long arg)
166{
167 char *buf = NULL;
168 struct obd_ioctl_data *data;
169 struct libcfs_debug_ioctl_data *debug_data;
170 struct obd_device *obd = NULL;
171 int err = 0, len = 0;
d7e09d03
PT
172
173 /* only for debugging */
174 if (cmd == LIBCFS_IOC_DEBUG_MASK) {
bdbb0512 175 debug_data = (struct libcfs_debug_ioctl_data *)arg;
d7e09d03
PT
176 libcfs_subsystem_debug = debug_data->subs;
177 libcfs_debug = debug_data->debug;
178 return 0;
179 }
180
181 CDEBUG(D_IOCTL, "cmd = %x\n", cmd);
e3e8ff41 182 if (obd_ioctl_getdata(&buf, &len, (void __user *)arg)) {
d7e09d03 183 CERROR("OBD ioctl: data error\n");
0a3bdb00 184 return -EINVAL;
d7e09d03
PT
185 }
186 data = (struct obd_ioctl_data *)buf;
187
188 switch (cmd) {
189 case OBD_IOC_PROCESS_CFG: {
190 struct lustre_cfg *lcfg;
191
192 if (!data->ioc_plen1 || !data->ioc_pbuf1) {
193 CERROR("No config buffer passed!\n");
d212afd9
JL
194 err = -EINVAL;
195 goto out;
d7e09d03 196 }
d7279044 197 lcfg = kzalloc(data->ioc_plen1, GFP_NOFS);
485640b5 198 if (!lcfg) {
d212afd9
JL
199 err = -ENOMEM;
200 goto out;
201 }
926d6fb2 202 err = copy_from_user(lcfg, data->ioc_pbuf1, data->ioc_plen1);
d7e09d03
PT
203 if (!err)
204 err = lustre_cfg_sanity_check(lcfg, data->ioc_plen1);
205 if (!err)
206 err = class_process_config(lcfg);
207
d7279044 208 kfree(lcfg);
d212afd9 209 goto out;
d7e09d03
PT
210 }
211
212 case OBD_GET_VERSION:
213 if (!data->ioc_inlbuf1) {
214 CERROR("No buffer passed in ioctl\n");
d212afd9
JL
215 err = -EINVAL;
216 goto out;
d7e09d03
PT
217 }
218
eb3d9989 219 if (strlen(LUSTRE_VERSION_STRING) + 1 > data->ioc_inllen1) {
d7e09d03 220 CERROR("ioctl buffer too small to hold version\n");
d212afd9
JL
221 err = -EINVAL;
222 goto out;
d7e09d03
PT
223 }
224
eb3d9989
OD
225 memcpy(data->ioc_bulk, LUSTRE_VERSION_STRING,
226 strlen(LUSTRE_VERSION_STRING) + 1);
d7e09d03 227
e3e8ff41 228 err = obd_ioctl_popdata((void __user *)arg, data, len);
d7e09d03
PT
229 if (err)
230 err = -EFAULT;
d212afd9 231 goto out;
d7e09d03
PT
232
233 case OBD_IOC_NAME2DEV: {
234 /* Resolve a device name. This does not change the
235 * currently selected device.
236 */
237 int dev;
238
239 dev = class_resolve_dev_name(data->ioc_inllen1,
240 data->ioc_inlbuf1);
241 data->ioc_dev = dev;
d212afd9
JL
242 if (dev < 0) {
243 err = -EINVAL;
244 goto out;
245 }
d7e09d03 246
e3e8ff41
OD
247 err = obd_ioctl_popdata((void __user *)arg, data,
248 sizeof(*data));
d7e09d03
PT
249 if (err)
250 err = -EFAULT;
d212afd9 251 goto out;
d7e09d03
PT
252 }
253
254 case OBD_IOC_UUID2DEV: {
255 /* Resolve a device uuid. This does not change the
256 * currently selected device.
257 */
258 int dev;
259 struct obd_uuid uuid;
260
261 if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
262 CERROR("No UUID passed!\n");
d212afd9
JL
263 err = -EINVAL;
264 goto out;
d7e09d03
PT
265 }
266 if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
267 CERROR("UUID not NUL terminated!\n");
d212afd9
JL
268 err = -EINVAL;
269 goto out;
d7e09d03
PT
270 }
271
272 CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
273 obd_str2uuid(&uuid, data->ioc_inlbuf1);
274 dev = class_uuid2dev(&uuid);
275 data->ioc_dev = dev;
276 if (dev == -1) {
277 CDEBUG(D_IOCTL, "No device for UUID %s!\n",
278 data->ioc_inlbuf1);
d212afd9
JL
279 err = -EINVAL;
280 goto out;
d7e09d03
PT
281 }
282
283 CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
284 dev);
e3e8ff41
OD
285 err = obd_ioctl_popdata((void __user *)arg, data,
286 sizeof(*data));
d7e09d03
PT
287 if (err)
288 err = -EFAULT;
d212afd9 289 goto out;
d7e09d03
PT
290 }
291
292 case OBD_IOC_CLOSE_UUID: {
293 CDEBUG(D_IOCTL, "closing all connections to uuid %s (NOOP)\n",
294 data->ioc_inlbuf1);
d212afd9
JL
295 err = 0;
296 goto out;
d7e09d03
PT
297 }
298
299 case OBD_IOC_GETDEVICE: {
300 int index = data->ioc_count;
301 char *status, *str;
302
303 if (!data->ioc_inlbuf1) {
304 CERROR("No buffer passed in ioctl\n");
d212afd9
JL
305 err = -EINVAL;
306 goto out;
d7e09d03
PT
307 }
308 if (data->ioc_inllen1 < 128) {
309 CERROR("ioctl buffer too small to hold version\n");
d212afd9
JL
310 err = -EINVAL;
311 goto out;
d7e09d03
PT
312 }
313
314 obd = class_num2obd(index);
d212afd9
JL
315 if (!obd) {
316 err = -ENOENT;
317 goto out;
318 }
d7e09d03
PT
319
320 if (obd->obd_stopping)
321 status = "ST";
322 else if (obd->obd_set_up)
323 status = "UP";
324 else if (obd->obd_attached)
325 status = "AT";
326 else
327 status = "--";
328 str = (char *)data->ioc_bulk;
329 snprintf(str, len - sizeof(*data), "%3d %s %s %s %s %d",
330 (int)index, status, obd->obd_type->typ_name,
331 obd->obd_name, obd->obd_uuid.uuid,
332 atomic_read(&obd->obd_refcount));
e3e8ff41 333 err = obd_ioctl_popdata((void __user *)arg, data, len);
d7e09d03 334
d212afd9
JL
335 err = 0;
336 goto out;
d7e09d03
PT
337 }
338
339 }
340
341 if (data->ioc_dev == OBD_DEV_BY_DEVNAME) {
cce3c2da 342 if (data->ioc_inllen4 <= 0 || !data->ioc_inlbuf4) {
d212afd9
JL
343 err = -EINVAL;
344 goto out;
345 }
346 if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME) {
347 err = -EINVAL;
348 goto out;
349 }
d7e09d03
PT
350 obd = class_name2obd(data->ioc_inlbuf4);
351 } else if (data->ioc_dev < class_devno_max()) {
352 obd = class_num2obd(data->ioc_dev);
353 } else {
354 CERROR("OBD ioctl: No device\n");
d212afd9
JL
355 err = -EINVAL;
356 goto out;
d7e09d03
PT
357 }
358
cce3c2da 359 if (!obd) {
d7e09d03 360 CERROR("OBD ioctl : No Device %d\n", data->ioc_dev);
d212afd9
JL
361 err = -EINVAL;
362 goto out;
d7e09d03
PT
363 }
364 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
365
366 if (!obd->obd_set_up || obd->obd_stopping) {
d212afd9
JL
367 CERROR("OBD ioctl: device not setup %d\n", data->ioc_dev);
368 err = -EINVAL;
369 goto out;
d7e09d03
PT
370 }
371
a58a38ac 372 switch (cmd) {
d7e09d03
PT
373 case OBD_IOC_NO_TRANSNO: {
374 if (!obd->obd_attached) {
375 CERROR("Device %d not attached\n", obd->obd_minor);
d212afd9
JL
376 err = -ENODEV;
377 goto out;
d7e09d03
PT
378 }
379 CDEBUG(D_HA, "%s: disabling committed-transno notification\n",
380 obd->obd_name);
381 obd->obd_no_transno = 1;
d212afd9
JL
382 err = 0;
383 goto out;
d7e09d03
PT
384 }
385
386 default: {
387 err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
388 if (err)
d212afd9 389 goto out;
d7e09d03 390
e3e8ff41 391 err = obd_ioctl_popdata((void __user *)arg, data, len);
d7e09d03
PT
392 if (err)
393 err = -EFAULT;
d212afd9 394 goto out;
d7e09d03
PT
395 }
396 }
397
398 out:
399 if (buf)
400 obd_ioctl_freedata(buf, len);
0a3bdb00 401 return err;
d7e09d03
PT
402} /* class_handle_ioctl */
403
d7e09d03 404#define OBD_INIT_CHECK
28fcc662 405static int obd_init_checks(void)
d7e09d03
PT
406{
407 __u64 u64val, div64val;
408 char buf[64];
409 int len, ret = 0;
410
55f5a824 411 CDEBUG(D_INFO, "LPU64=%s, LPD64=%s, LPX64=%s\n", "%llu", "%lld", "%#llx");
d7e09d03 412
55f5a824 413 CDEBUG(D_INFO, "OBD_OBJECT_EOF = %#llx\n", (__u64)OBD_OBJECT_EOF);
d7e09d03
PT
414
415 u64val = OBD_OBJECT_EOF;
55f5a824 416 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
d7e09d03 417 if (u64val != OBD_OBJECT_EOF) {
55f5a824 418 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
d7e09d03
PT
419 u64val, (int)sizeof(u64val));
420 ret = -EINVAL;
421 }
55f5a824 422 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
d7e09d03
PT
423 if (len != 18) {
424 CWARN("LPX64 wrong length! strlen(%s)=%d != 18\n", buf, len);
425 ret = -EINVAL;
426 }
427
428 div64val = OBD_OBJECT_EOF;
55f5a824 429 CDEBUG(D_INFO, "u64val OBD_OBJECT_EOF = %#llx\n", u64val);
d7e09d03 430 if (u64val != OBD_OBJECT_EOF) {
55f5a824 431 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
d7e09d03
PT
432 u64val, (int)sizeof(u64val));
433 ret = -EOVERFLOW;
434 }
435 if (u64val >> 8 != OBD_OBJECT_EOF >> 8) {
55f5a824 436 CERROR("__u64 %#llx(%d) != 0xffffffffffffffff\n",
d7e09d03
PT
437 u64val, (int)sizeof(u64val));
438 return -EOVERFLOW;
439 }
440 if (do_div(div64val, 256) != (u64val & 255)) {
b2952d62 441 CERROR("do_div(%#llx,256) != %llu\n", u64val, u64val & 255);
d7e09d03
PT
442 return -EOVERFLOW;
443 }
444 if (u64val >> 8 != div64val) {
55f5a824 445 CERROR("do_div(%#llx,256) %llu != %llu\n",
d7e09d03
PT
446 u64val, div64val, u64val >> 8);
447 return -EOVERFLOW;
448 }
55f5a824 449 len = snprintf(buf, sizeof(buf), "%#llx", u64val);
d7e09d03
PT
450 if (len != 18) {
451 CWARN("LPX64 wrong length! strlen(%s)=%d != 18\n", buf, len);
452 ret = -EINVAL;
453 }
b0f5aad5 454 len = snprintf(buf, sizeof(buf), "%llu", u64val);
d7e09d03
PT
455 if (len != 20) {
456 CWARN("LPU64 wrong length! strlen(%s)=%d != 20\n", buf, len);
457 ret = -EINVAL;
458 }
f537dd2c 459 len = snprintf(buf, sizeof(buf), "%lld", u64val);
d7e09d03
PT
460 if (len != 2) {
461 CWARN("LPD64 wrong length! strlen(%s)=%d != 2\n", buf, len);
462 ret = -EINVAL;
463 }
464 if ((u64val & ~CFS_PAGE_MASK) >= PAGE_CACHE_SIZE) {
b0f5aad5 465 CWARN("mask failed: u64val %llu >= %llu\n", u64val,
d7e09d03
PT
466 (__u64)PAGE_CACHE_SIZE);
467 ret = -EINVAL;
468 }
469
470 return ret;
471}
472
d7e09d03
PT
473extern int class_procfs_init(void);
474extern int class_procfs_clean(void);
475
476static int __init init_obdclass(void)
477{
478 int i, err;
50ffcb7e 479
d7e09d03
PT
480 int lustre_register_fs(void);
481
eb3d9989 482 LCONSOLE_INFO("Lustre: Build Version: " LUSTRE_VERSION_STRING "\n");
d7e09d03
PT
483
484 spin_lock_init(&obd_types_lock);
485 obd_zombie_impexp_init();
8cc420d0 486
d7e09d03
PT
487 err = obd_init_checks();
488 if (err == -EOVERFLOW)
489 return err;
490
491 class_init_uuidlist();
492 err = class_handle_init();
493 if (err)
494 return err;
495
496 INIT_LIST_HEAD(&obd_types);
497
498 err = misc_register(&obd_psdev);
499 if (err) {
500 CERROR("cannot register %d err %d\n", OBD_DEV_MINOR, err);
501 return err;
502 }
503
504 /* This struct is already zeroed for us (static global) */
505 for (i = 0; i < class_devno_max(); i++)
506 obd_devs[i] = NULL;
507
508 /* Default the dirty page cache cap to 1/2 of system memory.
509 * For clients with less memory, a larger fraction is needed
6ba59179
OD
510 * for other purposes (mostly for BGL).
511 */
4f6cc9ab
PT
512 if (totalram_pages <= 512 << (20 - PAGE_CACHE_SHIFT))
513 obd_max_dirty_pages = totalram_pages / 4;
d7e09d03 514 else
4f6cc9ab 515 obd_max_dirty_pages = totalram_pages / 2;
d7e09d03
PT
516
517 err = obd_init_caches();
518 if (err)
519 return err;
c7c5da01 520
d7e09d03
PT
521 err = class_procfs_init();
522 if (err)
523 return err;
524
e2424a12
OD
525 err = obd_sysctl_init();
526 if (err)
527 return err;
528
d7e09d03
PT
529 err = lu_global_init();
530 if (err)
531 return err;
532
533 err = cl_global_init();
534 if (err != 0)
535 return err;
536
d7e09d03
PT
537 err = llog_info_init();
538 if (err)
539 return err;
540
541 err = lustre_register_fs();
542
543 return err;
544}
545
d7e09d03
PT
546static void cleanup_obdclass(void)
547{
548 int i;
50ffcb7e 549
d7e09d03 550 int lustre_unregister_fs(void);
d7e09d03
PT
551
552 lustre_unregister_fs();
553
554 misc_deregister(&obd_psdev);
555 for (i = 0; i < class_devno_max(); i++) {
556 struct obd_device *obd = class_num2obd(i);
50ffcb7e 557
d7e09d03
PT
558 if (obd && obd->obd_set_up &&
559 OBT(obd) && OBP(obd, detach)) {
560 /* XXX should this call generic detach otherwise? */
561 LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
562 OBP(obd, detach)(obd);
563 }
564 }
565 llog_info_fini();
566 cl_global_fini();
567 lu_global_fini();
568
569 obd_cleanup_caches();
d7e09d03
PT
570
571 class_procfs_clean();
572
573 class_handle_cleanup();
574 class_exit_uuidlist();
575 obd_zombie_impexp_stop();
d7e09d03
PT
576}
577
a0455471 578MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
eb3d9989 579MODULE_DESCRIPTION("Lustre Class Driver Build Version: " LUSTRE_VERSION_STRING);
6960736c 580MODULE_VERSION(LUSTRE_VERSION_STRING);
5b0e50b9 581MODULE_LICENSE("GPL");
d7e09d03 582
6960736c
GKH
583module_init(init_obdclass);
584module_exit(cleanup_obdclass);