Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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 |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 20 | * GPL HEADER END |
| 21 | */ |
| 22 | /* |
| 23 | * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. |
| 24 | * Use is subject to license terms. |
| 25 | * |
| 26 | * Copyright (c) 2012, Intel Corporation. |
| 27 | */ |
| 28 | /* |
| 29 | * This file is part of Lustre, http://www.lustre.org/ |
| 30 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 31 | */ |
| 32 | |
| 33 | #define DEBUG_SUBSYSTEM S_CLASS |
| 34 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 35 | #include <linux/seq_file.h> |
Filipe Gonçalves | 588a12d | 2014-09-05 05:09:46 +0100 | [diff] [blame] | 36 | #include <linux/statfs.h> |
Greg Kroah-Hartman | a8c495a | 2014-07-11 21:57:32 -0700 | [diff] [blame] | 37 | #include "../include/lprocfs_status.h" |
| 38 | #include "../include/obd_class.h" |
Darshana Padmadas | 80e1773 | 2015-03-28 23:13:53 +0530 | [diff] [blame] | 39 | #include "lmv_internal.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 40 | |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 41 | static ssize_t numobd_show(struct kobject *kobj, struct attribute *attr, |
| 42 | char *buf) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 43 | { |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 44 | struct obd_device *dev = container_of(kobj, struct obd_device, |
| 45 | obd_kobj); |
| 46 | struct lmv_desc *desc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 47 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 48 | desc = &dev->u.lmv.desc; |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 49 | return sprintf(buf, "%u\n", desc->ld_tgt_count); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 50 | } |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 51 | LUSTRE_RO_ATTR(numobd); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 52 | |
| 53 | static const char *placement_name[] = { |
| 54 | [PLACEMENT_CHAR_POLICY] = "CHAR", |
| 55 | [PLACEMENT_NID_POLICY] = "NID", |
| 56 | [PLACEMENT_INVAL_POLICY] = "INVAL" |
| 57 | }; |
| 58 | |
Hugues Morisset | fe67299 | 2014-09-09 16:36:26 +0200 | [diff] [blame] | 59 | static enum placement_policy placement_name2policy(char *name, int len) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 60 | { |
| 61 | int i; |
| 62 | |
| 63 | for (i = 0; i < PLACEMENT_MAX_POLICY; i++) { |
| 64 | if (!strncmp(placement_name[i], name, len)) |
| 65 | return i; |
| 66 | } |
| 67 | return PLACEMENT_INVAL_POLICY; |
| 68 | } |
| 69 | |
Hugues Morisset | fe67299 | 2014-09-09 16:36:26 +0200 | [diff] [blame] | 70 | static const char *placement_policy2name(enum placement_policy placement) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 71 | { |
| 72 | LASSERT(placement < PLACEMENT_MAX_POLICY); |
| 73 | return placement_name[placement]; |
| 74 | } |
| 75 | |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 76 | static ssize_t placement_show(struct kobject *kobj, struct attribute *attr, |
| 77 | char *buf) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 78 | { |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 79 | struct obd_device *dev = container_of(kobj, struct obd_device, |
| 80 | obd_kobj); |
| 81 | struct lmv_obd *lmv; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 82 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 83 | lmv = &dev->u.lmv; |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 84 | return sprintf(buf, "%s\n", placement_policy2name(lmv->lmv_placement)); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | #define MAX_POLICY_STRING_SIZE 64 |
| 88 | |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 89 | static ssize_t placement_store(struct kobject *kobj, struct attribute *attr, |
| 90 | const char *buffer, |
| 91 | size_t count) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 92 | { |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 93 | struct obd_device *dev = container_of(kobj, struct obd_device, |
| 94 | obd_kobj); |
| 95 | char dummy[MAX_POLICY_STRING_SIZE + 1]; |
| 96 | enum placement_policy policy; |
| 97 | struct lmv_obd *lmv = &dev->u.lmv; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 98 | |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 99 | memcpy(dummy, buffer, MAX_POLICY_STRING_SIZE); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 100 | |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 101 | if (count > MAX_POLICY_STRING_SIZE) |
| 102 | count = MAX_POLICY_STRING_SIZE; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 103 | |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 104 | if (dummy[count - 1] == '\n') |
| 105 | count--; |
| 106 | dummy[count] = '\0'; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 107 | |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 108 | policy = placement_name2policy(dummy, count); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 109 | if (policy != PLACEMENT_INVAL_POLICY) { |
| 110 | spin_lock(&lmv->lmv_lock); |
| 111 | lmv->lmv_placement = policy; |
| 112 | spin_unlock(&lmv->lmv_lock); |
| 113 | } else { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 114 | return -EINVAL; |
| 115 | } |
| 116 | return count; |
| 117 | } |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 118 | LUSTRE_RW_ATTR(placement); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 119 | |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 120 | static ssize_t activeobd_show(struct kobject *kobj, struct attribute *attr, |
| 121 | char *buf) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 122 | { |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 123 | struct obd_device *dev = container_of(kobj, struct obd_device, |
| 124 | obd_kobj); |
| 125 | struct lmv_desc *desc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 126 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 127 | desc = &dev->u.lmv.desc; |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 128 | return sprintf(buf, "%u\n", desc->ld_active_tgt_count); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 129 | } |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 130 | LUSTRE_RO_ATTR(activeobd); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 131 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 132 | static int lmv_desc_uuid_seq_show(struct seq_file *m, void *v) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 133 | { |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 134 | struct obd_device *dev = (struct obd_device *)m->private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 135 | struct lmv_obd *lmv; |
| 136 | |
Oleg Drokin | 2cbdaa4 | 2016-02-16 00:46:48 -0500 | [diff] [blame] | 137 | LASSERT(dev); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 138 | lmv = &dev->u.lmv; |
Joe Perches | 8faeebd | 2015-02-21 18:53:28 -0800 | [diff] [blame] | 139 | seq_printf(m, "%s\n", lmv->desc.ld_uuid.uuid); |
| 140 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 141 | } |
Mike Rapoport | c9f6bb9 | 2015-10-13 16:03:42 +0300 | [diff] [blame] | 142 | |
Peng Tao | 73bb1da | 2013-05-29 21:40:55 +0800 | [diff] [blame] | 143 | LPROC_SEQ_FOPS_RO(lmv_desc_uuid); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 144 | |
| 145 | static void *lmv_tgt_seq_start(struct seq_file *p, loff_t *pos) |
| 146 | { |
| 147 | struct obd_device *dev = p->private; |
| 148 | struct lmv_obd *lmv = &dev->u.lmv; |
Mike Rapoport | 50ffcb7 | 2015-10-13 16:03:40 +0300 | [diff] [blame] | 149 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 150 | return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos]; |
| 151 | } |
| 152 | |
| 153 | static void lmv_tgt_seq_stop(struct seq_file *p, void *v) |
| 154 | { |
| 155 | return; |
| 156 | } |
| 157 | |
| 158 | static void *lmv_tgt_seq_next(struct seq_file *p, void *v, loff_t *pos) |
| 159 | { |
| 160 | struct obd_device *dev = p->private; |
| 161 | struct lmv_obd *lmv = &dev->u.lmv; |
| 162 | ++*pos; |
| 163 | return (*pos >= lmv->desc.ld_tgt_count) ? NULL : lmv->tgts[*pos]; |
| 164 | } |
| 165 | |
| 166 | static int lmv_tgt_seq_show(struct seq_file *p, void *v) |
| 167 | { |
| 168 | struct lmv_tgt_desc *tgt = v; |
| 169 | |
Oleg Drokin | 2cbdaa4 | 2016-02-16 00:46:48 -0500 | [diff] [blame] | 170 | if (!tgt) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 171 | return 0; |
Joe Perches | 8faeebd | 2015-02-21 18:53:28 -0800 | [diff] [blame] | 172 | seq_printf(p, "%d: %s %sACTIVE\n", |
| 173 | tgt->ltd_idx, tgt->ltd_uuid.uuid, |
| 174 | tgt->ltd_active ? "" : "IN"); |
| 175 | return 0; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 176 | } |
| 177 | |
Xavier Roche | 02b3107 | 2015-06-05 10:19:20 +0200 | [diff] [blame] | 178 | static const struct seq_operations lmv_tgt_sops = { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 179 | .start = lmv_tgt_seq_start, |
| 180 | .stop = lmv_tgt_seq_stop, |
| 181 | .next = lmv_tgt_seq_next, |
| 182 | .show = lmv_tgt_seq_show, |
| 183 | }; |
| 184 | |
| 185 | static int lmv_target_seq_open(struct inode *inode, struct file *file) |
| 186 | { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 187 | struct seq_file *seq; |
| 188 | int rc; |
| 189 | |
| 190 | rc = seq_open(file, &lmv_tgt_sops); |
| 191 | if (rc) |
| 192 | return rc; |
| 193 | |
| 194 | seq = file->private_data; |
Dmitry Eremin | 61e87ab | 2015-05-21 15:32:27 -0400 | [diff] [blame] | 195 | seq->private = inode->i_private; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
Luca Ceresoli | 5dc8d7b | 2015-01-18 15:06:48 +0100 | [diff] [blame] | 200 | static struct lprocfs_vars lprocfs_lmv_obd_vars[] = { |
John de la Garza | f5e8269 | 2014-03-24 13:58:02 -0700 | [diff] [blame] | 201 | { "desc_uuid", &lmv_desc_uuid_fops, NULL, 0 }, |
| 202 | { NULL } |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 203 | }; |
| 204 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 205 | struct file_operations lmv_proc_target_fops = { |
| 206 | .owner = THIS_MODULE, |
| 207 | .open = lmv_target_seq_open, |
| 208 | .read = seq_read, |
| 209 | .llseek = seq_lseek, |
| 210 | .release = seq_release, |
| 211 | }; |
| 212 | |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 213 | static struct attribute *lmv_attrs[] = { |
| 214 | &lustre_attr_activeobd.attr, |
| 215 | &lustre_attr_numobd.attr, |
| 216 | &lustre_attr_placement.attr, |
| 217 | NULL, |
| 218 | }; |
| 219 | |
| 220 | static struct attribute_group lmv_attr_group = { |
| 221 | .attrs = lmv_attrs, |
| 222 | }; |
| 223 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 224 | void lprocfs_lmv_init_vars(struct lprocfs_static_vars *lvars) |
| 225 | { |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 226 | lvars->sysfs_vars = &lmv_attr_group; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 227 | lvars->obd_vars = lprocfs_lmv_obd_vars; |
| 228 | } |