sys.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/sched.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/module.h>
  14. #include <linux/kobject.h>
  15. #include <asm/uaccess.h>
  16. #include <linux/gfs2_ondisk.h>
  17. #include <linux/genhd.h>
  18. #include "gfs2.h"
  19. #include "incore.h"
  20. #include "sys.h"
  21. #include "super.h"
  22. #include "glock.h"
  23. #include "quota.h"
  24. #include "util.h"
  25. #include "glops.h"
  26. #include "recovery.h"
  27. struct gfs2_attr {
  28. struct attribute attr;
  29. ssize_t (*show)(struct gfs2_sbd *, char *);
  30. ssize_t (*store)(struct gfs2_sbd *, const char *, size_t);
  31. };
  32. static ssize_t gfs2_attr_show(struct kobject *kobj, struct attribute *attr,
  33. char *buf)
  34. {
  35. struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
  36. struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
  37. return a->show ? a->show(sdp, buf) : 0;
  38. }
  39. static ssize_t gfs2_attr_store(struct kobject *kobj, struct attribute *attr,
  40. const char *buf, size_t len)
  41. {
  42. struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
  43. struct gfs2_attr *a = container_of(attr, struct gfs2_attr, attr);
  44. return a->store ? a->store(sdp, buf, len) : len;
  45. }
  46. static const struct sysfs_ops gfs2_attr_ops = {
  47. .show = gfs2_attr_show,
  48. .store = gfs2_attr_store,
  49. };
  50. static struct kset *gfs2_kset;
  51. static ssize_t id_show(struct gfs2_sbd *sdp, char *buf)
  52. {
  53. return snprintf(buf, PAGE_SIZE, "%u:%u\n",
  54. MAJOR(sdp->sd_vfs->s_dev), MINOR(sdp->sd_vfs->s_dev));
  55. }
  56. static ssize_t fsname_show(struct gfs2_sbd *sdp, char *buf)
  57. {
  58. return snprintf(buf, PAGE_SIZE, "%s\n", sdp->sd_fsname);
  59. }
  60. static int gfs2_uuid_valid(const u8 *uuid)
  61. {
  62. int i;
  63. for (i = 0; i < 16; i++) {
  64. if (uuid[i])
  65. return 1;
  66. }
  67. return 0;
  68. }
  69. static ssize_t uuid_show(struct gfs2_sbd *sdp, char *buf)
  70. {
  71. struct super_block *s = sdp->sd_vfs;
  72. const u8 *uuid = s->s_uuid;
  73. buf[0] = '\0';
  74. if (!gfs2_uuid_valid(uuid))
  75. return 0;
  76. return snprintf(buf, PAGE_SIZE, "%pUB\n", uuid);
  77. }
  78. static ssize_t freeze_show(struct gfs2_sbd *sdp, char *buf)
  79. {
  80. unsigned int count;
  81. mutex_lock(&sdp->sd_freeze_lock);
  82. count = sdp->sd_freeze_count;
  83. mutex_unlock(&sdp->sd_freeze_lock);
  84. return snprintf(buf, PAGE_SIZE, "%u\n", count);
  85. }
  86. static ssize_t freeze_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
  87. {
  88. ssize_t ret = len;
  89. int error = 0;
  90. int n = simple_strtol(buf, NULL, 0);
  91. if (!capable(CAP_SYS_ADMIN))
  92. return -EACCES;
  93. switch (n) {
  94. case 0:
  95. gfs2_unfreeze_fs(sdp);
  96. break;
  97. case 1:
  98. error = gfs2_freeze_fs(sdp);
  99. break;
  100. default:
  101. ret = -EINVAL;
  102. }
  103. if (error)
  104. fs_warn(sdp, "freeze %d error %d", n, error);
  105. return ret;
  106. }
  107. static ssize_t withdraw_show(struct gfs2_sbd *sdp, char *buf)
  108. {
  109. unsigned int b = test_bit(SDF_SHUTDOWN, &sdp->sd_flags);
  110. return snprintf(buf, PAGE_SIZE, "%u\n", b);
  111. }
  112. static ssize_t withdraw_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
  113. {
  114. if (!capable(CAP_SYS_ADMIN))
  115. return -EACCES;
  116. if (simple_strtol(buf, NULL, 0) != 1)
  117. return -EINVAL;
  118. gfs2_lm_withdraw(sdp,
  119. "GFS2: fsid=%s: withdrawing from cluster at user's request\n",
  120. sdp->sd_fsname);
  121. return len;
  122. }
  123. static ssize_t statfs_sync_store(struct gfs2_sbd *sdp, const char *buf,
  124. size_t len)
  125. {
  126. if (!capable(CAP_SYS_ADMIN))
  127. return -EACCES;
  128. if (simple_strtol(buf, NULL, 0) != 1)
  129. return -EINVAL;
  130. gfs2_statfs_sync(sdp->sd_vfs, 0);
  131. return len;
  132. }
  133. static ssize_t quota_sync_store(struct gfs2_sbd *sdp, const char *buf,
  134. size_t len)
  135. {
  136. if (!capable(CAP_SYS_ADMIN))
  137. return -EACCES;
  138. if (simple_strtol(buf, NULL, 0) != 1)
  139. return -EINVAL;
  140. gfs2_quota_sync(sdp->sd_vfs, 0, 1);
  141. return len;
  142. }
  143. static ssize_t quota_refresh_user_store(struct gfs2_sbd *sdp, const char *buf,
  144. size_t len)
  145. {
  146. int error;
  147. u32 id;
  148. if (!capable(CAP_SYS_ADMIN))
  149. return -EACCES;
  150. id = simple_strtoul(buf, NULL, 0);
  151. error = gfs2_quota_refresh(sdp, 1, id);
  152. return error ? error : len;
  153. }
  154. static ssize_t quota_refresh_group_store(struct gfs2_sbd *sdp, const char *buf,
  155. size_t len)
  156. {
  157. int error;
  158. u32 id;
  159. if (!capable(CAP_SYS_ADMIN))
  160. return -EACCES;
  161. id = simple_strtoul(buf, NULL, 0);
  162. error = gfs2_quota_refresh(sdp, 0, id);
  163. return error ? error : len;
  164. }
  165. static ssize_t demote_rq_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
  166. {
  167. struct gfs2_glock *gl;
  168. const struct gfs2_glock_operations *glops;
  169. unsigned int glmode;
  170. unsigned int gltype;
  171. unsigned long long glnum;
  172. char mode[16];
  173. int rv;
  174. if (!capable(CAP_SYS_ADMIN))
  175. return -EACCES;
  176. rv = sscanf(buf, "%u:%llu %15s", &gltype, &glnum,
  177. mode);
  178. if (rv != 3)
  179. return -EINVAL;
  180. if (strcmp(mode, "EX") == 0)
  181. glmode = LM_ST_UNLOCKED;
  182. else if ((strcmp(mode, "CW") == 0) || (strcmp(mode, "DF") == 0))
  183. glmode = LM_ST_DEFERRED;
  184. else if ((strcmp(mode, "PR") == 0) || (strcmp(mode, "SH") == 0))
  185. glmode = LM_ST_SHARED;
  186. else
  187. return -EINVAL;
  188. if (gltype > LM_TYPE_JOURNAL)
  189. return -EINVAL;
  190. if (gltype == LM_TYPE_NONDISK && glnum == GFS2_TRANS_LOCK)
  191. glops = &gfs2_trans_glops;
  192. else
  193. glops = gfs2_glops_list[gltype];
  194. if (glops == NULL)
  195. return -EINVAL;
  196. if (!test_and_set_bit(SDF_DEMOTE, &sdp->sd_flags))
  197. fs_info(sdp, "demote interface used\n");
  198. rv = gfs2_glock_get(sdp, glnum, glops, 0, &gl);
  199. if (rv)
  200. return rv;
  201. gfs2_glock_cb(gl, glmode);
  202. gfs2_glock_put(gl);
  203. return len;
  204. }
  205. #define GFS2_ATTR(name, mode, show, store) \
  206. static struct gfs2_attr gfs2_attr_##name = __ATTR(name, mode, show, store)
  207. GFS2_ATTR(id, 0444, id_show, NULL);
  208. GFS2_ATTR(fsname, 0444, fsname_show, NULL);
  209. GFS2_ATTR(uuid, 0444, uuid_show, NULL);
  210. GFS2_ATTR(freeze, 0644, freeze_show, freeze_store);
  211. GFS2_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
  212. GFS2_ATTR(statfs_sync, 0200, NULL, statfs_sync_store);
  213. GFS2_ATTR(quota_sync, 0200, NULL, quota_sync_store);
  214. GFS2_ATTR(quota_refresh_user, 0200, NULL, quota_refresh_user_store);
  215. GFS2_ATTR(quota_refresh_group, 0200, NULL, quota_refresh_group_store);
  216. GFS2_ATTR(demote_rq, 0200, NULL, demote_rq_store);
  217. static struct attribute *gfs2_attrs[] = {
  218. &gfs2_attr_id.attr,
  219. &gfs2_attr_fsname.attr,
  220. &gfs2_attr_uuid.attr,
  221. &gfs2_attr_freeze.attr,
  222. &gfs2_attr_withdraw.attr,
  223. &gfs2_attr_statfs_sync.attr,
  224. &gfs2_attr_quota_sync.attr,
  225. &gfs2_attr_quota_refresh_user.attr,
  226. &gfs2_attr_quota_refresh_group.attr,
  227. &gfs2_attr_demote_rq.attr,
  228. NULL,
  229. };
  230. static struct kobj_type gfs2_ktype = {
  231. .default_attrs = gfs2_attrs,
  232. .sysfs_ops = &gfs2_attr_ops,
  233. };
  234. /*
  235. * lock_module. Originally from lock_dlm
  236. */
  237. static ssize_t proto_name_show(struct gfs2_sbd *sdp, char *buf)
  238. {
  239. const struct lm_lockops *ops = sdp->sd_lockstruct.ls_ops;
  240. return sprintf(buf, "%s\n", ops->lm_proto_name);
  241. }
  242. static ssize_t block_show(struct gfs2_sbd *sdp, char *buf)
  243. {
  244. struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  245. ssize_t ret;
  246. int val = 0;
  247. if (test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))
  248. val = 1;
  249. ret = sprintf(buf, "%d\n", val);
  250. return ret;
  251. }
  252. static ssize_t block_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
  253. {
  254. struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  255. ssize_t ret = len;
  256. int val;
  257. val = simple_strtol(buf, NULL, 0);
  258. if (val == 1)
  259. set_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
  260. else if (val == 0) {
  261. clear_bit(DFL_BLOCK_LOCKS, &ls->ls_flags);
  262. smp_mb__after_clear_bit();
  263. gfs2_glock_thaw(sdp);
  264. } else {
  265. ret = -EINVAL;
  266. }
  267. return ret;
  268. }
  269. static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf)
  270. {
  271. struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  272. return sprintf(buf, "%d\n", ls->ls_first);
  273. }
  274. static ssize_t lkfirst_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
  275. {
  276. unsigned first;
  277. int rv;
  278. rv = sscanf(buf, "%u", &first);
  279. if (rv != 1 || first > 1)
  280. return -EINVAL;
  281. rv = wait_for_completion_killable(&sdp->sd_locking_init);
  282. if (rv)
  283. return rv;
  284. spin_lock(&sdp->sd_jindex_spin);
  285. rv = -EBUSY;
  286. if (test_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0)
  287. goto out;
  288. rv = -EINVAL;
  289. if (sdp->sd_args.ar_spectator)
  290. goto out;
  291. if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
  292. goto out;
  293. sdp->sd_lockstruct.ls_first = first;
  294. rv = 0;
  295. out:
  296. spin_unlock(&sdp->sd_jindex_spin);
  297. return rv ? rv : len;
  298. }
  299. static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf)
  300. {
  301. struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  302. return sprintf(buf, "%d\n", ls->ls_first_done);
  303. }
  304. static ssize_t recover_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
  305. {
  306. unsigned jid;
  307. struct gfs2_jdesc *jd;
  308. int rv;
  309. rv = sscanf(buf, "%u", &jid);
  310. if (rv != 1)
  311. return -EINVAL;
  312. rv = -ESHUTDOWN;
  313. spin_lock(&sdp->sd_jindex_spin);
  314. if (test_bit(SDF_NORECOVERY, &sdp->sd_flags))
  315. goto out;
  316. rv = -EBUSY;
  317. if (sdp->sd_jdesc->jd_jid == jid)
  318. goto out;
  319. rv = -ENOENT;
  320. list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
  321. if (jd->jd_jid != jid)
  322. continue;
  323. rv = gfs2_recover_journal(jd, false);
  324. break;
  325. }
  326. out:
  327. spin_unlock(&sdp->sd_jindex_spin);
  328. return rv ? rv : len;
  329. }
  330. static ssize_t recover_done_show(struct gfs2_sbd *sdp, char *buf)
  331. {
  332. struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  333. return sprintf(buf, "%d\n", ls->ls_recover_jid_done);
  334. }
  335. static ssize_t recover_status_show(struct gfs2_sbd *sdp, char *buf)
  336. {
  337. struct lm_lockstruct *ls = &sdp->sd_lockstruct;
  338. return sprintf(buf, "%d\n", ls->ls_recover_jid_status);
  339. }
  340. static ssize_t jid_show(struct gfs2_sbd *sdp, char *buf)
  341. {
  342. return sprintf(buf, "%d\n", sdp->sd_lockstruct.ls_jid);
  343. }
  344. static ssize_t jid_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
  345. {
  346. int jid;
  347. int rv;
  348. rv = sscanf(buf, "%d", &jid);
  349. if (rv != 1)
  350. return -EINVAL;
  351. rv = wait_for_completion_killable(&sdp->sd_locking_init);
  352. if (rv)
  353. return rv;
  354. spin_lock(&sdp->sd_jindex_spin);
  355. rv = -EINVAL;
  356. if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
  357. goto out;
  358. rv = -EBUSY;
  359. if (test_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0)
  360. goto out;
  361. rv = 0;
  362. if (sdp->sd_args.ar_spectator && jid > 0)
  363. rv = jid = -EINVAL;
  364. sdp->sd_lockstruct.ls_jid = jid;
  365. clear_bit(SDF_NOJOURNALID, &sdp->sd_flags);
  366. smp_mb__after_clear_bit();
  367. wake_up_bit(&sdp->sd_flags, SDF_NOJOURNALID);
  368. out:
  369. spin_unlock(&sdp->sd_jindex_spin);
  370. return rv ? rv : len;
  371. }
  372. #define GDLM_ATTR(_name,_mode,_show,_store) \
  373. static struct gfs2_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
  374. GDLM_ATTR(proto_name, 0444, proto_name_show, NULL);
  375. GDLM_ATTR(block, 0644, block_show, block_store);
  376. GDLM_ATTR(withdraw, 0644, withdraw_show, withdraw_store);
  377. GDLM_ATTR(jid, 0644, jid_show, jid_store);
  378. GDLM_ATTR(first, 0644, lkfirst_show, lkfirst_store);
  379. GDLM_ATTR(first_done, 0444, first_done_show, NULL);
  380. GDLM_ATTR(recover, 0600, NULL, recover_store);
  381. GDLM_ATTR(recover_done, 0444, recover_done_show, NULL);
  382. GDLM_ATTR(recover_status, 0444, recover_status_show, NULL);
  383. static struct attribute *lock_module_attrs[] = {
  384. &gdlm_attr_proto_name.attr,
  385. &gdlm_attr_block.attr,
  386. &gdlm_attr_withdraw.attr,
  387. &gdlm_attr_jid.attr,
  388. &gdlm_attr_first.attr,
  389. &gdlm_attr_first_done.attr,
  390. &gdlm_attr_recover.attr,
  391. &gdlm_attr_recover_done.attr,
  392. &gdlm_attr_recover_status.attr,
  393. NULL,
  394. };
  395. /*
  396. * get and set struct gfs2_tune fields
  397. */
  398. static ssize_t quota_scale_show(struct gfs2_sbd *sdp, char *buf)
  399. {
  400. return snprintf(buf, PAGE_SIZE, "%u %u\n",
  401. sdp->sd_tune.gt_quota_scale_num,
  402. sdp->sd_tune.gt_quota_scale_den);
  403. }
  404. static ssize_t quota_scale_store(struct gfs2_sbd *sdp, const char *buf,
  405. size_t len)
  406. {
  407. struct gfs2_tune *gt = &sdp->sd_tune;
  408. unsigned int x, y;
  409. if (!capable(CAP_SYS_ADMIN))
  410. return -EACCES;
  411. if (sscanf(buf, "%u %u", &x, &y) != 2 || !y)
  412. return -EINVAL;
  413. spin_lock(&gt->gt_spin);
  414. gt->gt_quota_scale_num = x;
  415. gt->gt_quota_scale_den = y;
  416. spin_unlock(&gt->gt_spin);
  417. return len;
  418. }
  419. static ssize_t tune_set(struct gfs2_sbd *sdp, unsigned int *field,
  420. int check_zero, const char *buf, size_t len)
  421. {
  422. struct gfs2_tune *gt = &sdp->sd_tune;
  423. unsigned int x;
  424. if (!capable(CAP_SYS_ADMIN))
  425. return -EACCES;
  426. x = simple_strtoul(buf, NULL, 0);
  427. if (check_zero && !x)
  428. return -EINVAL;
  429. spin_lock(&gt->gt_spin);
  430. *field = x;
  431. spin_unlock(&gt->gt_spin);
  432. return len;
  433. }
  434. #define TUNE_ATTR_3(name, show, store) \
  435. static struct gfs2_attr tune_attr_##name = __ATTR(name, 0644, show, store)
  436. #define TUNE_ATTR_2(name, store) \
  437. static ssize_t name##_show(struct gfs2_sbd *sdp, char *buf) \
  438. { \
  439. return snprintf(buf, PAGE_SIZE, "%u\n", sdp->sd_tune.gt_##name); \
  440. } \
  441. TUNE_ATTR_3(name, name##_show, store)
  442. #define TUNE_ATTR(name, check_zero) \
  443. static ssize_t name##_store(struct gfs2_sbd *sdp, const char *buf, size_t len)\
  444. { \
  445. return tune_set(sdp, &sdp->sd_tune.gt_##name, check_zero, buf, len); \
  446. } \
  447. TUNE_ATTR_2(name, name##_store)
  448. TUNE_ATTR(quota_warn_period, 0);
  449. TUNE_ATTR(quota_quantum, 0);
  450. TUNE_ATTR(max_readahead, 0);
  451. TUNE_ATTR(complain_secs, 0);
  452. TUNE_ATTR(statfs_slow, 0);
  453. TUNE_ATTR(new_files_jdata, 0);
  454. TUNE_ATTR(quota_simul_sync, 1);
  455. TUNE_ATTR(statfs_quantum, 1);
  456. TUNE_ATTR_3(quota_scale, quota_scale_show, quota_scale_store);
  457. static struct attribute *tune_attrs[] = {
  458. &tune_attr_quota_warn_period.attr,
  459. &tune_attr_quota_quantum.attr,
  460. &tune_attr_max_readahead.attr,
  461. &tune_attr_complain_secs.attr,
  462. &tune_attr_statfs_slow.attr,
  463. &tune_attr_quota_simul_sync.attr,
  464. &tune_attr_statfs_quantum.attr,
  465. &tune_attr_quota_scale.attr,
  466. &tune_attr_new_files_jdata.attr,
  467. NULL,
  468. };
  469. static struct attribute_group tune_group = {
  470. .name = "tune",
  471. .attrs = tune_attrs,
  472. };
  473. static struct attribute_group lock_module_group = {
  474. .name = "lock_module",
  475. .attrs = lock_module_attrs,
  476. };
  477. int gfs2_sys_fs_add(struct gfs2_sbd *sdp)
  478. {
  479. struct super_block *sb = sdp->sd_vfs;
  480. int error;
  481. char ro[20];
  482. char spectator[20];
  483. char *envp[] = { ro, spectator, NULL };
  484. sprintf(ro, "RDONLY=%d", (sb->s_flags & MS_RDONLY) ? 1 : 0);
  485. sprintf(spectator, "SPECTATOR=%d", sdp->sd_args.ar_spectator ? 1 : 0);
  486. sdp->sd_kobj.kset = gfs2_kset;
  487. error = kobject_init_and_add(&sdp->sd_kobj, &gfs2_ktype, NULL,
  488. "%s", sdp->sd_table_name);
  489. if (error)
  490. goto fail;
  491. error = sysfs_create_group(&sdp->sd_kobj, &tune_group);
  492. if (error)
  493. goto fail_reg;
  494. error = sysfs_create_group(&sdp->sd_kobj, &lock_module_group);
  495. if (error)
  496. goto fail_tune;
  497. error = sysfs_create_link(&sdp->sd_kobj,
  498. &disk_to_dev(sb->s_bdev->bd_disk)->kobj,
  499. "device");
  500. if (error)
  501. goto fail_lock_module;
  502. kobject_uevent_env(&sdp->sd_kobj, KOBJ_ADD, envp);
  503. return 0;
  504. fail_lock_module:
  505. sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
  506. fail_tune:
  507. sysfs_remove_group(&sdp->sd_kobj, &tune_group);
  508. fail_reg:
  509. kobject_put(&sdp->sd_kobj);
  510. fail:
  511. fs_err(sdp, "error %d adding sysfs files", error);
  512. return error;
  513. }
  514. void gfs2_sys_fs_del(struct gfs2_sbd *sdp)
  515. {
  516. sysfs_remove_link(&sdp->sd_kobj, "device");
  517. sysfs_remove_group(&sdp->sd_kobj, &tune_group);
  518. sysfs_remove_group(&sdp->sd_kobj, &lock_module_group);
  519. kobject_put(&sdp->sd_kobj);
  520. }
  521. static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
  522. struct kobj_uevent_env *env)
  523. {
  524. struct gfs2_sbd *sdp = container_of(kobj, struct gfs2_sbd, sd_kobj);
  525. struct super_block *s = sdp->sd_vfs;
  526. const u8 *uuid = s->s_uuid;
  527. add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name);
  528. add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name);
  529. if (!test_bit(SDF_NOJOURNALID, &sdp->sd_flags))
  530. add_uevent_var(env, "JOURNALID=%d", sdp->sd_lockstruct.ls_jid);
  531. if (gfs2_uuid_valid(uuid))
  532. add_uevent_var(env, "UUID=%pUB", uuid);
  533. return 0;
  534. }
  535. static const struct kset_uevent_ops gfs2_uevent_ops = {
  536. .uevent = gfs2_uevent,
  537. };
  538. int gfs2_sys_init(void)
  539. {
  540. gfs2_kset = kset_create_and_add("gfs2", &gfs2_uevent_ops, fs_kobj);
  541. if (!gfs2_kset)
  542. return -ENOMEM;
  543. return 0;
  544. }
  545. void gfs2_sys_uninit(void)
  546. {
  547. kset_unregister(gfs2_kset);
  548. }