1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2002, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
32 * Copyright (c) 2012, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
38 #define DEBUG_SUBSYSTEM S_CLASS
40 #include <linux/version.h>
41 #include <asm/statfs.h>
43 #include <obd_class.h>
44 #include <lprocfs_status.h>
45 #include "mds_internal.h"
48 static int lprocfs_mds_rd_evictostnids(char *page, char **start, off_t off,
49 int count, int *eof, void *data)
51 struct obd_device* obd = (struct obd_device *)data;
55 return snprintf(page, count, "%d\n", obd->u.mds.mds_evict_ost_nids);
58 static int lprocfs_mds_wr_evictostnids(struct file *file, const char *buffer,
59 unsigned long count, void *data)
61 struct obd_device *obd = data;
64 rc = lprocfs_write_helper(buffer, count, &val);
68 obd->u.mds.mds_evict_ost_nids = !!val;
73 #define BUFLEN (UUID_MAX + 4)
75 static int lprocfs_mds_wr_evict_client(struct file *file, const char *buffer,
76 unsigned long count, void *data)
78 struct ptlrpc_request_set *set;
79 struct obd_device *obd = data;
80 struct mds_obd *mds = &obd->u.mds;
85 OBD_ALLOC(kbuf, BUFLEN);
90 * OBD_ALLOC() will zero kbuf, but we only copy BUFLEN - 1
91 * bytes into kbuf, to ensure that the string is NUL-terminated.
92 * UUID_MAX should include a trailing NUL already.
94 if (cfs_copy_from_user(kbuf, buffer,
95 min_t(unsigned long, BUFLEN - 1, count))) {
99 tmpbuf = cfs_firststr(kbuf, min_t(unsigned long, BUFLEN - 1, count));
101 if (strncmp(tmpbuf, "nid:", 4) != 0) {
102 count = lprocfs_wr_evict_client(file, buffer, count, data);
106 set = ptlrpc_prep_set();
112 if (obd->u.mds.mds_evict_ost_nids) {
113 rc = obd_set_info_async(mds->mds_lov_exp,
114 sizeof(KEY_EVICT_BY_NID),
115 KEY_EVICT_BY_NID, strlen(tmpbuf + 4) + 1,
118 CERROR("Failed to evict nid %s from OSTs: rc %d\n",
121 ptlrpc_check_set(NULL, set);
124 /* See the comments in function lprocfs_wr_evict_client()
125 * in ptlrpc/lproc_ptlrpc.c for details. - jay */
126 class_incref(obd, __FUNCTION__, cfs_current());
129 obd_export_evict_by_nid(obd, tmpbuf + 4);
132 rc = ptlrpc_set_wait(set);
134 CERROR("Failed to evict nid %s from OSTs: rc %d\n", tmpbuf + 4,
138 class_decref(obd, __FUNCTION__, cfs_current());
140 ptlrpc_set_destroy(set);
142 OBD_FREE(kbuf, BUFLEN);
148 static int lprocfs_wr_atime_diff(struct file *file, const char *buffer,
149 unsigned long count, void *data)
151 struct obd_device *obd = data;
152 struct mds_obd *mds = &obd->u.mds;
153 char kernbuf[20], *end;
154 unsigned long diff = 0;
156 if (count > (sizeof(kernbuf) - 1))
159 if (cfs_copy_from_user(kernbuf, buffer, count))
162 kernbuf[count] = '\0';
164 diff = simple_strtoul(kernbuf, &end, 0);
168 mds->mds_atime_diff = diff;
172 static int lprocfs_rd_atime_diff(char *page, char **start, off_t off,
173 int count, int *eof, void *data)
175 struct obd_device *obd = data;
176 struct mds_obd *mds = &obd->u.mds;
179 return snprintf(page, count, "%lu\n", mds->mds_atime_diff);
182 struct lprocfs_vars lprocfs_mds_obd_vars[] = {
183 { "uuid", lprocfs_rd_uuid, 0, 0 },
184 { "blocksize", lprocfs_rd_blksize, 0, 0 },
185 { "kbytestotal", lprocfs_rd_kbytestotal, 0, 0 },
186 { "kbytesfree", lprocfs_rd_kbytesfree, 0, 0 },
187 { "kbytesavail", lprocfs_rd_kbytesavail, 0, 0 },
188 { "filestotal", lprocfs_rd_filestotal, 0, 0 },
189 { "filesfree", lprocfs_rd_filesfree, 0, 0 },
190 { "fstype", lprocfs_rd_fstype, 0, 0 },
191 { "mntdev", lprocfs_obd_rd_mntdev, 0, 0 },
192 { "recovery_status", lprocfs_obd_rd_recovery_status, 0, 0 },
193 { "hash_stats", lprocfs_obd_rd_hash, 0, 0 },
194 { "evict_client", 0, lprocfs_mds_wr_evict_client, 0 },
195 { "evict_ost_nids", lprocfs_mds_rd_evictostnids,
196 lprocfs_mds_wr_evictostnids, 0 },
197 { "num_exports", lprocfs_rd_num_exports, 0, 0 },
198 { "atime_diff", lprocfs_rd_atime_diff, lprocfs_wr_atime_diff, 0 },
202 struct lprocfs_vars lprocfs_mds_module_vars[] = {
203 { "num_refs", lprocfs_rd_numrefs, 0, 0 },
207 struct lprocfs_vars lprocfs_mdt_obd_vars[] = {
208 { "uuid", lprocfs_rd_uuid, 0, 0 },
212 void lprocfs_mds_init_vars(struct lprocfs_static_vars *lvars)
214 lvars->module_vars = lprocfs_mds_module_vars;
215 lvars->obd_vars = lprocfs_mds_obd_vars;