sys.c 18 KB

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