sys.c 18 KB

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