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, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
24 * Copyright 2017 Cray Inc. All rights reserved.
28 /* Check that the inode number is the same whether the call to
29 * vfs_getattr is coming from a system call or from a kthread. When
30 * CONFIG_X86_X32 was set, the result used to be different for
31 * Lustre. In addition, a user can also check that the same inode
32 * number is also seen from the kernel and userspace. */
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/kthread.h>
38 #include <linux/version.h>
40 /* Random ID passed by userspace, and printed in messages, used to
41 * separate different runs of that module. */
43 module_param(run_id, int, 0644);
44 MODULE_PARM_DESC(run_id, "run ID");
46 /* Name of the file to stat. */
47 static char fname[4096];
48 module_param_string(fname, fname, sizeof(fname), 0644);
49 MODULE_PARM_DESC(fname, "name of file to stat");
51 struct completion thr_start;
53 #define PREFIX "lustre_kinode_%u:"
55 static int stat_file(struct kstat *stbuf)
60 fd = filp_open(fname, O_RDONLY, 0);
62 pr_err(PREFIX " can't open file %s\n", run_id, fname);
66 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
67 rc = vfs_getattr(&fd->f_path, stbuf);
69 rc = vfs_getattr(fd->f_path.mnt, fd->f_path.dentry, stbuf);
72 pr_err(PREFIX " vfs_getattr failed: %d\n", run_id, rc);
76 pr_err(PREFIX " inode is %llu\n", run_id, stbuf->ino);
85 static int stat_thread(void *data)
87 struct kstat *stbuf = data;
90 /* Signal caller that thread has started. */
93 rc = stat_file(stbuf);
95 /* Wait for call to kthread_stop. */
96 set_current_state(TASK_INTERRUPTIBLE);
97 while (!kthread_should_stop()) {
99 set_current_state(TASK_INTERRUPTIBLE);
101 set_current_state(TASK_RUNNING);
106 static int __init kinode_init(void)
108 struct task_struct *thr;
113 #ifdef CONFIG_X86_X32
114 pr_err(PREFIX " CONFIG_X86_X32 is set\n", run_id);
116 pr_err(PREFIX " CONFIG_X86_X32 is not set\n", run_id);
119 if (strlen(fname) < 1) {
120 pr_err(PREFIX " invalid file name '%s'\n", run_id, fname);
124 rc = stat_file(&stbuf1);
126 pr_err(PREFIX " direct stat failed: %d\n", run_id, rc);
130 /* Run the same from a kthread. */
131 init_completion(&thr_start);
132 thr = kthread_run(stat_thread, &stbuf2, "kinode_%u", run_id);
134 pr_err(PREFIX " Cannot create kthread\n", run_id);
138 /* Wait for the thread to start, then wait for it to
140 wait_for_completion(&thr_start);
141 rc = kthread_stop(thr);
143 pr_err(PREFIX " indirect stat failed: %d\n", run_id, rc);
147 if (stbuf1.ino != stbuf2.ino)
148 pr_err(PREFIX " inode numbers are different: %llu %llu\n",
149 run_id, stbuf1.ino, stbuf2.ino);
151 pr_err(PREFIX " inode numbers are identical: %llu\n",
159 static void __exit kinode_exit(void)
163 MODULE_AUTHOR("OpenSFS, Inc. <http://www.lustre.org/>");
164 MODULE_DESCRIPTION("Lustre inode stat test module");
165 MODULE_VERSION(LUSTRE_VERSION_STRING);
166 MODULE_LICENSE("GPL");
168 module_init(kinode_init);
169 module_exit(kinode_exit);