1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved. 4 * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved. 5 */ 6 7 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 8 9 #include <linux/sched.h> 10 #include <linux/cred.h> 11 #include <linux/spinlock.h> 12 #include <linux/completion.h> 13 #include <linux/buffer_head.h> 14 #include <linux/module.h> 15 #include <linux/kobject.h> 16 #include <linux/uaccess.h> 17 #include <linux/gfs2_ondisk.h> 18 #include <linux/genhd.h> 19 20 #include "gfs2.h" 21 #include "incore.h" 22 #include "sys.h" 23 #include "super.h" 24 #include "glock.h" 25 #include "quota.h" 26 #include "util.h" 27 #include "glops.h" 28 #include "recovery.h" 29 30 struct gfs2_attr { 31 struct attribute attr; 32 ssize_t (*show)(struct gfs2_sbd *, char *); 33 ssize_t (*store)(struct gfs2_sbd *, const char *, size_t); 34 }; 35 36 static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr, 37 char *buf) 38 { 39 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); 40 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); 41 return a->show ? a->show(sdp, buf) : 0; 42 } 43 44 static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr, 45 const char *buf, size_t len) 46 { 47 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); 48 struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr); 49 return a->store ? a->store(sdp, buf, len) : len; 50 } 51 52 static const struct sysfs_ops gfs2_attr_ops = { 53 .show = gfs2_attr_show, 54 .store = gfs2_attr_store, 55 }; 56 57 58 static struct kset *gfs2_kset; 59 60 static ssize_t id_show(struct gfs2_sbd *sdp, char *buf) 61 { 62 return snprintf(buf, PAGE_SIZE, "%u:%u\n", 63 MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev)); 64 } 65 66 static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf) 67 { 68 return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname); 69 } 70 71 static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf) 72 { 73 struct super_block *s = sdp->sd_vfs; 74 75 buf[0] = '\0'; 76 if (uuid_is_null(&s->s_uuid)) 77 return 0; 78 return snprintf(buf, PAGE_SIZE, "%pUB\n", &s->s_uuid); 79 } 80 81 static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf) 82 { 83 struct super_block *sb = sdp->sd_vfs; 84 int frozen = (sb->s_writers.frozen == SB_UNFROZEN) ? 0 : 1; 85 86 return snprintf(buf, PAGE_SIZE, "%d\n", frozen); 87 } 88 89 static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len) 90 { 91 int error, n; 92 93 error = kstrtoint(buf, 0, &n); 94 if (error) 95 return error; 96 97 if (!capable(CAP_SYS_ADMIN)) 98 return -EPERM; 99 100 switch (n) { 101 case 0: 102 error = thaw_super(sdp->sd_vfs); 103 break; 104 case 1: 105 error = freeze_super(sdp->sd_vfs); 106 break; 107 default: 108 return -EINVAL; 109 } 110 111 if (error) { 112 fs_warn(sdp, "freeze %d error %d\n", n, error); 113 return error; 114 } 115 116 return len; 117 } 118 119 static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf) 120 { 121 unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags); 122 return snprintf(buf, PAGE_SIZE, "%u\n", b); 123 } 124 125 static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len) 126 { 127 int error, val; 128 129 if (!capable(CAP_SYS_ADMIN)) 130 return -EPERM; 131 132 error = kstrtoint(buf, 0, &val); 133 if (error) 134 return error; 135 136 if (val != 1) 137 return -EINVAL; 138 139 gfs2_lm_withdraw(sdp, "withdrawing from cluster at user's request\n"); 140 141 return len; 142 } 143 144 static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf, 145 size_t len) 146 { 147 int error, val; 148 149 if (!capable(CAP_SYS_ADMIN)) 150 return -EPERM; 151 152 error = kstrtoint(buf, 0, &val); 153 if (error) 154 return error; 155 156 if (val != 1) 157 return -EINVAL; 158 159 gfs2_statfs_sync(sdp->sd_vfs, 0); 160 return len; 161 } 162 163 static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf, 164 size_t len) 165 { 166 int error, val; 167 168 if (!capable(CAP_SYS_ADMIN)) 169 return -EPERM; 170 171 error = kstrtoint(buf, 0, &val); 172 if (error) 173 return error; 174 175 if (val != 1) 176 return -EINVAL; 177 178 gfs2_quota_sync(sdp->sd_vfs, 0); 179 return len; 180 } 181 182 static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf, 183 size_t len) 184 { 185 struct kqid qid; 186 int error; 187 u32 id; 188 189 if (!capable(CAP_SYS_ADMIN)) 190 return -EPERM; 191 192 error = kstrtou32(buf, 0, &id); 193 if (error) 194 return error; 195 196 qid = make_kqid(current_user_ns(), USRQUOTA, id); 197 if (!qid_valid(qid)) 198 return -EINVAL; 199 200 error = gfs2_quota_refresh(sdp, qid); 201 return error ? error : len; 202 } 203 204 static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf, 205 size_t len) 206 { 207 struct kqid qid; 208 int error; 209 u32 id; 210 211 if (!capable(CAP_SYS_ADMIN)) 212 return -EPERM; 213 214 error = kstrtou32(buf, 0, &id); 215 if (error) 216 return error; 217 218 qid = make_kqid(current_user_ns(), GRPQUOTA, id); 219 if (!qid_valid(qid)) 220 return -EINVAL; 221 222 error = gfs2_quota_refresh(sdp, qid); 223 return error ? error : len; 224 } 225 226 static ssize_t demote_rq_store(struct gfs2_sbd *sdp, const char *buf, size_t len) 227 { 228 struct gfs2_glock *gl; 229 const struct gfs2_glock_operations *glops; 230 unsigned int glmode; 231 unsigned int gltype; 232 unsigned long long glnum; 233 char mode[16]; 234 int rv; 235 236 if (!capable(CAP_SYS_ADMIN)) 237 return -EPERM; 238 239 rv = sscanf(buf, "%u:%llu %15s", &gltype, &glnum, 240 mode); 241 if (rv != 3) 242 return -EINVAL; 243 244 if (strcmp(mode, "EX") == 0) 245 glmode = LM_ST_UNLOCKED; 246 else if ((strcmp(mode, "CW") == 0) || (strcmp(mode, "DF") == 0)) 247 glmode = LM_ST_DEFERRED; 248 else if ((strcmp(mode, "PR") == 0) || (strcmp(mode, "SH") == 0)) 249 glmode = LM_ST_SHARED; 250 else 251 return -EINVAL; 252 253 if (gltype > LM_TYPE_JOURNAL) 254 return -EINVAL; 255 if (gltype == LM_TYPE_NONDISK && glnum == GFS2_FREEZE_LOCK) 256 glops = &gfs2_freeze_glops; 257 else 258 glops = gfs2_glops_list[gltype]; 259 if (glops == NULL) 260 return -EINVAL; 261 if (!test_and_set_bit(SDF_DEMOTE, &sdp->sd_flags)) 262 fs_info(sdp, "demote interface used\n"); 263 rv = gfs2_glock_get(sdp, glnum, glops, 0, &gl); 264 if (rv) 265 return rv; 266 gfs2_glock_cb(gl, glmode); 267 gfs2_glock_put(gl); 268 return len; 269 } 270 271 272 #define GFS2_ATTR(name, mode, show, store) \ 273 static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store) 274 275 GFS2_ATTR(id, 0444, id_show, NULL); 276 GFS2_ATTR(fsname, 0444, fsname_show, NULL); 277 GFS2_ATTR(uuid, 0444, uuid_show, NULL); 278 GFS2_ATTR(freeze, 0644, freeze_show, freeze_store); 279 GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store); 280 GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store); 281 GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store); 282 GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store); 283 GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store); 284 GFS2_ATTR(demote_rq, 0200, NULL, demote_rq_store); 285 286 static struct attribute *gfs2_attrs[] = { 287 &gfs2_attr_id.attr, 288 &gfs2_attr_fsname.attr, 289 &gfs2_attr_uuid.attr, 290 &gfs2_attr_freeze.attr, 291 &gfs2_attr_withdraw.attr, 292 &gfs2_attr_statfs_sync.attr, 293 &gfs2_attr_quota_sync.attr, 294 &gfs2_attr_quota_refresh_user.attr, 295 &gfs2_attr_quota_refresh_group.attr, 296 &gfs2_attr_demote_rq.attr, 297 NULL, 298 }; 299 300 static void gfs2_sbd_release(struct kobject *kobj) 301 { 302 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); 303 304 kfree(sdp); 305 } 306 307 static struct kobj_type gfs2_ktype = { 308 .release = gfs2_sbd_release, 309 .default_attrs = gfs2_attrs, 310 .sysfs_ops = &gfs2_attr_ops, 311 }; 312 313 314 /* 315 * lock_module. Originally from lock_dlm 316 */ 317 318 static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf) 319 { 320 const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops; 321 return sprintf(buf, "%s\n", ops->lm_proto_name); 322 } 323 324 static ssize_t block_show(struct gfs2_sbd *sdp, char *buf) 325 { 326 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 327 ssize_t ret; 328 int val = 0; 329 330 if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags)) 331 val = 1; 332 ret = sprintf(buf, "%d\n", val); 333 return ret; 334 } 335 336 static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len) 337 { 338 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 339 int ret, val; 340 341 ret = kstrtoint(buf, 0, &val); 342 if (ret) 343 return ret; 344 345 if (val == 1) 346 set_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags); 347 else if (val == 0) { 348 clear_bit(DFL_BLOCK_LOCKS, &ls->ls_recover_flags); 349 smp_mb__after_atomic(); 350 gfs2_glock_thaw(sdp); 351 } else { 352 return -EINVAL; 353 } 354 return len; 355 } 356 357 static ssize_t wdack_show(struct gfs2_sbd *sdp, char *buf) 358 { 359 int val = completion_done(&sdp->sd_wdack) ? 1 : 0; 360 361 return sprintf(buf, "%d\n", val); 362 } 363 364 static ssize_t wdack_store(struct gfs2_sbd *sdp, const char *buf, size_t len) 365 { 366 int ret, val; 367 368 ret = kstrtoint(buf, 0, &val); 369 if (ret) 370 return ret; 371 372 if ((val == 1) && 373 !strcmp(sdp->sd_lockstruct.ls_ops->lm_proto_name, "lock_dlm")) 374 complete(&sdp->sd_wdack); 375 else 376 return -EINVAL; 377 return len; 378 } 379 380 static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf) 381 { 382 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 383 return sprintf(buf, "%d\n", ls->ls_first); 384 } 385 386 static ssize_t lkfirst_store(struct gfs2_sbd *sdp, const char *buf, size_t len) 387 { 388 unsigned first; 389 int rv; 390 391 rv = sscanf(buf, "%u", &first); 392 if (rv != 1 || first > 1) 393 return -EINVAL; 394 rv = wait_for_completion_killable(&sdp->sd_locking_init); 395 if (rv) 396 return rv; 397 spin_lock(&sdp->sd_jindex_spin); 398 rv = -EBUSY; 399 if (test_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0) 400 goto out; 401 rv = -EINVAL; 402 if (sdp->sd_args.ar_spectator) 403 goto out; 404 if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) 405 goto out; 406 sdp->sd_lockstruct.ls_first = first; 407 rv = 0; 408 out: 409 spin_unlock(&sdp->sd_jindex_spin); 410 return rv ? rv : len; 411 } 412 413 static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf) 414 { 415 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 416 return sprintf(buf, "%d\n", !!test_bit(DFL_FIRST_MOUNT_DONE, &ls->ls_recover_flags)); 417 } 418 419 int gfs2_recover_set(struct gfs2_sbd *sdp, unsigned jid) 420 { 421 struct gfs2_jdesc *jd; 422 int rv; 423 424 /* Wait for our primary journal to be initialized */ 425 wait_for_completion(&sdp->sd_journal_ready); 426 427 spin_lock(&sdp->sd_jindex_spin); 428 rv = -EBUSY; 429 /** 430 * If we're a spectator, we use journal0, but it's not really ours. 431 * So we need to wait for its recovery too. If we skip it we'd never 432 * queue work to the recovery workqueue, and so its completion would 433 * never clear the DFL_BLOCK_LOCKS flag, so all our locks would 434 * permanently stop working. 435 */ 436 if (sdp->sd_jdesc->jd_jid == jid && !sdp->sd_args.ar_spectator) 437 goto out; 438 rv = -ENOENT; 439 list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) { 440 if (jd->jd_jid != jid && !sdp->sd_args.ar_spectator) 441 continue; 442 rv = gfs2_recover_journal(jd, false); 443 break; 444 } 445 out: 446 spin_unlock(&sdp->sd_jindex_spin); 447 return rv; 448 } 449 450 static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len) 451 { 452 unsigned jid; 453 int rv; 454 455 rv = sscanf(buf, "%u", &jid); 456 if (rv != 1) 457 return -EINVAL; 458 459 if (test_bit(SDF_NORECOVERY, &sdp->sd_flags)) { 460 rv = -ESHUTDOWN; 461 goto out; 462 } 463 464 rv = gfs2_recover_set(sdp, jid); 465 out: 466 return rv ? rv : len; 467 } 468 469 static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf) 470 { 471 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 472 return sprintf(buf, "%d\n", ls->ls_recover_jid_done); 473 } 474 475 static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf) 476 { 477 struct lm_lockstruct *ls = &sdp->sd_lockstruct; 478 return sprintf(buf, "%d\n", ls->ls_recover_jid_status); 479 } 480 481 static ssize_t jid_show(struct gfs2_sbd *sdp, char *buf) 482 { 483 return sprintf(buf, "%d\n", sdp->sd_lockstruct.ls_jid); 484 } 485 486 static ssize_t jid_store(struct gfs2_sbd *sdp, const char *buf, size_t len) 487 { 488 int jid; 489 int rv; 490 491 rv = sscanf(buf, "%d", &jid); 492 if (rv != 1) 493 return -EINVAL; 494 rv = wait_for_completion_killable(&sdp->sd_locking_init); 495 if (rv) 496 return rv; 497 spin_lock(&sdp->sd_jindex_spin); 498 rv = -EINVAL; 499 if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL) 500 goto out; 501 rv = -EBUSY; 502 if (test_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0) 503 goto out; 504 rv = 0; 505 if (sdp->sd_args.ar_spectator && jid > 0) 506 rv = jid = -EINVAL; 507 sdp->sd_lockstruct.ls_jid = jid; 508 clear_bit(SDF_NOJOURNALID, &sdp->sd_flags); 509 smp_mb__after_atomic(); 510 wake_up_bit(&sdp->sd_flags, SDF_NOJOURNALID); 511 out: 512 spin_unlock(&sdp->sd_jindex_spin); 513 return rv ? rv : len; 514 } 515 516 #define GDLM_ATTR(_name,_mode,_show,_store) \ 517 static struct gfs2_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store) 518 519 GDLM_ATTR(proto_name, 0444, proto_name_show, NULL); 520 GDLM_ATTR(block, 0644, block_show, block_store); 521 GDLM_ATTR(withdraw, 0644, wdack_show, wdack_store); 522 GDLM_ATTR(jid, 0644, jid_show, jid_store); 523 GDLM_ATTR(first, 0644, lkfirst_show, lkfirst_store); 524 GDLM_ATTR(first_done, 0444, first_done_show, NULL); 525 GDLM_ATTR(recover, 0600, NULL, recover_store); 526 GDLM_ATTR(recover_done, 0444, recover_done_show, NULL); 527 GDLM_ATTR(recover_status, 0444, recover_status_show, NULL); 528 529 static struct attribute *lock_module_attrs[] = { 530 &gdlm_attr_proto_name.attr, 531 &gdlm_attr_block.attr, 532 &gdlm_attr_withdraw.attr, 533 &gdlm_attr_jid.attr, 534 &gdlm_attr_first.attr, 535 &gdlm_attr_first_done.attr, 536 &gdlm_attr_recover.attr, 537 &gdlm_attr_recover_done.attr, 538 &gdlm_attr_recover_status.attr, 539 NULL, 540 }; 541 542 /* 543 * get and set struct gfs2_tune fields 544 */ 545 546 static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf) 547 { 548 return snprintf(buf, PAGE_SIZE, "%u %u\n", 549 sdp->sd_tune.gt_quota_scale_num, 550 sdp->sd_tune.gt_quota_scale_den); 551 } 552 553 static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf, 554 size_t len) 555 { 556 struct gfs2_tune *gt = &sdp->sd_tune; 557 unsigned int x, y; 558 559 if (!capable(CAP_SYS_ADMIN)) 560 return -EPERM; 561 562 if (sscanf(buf, "%u %u", &x, &y) != 2 || !y) 563 return -EINVAL; 564 565 spin_lock(>->gt_spin); 566 gt->gt_quota_scale_num = x; 567 gt->gt_quota_scale_den = y; 568 spin_unlock(>->gt_spin); 569 return len; 570 } 571 572 static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field, 573 int check_zero, const char *buf, size_t len) 574 { 575 struct gfs2_tune *gt = &sdp->sd_tune; 576 unsigned int x; 577 int error; 578 579 if (!capable(CAP_SYS_ADMIN)) 580 return -EPERM; 581 582 error = kstrtouint(buf, 0, &x); 583 if (error) 584 return error; 585 586 if (check_zero && !x) 587 return -EINVAL; 588 589 spin_lock(>->gt_spin); 590 *field = x; 591 spin_unlock(>->gt_spin); 592 return len; 593 } 594 595 #define TUNE_ATTR_3(name, show, store) \ 596 static struct gfs2_attr tune_attr_##name = __ATTR(name, 0644, show, store) 597 598 #define TUNE_ATTR_2(name, store) \ 599 static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \ 600 { \ 601 return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \ 602 } \ 603 TUNE_ATTR_3(name, name##_show, store) 604 605 #define TUNE_ATTR(name, check_zero) \ 606 static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\ 607 { \ 608 return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \ 609 } \ 610 TUNE_ATTR_2(name, name##_store) 611 612 TUNE_ATTR(quota_warn_period, 0); 613 TUNE_ATTR(quota_quantum, 0); 614 TUNE_ATTR(max_readahead, 0); 615 TUNE_ATTR(complain_secs, 0); 616 TUNE_ATTR(statfs_slow, 0); 617 TUNE_ATTR(new_files_jdata, 0); 618 TUNE_ATTR(statfs_quantum, 1); 619 TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store); 620 621 static struct attribute *tune_attrs[] = { 622 &tune_attr_quota_warn_period.attr, 623 &tune_attr_quota_quantum.attr, 624 &tune_attr_max_readahead.attr, 625 &tune_attr_complain_secs.attr, 626 &tune_attr_statfs_slow.attr, 627 &tune_attr_statfs_quantum.attr, 628 &tune_attr_quota_scale.attr, 629 &tune_attr_new_files_jdata.attr, 630 NULL, 631 }; 632 633 static const struct attribute_group tune_group = { 634 .name = "tune", 635 .attrs = tune_attrs, 636 }; 637 638 static const struct attribute_group lock_module_group = { 639 .name = "lock_module", 640 .attrs = lock_module_attrs, 641 }; 642 643 int gfs2_sys_fs_add(struct gfs2_sbd *sdp) 644 { 645 struct super_block *sb = sdp->sd_vfs; 646 int error; 647 char ro[20]; 648 char spectator[20]; 649 char *envp[] = { ro, spectator, NULL }; 650 651 sprintf(ro, "RDONLY=%d", sb_rdonly(sb)); 652 sprintf(spectator, "SPECTATOR=%d", sdp->sd_args.ar_spectator ? 1 : 0); 653 654 sdp->sd_kobj.kset = gfs2_kset; 655 error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL, 656 "%s", sdp->sd_table_name); 657 if (error) 658 goto fail_reg; 659 660 error = sysfs_create_group(&sdp->sd_kobj, &tune_group); 661 if (error) 662 goto fail_reg; 663 664 error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group); 665 if (error) 666 goto fail_tune; 667 668 error = sysfs_create_link(&sdp->sd_kobj, 669 &disk_to_dev(sb->s_bdev->bd_disk)->kobj, 670 "device"); 671 if (error) 672 goto fail_lock_module; 673 674 kobject_uevent_env(&sdp->sd_kobj, KOBJ_ADD, envp); 675 return 0; 676 677 fail_lock_module: 678 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group); 679 fail_tune: 680 sysfs_remove_group(&sdp->sd_kobj, &tune_group); 681 fail_reg: 682 free_percpu(sdp->sd_lkstats); 683 fs_err(sdp, "error %d adding sysfs files\n", error); 684 kobject_put(&sdp->sd_kobj); 685 sb->s_fs_info = NULL; 686 return error; 687 } 688 689 void gfs2_sys_fs_del(struct gfs2_sbd *sdp) 690 { 691 sysfs_remove_link(&sdp->sd_kobj, "device"); 692 sysfs_remove_group(&sdp->sd_kobj, &tune_group); 693 sysfs_remove_group(&sdp->sd_kobj, &lock_module_group); 694 kobject_put(&sdp->sd_kobj); 695 } 696 697 static int gfs2_uevent(struct kset *kset, struct kobject *kobj, 698 struct kobj_uevent_env *env) 699 { 700 struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj); 701 struct super_block *s = sdp->sd_vfs; 702 703 add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name); 704 add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name); 705 if (!test_bit(SDF_NOJOURNALID, &sdp->sd_flags)) 706 add_uevent_var(env, "JOURNALID=%d", sdp->sd_lockstruct.ls_jid); 707 if (!uuid_is_null(&s->s_uuid)) 708 add_uevent_var(env, "UUID=%pUB", &s->s_uuid); 709 return 0; 710 } 711 712 static const struct kset_uevent_ops gfs2_uevent_ops = { 713 .uevent = gfs2_uevent, 714 }; 715 716 int gfs2_sys_init(void) 717 { 718 gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj); 719 if (!gfs2_kset) 720 return -ENOMEM; 721 return 0; 722 } 723 724 void gfs2_sys_uninit(void) 725 { 726 kset_unregister(gfs2_kset); 727 } 728 729