super.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2007 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/bio.h>
  10. #include <linux/sched.h>
  11. #include <linux/slab.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/completion.h>
  14. #include <linux/buffer_head.h>
  15. #include <linux/statfs.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/mount.h>
  18. #include <linux/kthread.h>
  19. #include <linux/delay.h>
  20. #include <linux/gfs2_ondisk.h>
  21. #include <linux/crc32.h>
  22. #include <linux/time.h>
  23. #include <linux/wait.h>
  24. #include <linux/writeback.h>
  25. #include "gfs2.h"
  26. #include "incore.h"
  27. #include "bmap.h"
  28. #include "dir.h"
  29. #include "glock.h"
  30. #include "glops.h"
  31. #include "inode.h"
  32. #include "log.h"
  33. #include "meta_io.h"
  34. #include "quota.h"
  35. #include "recovery.h"
  36. #include "rgrp.h"
  37. #include "super.h"
  38. #include "trans.h"
  39. #include "util.h"
  40. #include "sys.h"
  41. #include "xattr.h"
  42. #define args_neq(a1, a2, x) ((a1)->ar_##x != (a2)->ar_##x)
  43. enum {
  44. Opt_lockproto,
  45. Opt_locktable,
  46. Opt_hostdata,
  47. Opt_spectator,
  48. Opt_ignore_local_fs,
  49. Opt_localflocks,
  50. Opt_localcaching,
  51. Opt_debug,
  52. Opt_nodebug,
  53. Opt_upgrade,
  54. Opt_acl,
  55. Opt_noacl,
  56. Opt_quota_off,
  57. Opt_quota_account,
  58. Opt_quota_on,
  59. Opt_quota,
  60. Opt_noquota,
  61. Opt_suiddir,
  62. Opt_nosuiddir,
  63. Opt_data_writeback,
  64. Opt_data_ordered,
  65. Opt_meta,
  66. Opt_discard,
  67. Opt_nodiscard,
  68. Opt_commit,
  69. Opt_err_withdraw,
  70. Opt_err_panic,
  71. Opt_statfs_quantum,
  72. Opt_statfs_percent,
  73. Opt_quota_quantum,
  74. Opt_barrier,
  75. Opt_nobarrier,
  76. Opt_error,
  77. };
  78. static const match_table_t tokens = {
  79. {Opt_lockproto, "lockproto=%s"},
  80. {Opt_locktable, "locktable=%s"},
  81. {Opt_hostdata, "hostdata=%s"},
  82. {Opt_spectator, "spectator"},
  83. {Opt_ignore_local_fs, "ignore_local_fs"},
  84. {Opt_localflocks, "localflocks"},
  85. {Opt_localcaching, "localcaching"},
  86. {Opt_debug, "debug"},
  87. {Opt_nodebug, "nodebug"},
  88. {Opt_upgrade, "upgrade"},
  89. {Opt_acl, "acl"},
  90. {Opt_noacl, "noacl"},
  91. {Opt_quota_off, "quota=off"},
  92. {Opt_quota_account, "quota=account"},
  93. {Opt_quota_on, "quota=on"},
  94. {Opt_quota, "quota"},
  95. {Opt_noquota, "noquota"},
  96. {Opt_suiddir, "suiddir"},
  97. {Opt_nosuiddir, "nosuiddir"},
  98. {Opt_data_writeback, "data=writeback"},
  99. {Opt_data_ordered, "data=ordered"},
  100. {Opt_meta, "meta"},
  101. {Opt_discard, "discard"},
  102. {Opt_nodiscard, "nodiscard"},
  103. {Opt_commit, "commit=%d"},
  104. {Opt_err_withdraw, "errors=withdraw"},
  105. {Opt_err_panic, "errors=panic"},
  106. {Opt_statfs_quantum, "statfs_quantum=%d"},
  107. {Opt_statfs_percent, "statfs_percent=%d"},
  108. {Opt_quota_quantum, "quota_quantum=%d"},
  109. {Opt_barrier, "barrier"},
  110. {Opt_nobarrier, "nobarrier"},
  111. {Opt_error, NULL}
  112. };
  113. /**
  114. * gfs2_mount_args - Parse mount options
  115. * @args: The structure into which the parsed options will be written
  116. * @options: The options to parse
  117. *
  118. * Return: errno
  119. */
  120. int gfs2_mount_args(struct gfs2_args *args, char *options)
  121. {
  122. char *o;
  123. int token;
  124. substring_t tmp[MAX_OPT_ARGS];
  125. int rv;
  126. /* Split the options into tokens with the "," character and
  127. process them */
  128. while (1) {
  129. o = strsep(&options, ",");
  130. if (o == NULL)
  131. break;
  132. if (*o == '\0')
  133. continue;
  134. token = match_token(o, tokens, tmp);
  135. switch (token) {
  136. case Opt_lockproto:
  137. match_strlcpy(args->ar_lockproto, &tmp[0],
  138. GFS2_LOCKNAME_LEN);
  139. break;
  140. case Opt_locktable:
  141. match_strlcpy(args->ar_locktable, &tmp[0],
  142. GFS2_LOCKNAME_LEN);
  143. break;
  144. case Opt_hostdata:
  145. match_strlcpy(args->ar_hostdata, &tmp[0],
  146. GFS2_LOCKNAME_LEN);
  147. break;
  148. case Opt_spectator:
  149. args->ar_spectator = 1;
  150. break;
  151. case Opt_ignore_local_fs:
  152. args->ar_ignore_local_fs = 1;
  153. break;
  154. case Opt_localflocks:
  155. args->ar_localflocks = 1;
  156. break;
  157. case Opt_localcaching:
  158. args->ar_localcaching = 1;
  159. break;
  160. case Opt_debug:
  161. if (args->ar_errors == GFS2_ERRORS_PANIC) {
  162. printk(KERN_WARNING "GFS2: -o debug and -o errors=panic "
  163. "are mutually exclusive.\n");
  164. return -EINVAL;
  165. }
  166. args->ar_debug = 1;
  167. break;
  168. case Opt_nodebug:
  169. args->ar_debug = 0;
  170. break;
  171. case Opt_upgrade:
  172. args->ar_upgrade = 1;
  173. break;
  174. case Opt_acl:
  175. args->ar_posix_acl = 1;
  176. break;
  177. case Opt_noacl:
  178. args->ar_posix_acl = 0;
  179. break;
  180. case Opt_quota_off:
  181. case Opt_noquota:
  182. args->ar_quota = GFS2_QUOTA_OFF;
  183. break;
  184. case Opt_quota_account:
  185. args->ar_quota = GFS2_QUOTA_ACCOUNT;
  186. break;
  187. case Opt_quota_on:
  188. case Opt_quota:
  189. args->ar_quota = GFS2_QUOTA_ON;
  190. break;
  191. case Opt_suiddir:
  192. args->ar_suiddir = 1;
  193. break;
  194. case Opt_nosuiddir:
  195. args->ar_suiddir = 0;
  196. break;
  197. case Opt_data_writeback:
  198. args->ar_data = GFS2_DATA_WRITEBACK;
  199. break;
  200. case Opt_data_ordered:
  201. args->ar_data = GFS2_DATA_ORDERED;
  202. break;
  203. case Opt_meta:
  204. args->ar_meta = 1;
  205. break;
  206. case Opt_discard:
  207. args->ar_discard = 1;
  208. break;
  209. case Opt_nodiscard:
  210. args->ar_discard = 0;
  211. break;
  212. case Opt_commit:
  213. rv = match_int(&tmp[0], &args->ar_commit);
  214. if (rv || args->ar_commit <= 0) {
  215. printk(KERN_WARNING "GFS2: commit mount option requires a positive numeric argument\n");
  216. return rv ? rv : -EINVAL;
  217. }
  218. break;
  219. case Opt_statfs_quantum:
  220. rv = match_int(&tmp[0], &args->ar_statfs_quantum);
  221. if (rv || args->ar_statfs_quantum < 0) {
  222. printk(KERN_WARNING "GFS2: statfs_quantum mount option requires a non-negative numeric argument\n");
  223. return rv ? rv : -EINVAL;
  224. }
  225. break;
  226. case Opt_quota_quantum:
  227. rv = match_int(&tmp[0], &args->ar_quota_quantum);
  228. if (rv || args->ar_quota_quantum <= 0) {
  229. printk(KERN_WARNING "GFS2: quota_quantum mount option requires a positive numeric argument\n");
  230. return rv ? rv : -EINVAL;
  231. }
  232. break;
  233. case Opt_statfs_percent:
  234. rv = match_int(&tmp[0], &args->ar_statfs_percent);
  235. if (rv || args->ar_statfs_percent < 0 ||
  236. args->ar_statfs_percent > 100) {
  237. printk(KERN_WARNING "statfs_percent mount option requires a numeric argument between 0 and 100\n");
  238. return rv ? rv : -EINVAL;
  239. }
  240. break;
  241. case Opt_err_withdraw:
  242. args->ar_errors = GFS2_ERRORS_WITHDRAW;
  243. break;
  244. case Opt_err_panic:
  245. if (args->ar_debug) {
  246. printk(KERN_WARNING "GFS2: -o debug and -o errors=panic "
  247. "are mutually exclusive.\n");
  248. return -EINVAL;
  249. }
  250. args->ar_errors = GFS2_ERRORS_PANIC;
  251. break;
  252. case Opt_barrier:
  253. args->ar_nobarrier = 0;
  254. break;
  255. case Opt_nobarrier:
  256. args->ar_nobarrier = 1;
  257. break;
  258. case Opt_error:
  259. default:
  260. printk(KERN_WARNING "GFS2: invalid mount option: %s\n", o);
  261. return -EINVAL;
  262. }
  263. }
  264. return 0;
  265. }
  266. /**
  267. * gfs2_jindex_free - Clear all the journal index information
  268. * @sdp: The GFS2 superblock
  269. *
  270. */
  271. void gfs2_jindex_free(struct gfs2_sbd *sdp)
  272. {
  273. struct list_head list, *head;
  274. struct gfs2_jdesc *jd;
  275. struct gfs2_journal_extent *jext;
  276. spin_lock(&sdp->sd_jindex_spin);
  277. list_add(&list, &sdp->sd_jindex_list);
  278. list_del_init(&sdp->sd_jindex_list);
  279. sdp->sd_journals = 0;
  280. spin_unlock(&sdp->sd_jindex_spin);
  281. while (!list_empty(&list)) {
  282. jd = list_entry(list.next, struct gfs2_jdesc, jd_list);
  283. head = &jd->extent_list;
  284. while (!list_empty(head)) {
  285. jext = list_entry(head->next,
  286. struct gfs2_journal_extent,
  287. extent_list);
  288. list_del(&jext->extent_list);
  289. kfree(jext);
  290. }
  291. list_del(&jd->jd_list);
  292. iput(jd->jd_inode);
  293. kfree(jd);
  294. }
  295. }
  296. static struct gfs2_jdesc *jdesc_find_i(struct list_head *head, unsigned int jid)
  297. {
  298. struct gfs2_jdesc *jd;
  299. int found = 0;
  300. list_for_each_entry(jd, head, jd_list) {
  301. if (jd->jd_jid == jid) {
  302. found = 1;
  303. break;
  304. }
  305. }
  306. if (!found)
  307. jd = NULL;
  308. return jd;
  309. }
  310. struct gfs2_jdesc *gfs2_jdesc_find(struct gfs2_sbd *sdp, unsigned int jid)
  311. {
  312. struct gfs2_jdesc *jd;
  313. spin_lock(&sdp->sd_jindex_spin);
  314. jd = jdesc_find_i(&sdp->sd_jindex_list, jid);
  315. spin_unlock(&sdp->sd_jindex_spin);
  316. return jd;
  317. }
  318. int gfs2_jdesc_check(struct gfs2_jdesc *jd)
  319. {
  320. struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
  321. struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
  322. if (ip->i_disksize < (8 << 20) || ip->i_disksize > (1 << 30) ||
  323. (ip->i_disksize & (sdp->sd_sb.sb_bsize - 1))) {
  324. gfs2_consist_inode(ip);
  325. return -EIO;
  326. }
  327. jd->jd_blocks = ip->i_disksize >> sdp->sd_sb.sb_bsize_shift;
  328. if (gfs2_write_alloc_required(ip, 0, ip->i_disksize)) {
  329. gfs2_consist_inode(ip);
  330. return -EIO;
  331. }
  332. return 0;
  333. }
  334. /**
  335. * gfs2_make_fs_rw - Turn a Read-Only FS into a Read-Write one
  336. * @sdp: the filesystem
  337. *
  338. * Returns: errno
  339. */
  340. int gfs2_make_fs_rw(struct gfs2_sbd *sdp)
  341. {
  342. struct gfs2_inode *ip = GFS2_I(sdp->sd_jdesc->jd_inode);
  343. struct gfs2_glock *j_gl = ip->i_gl;
  344. struct gfs2_holder t_gh;
  345. struct gfs2_log_header_host head;
  346. int error;
  347. error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, 0, &t_gh);
  348. if (error)
  349. return error;
  350. j_gl->gl_ops->go_inval(j_gl, DIO_METADATA);
  351. error = gfs2_find_jhead(sdp->sd_jdesc, &head);
  352. if (error)
  353. goto fail;
  354. if (!(head.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
  355. gfs2_consist(sdp);
  356. error = -EIO;
  357. goto fail;
  358. }
  359. /* Initialize some head of the log stuff */
  360. sdp->sd_log_sequence = head.lh_sequence + 1;
  361. gfs2_log_pointers_init(sdp, head.lh_blkno);
  362. error = gfs2_quota_init(sdp);
  363. if (error)
  364. goto fail;
  365. set_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
  366. gfs2_glock_dq_uninit(&t_gh);
  367. return 0;
  368. fail:
  369. t_gh.gh_flags |= GL_NOCACHE;
  370. gfs2_glock_dq_uninit(&t_gh);
  371. return error;
  372. }
  373. void gfs2_statfs_change_in(struct gfs2_statfs_change_host *sc, const void *buf)
  374. {
  375. const struct gfs2_statfs_change *str = buf;
  376. sc->sc_total = be64_to_cpu(str->sc_total);
  377. sc->sc_free = be64_to_cpu(str->sc_free);
  378. sc->sc_dinodes = be64_to_cpu(str->sc_dinodes);
  379. }
  380. static void gfs2_statfs_change_out(const struct gfs2_statfs_change_host *sc, void *buf)
  381. {
  382. struct gfs2_statfs_change *str = buf;
  383. str->sc_total = cpu_to_be64(sc->sc_total);
  384. str->sc_free = cpu_to_be64(sc->sc_free);
  385. str->sc_dinodes = cpu_to_be64(sc->sc_dinodes);
  386. }
  387. int gfs2_statfs_init(struct gfs2_sbd *sdp)
  388. {
  389. struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
  390. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  391. struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
  392. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  393. struct buffer_head *m_bh, *l_bh;
  394. struct gfs2_holder gh;
  395. int error;
  396. error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
  397. &gh);
  398. if (error)
  399. return error;
  400. error = gfs2_meta_inode_buffer(m_ip, &m_bh);
  401. if (error)
  402. goto out;
  403. if (sdp->sd_args.ar_spectator) {
  404. spin_lock(&sdp->sd_statfs_spin);
  405. gfs2_statfs_change_in(m_sc, m_bh->b_data +
  406. sizeof(struct gfs2_dinode));
  407. spin_unlock(&sdp->sd_statfs_spin);
  408. } else {
  409. error = gfs2_meta_inode_buffer(l_ip, &l_bh);
  410. if (error)
  411. goto out_m_bh;
  412. spin_lock(&sdp->sd_statfs_spin);
  413. gfs2_statfs_change_in(m_sc, m_bh->b_data +
  414. sizeof(struct gfs2_dinode));
  415. gfs2_statfs_change_in(l_sc, l_bh->b_data +
  416. sizeof(struct gfs2_dinode));
  417. spin_unlock(&sdp->sd_statfs_spin);
  418. brelse(l_bh);
  419. }
  420. out_m_bh:
  421. brelse(m_bh);
  422. out:
  423. gfs2_glock_dq_uninit(&gh);
  424. return 0;
  425. }
  426. void gfs2_statfs_change(struct gfs2_sbd *sdp, s64 total, s64 free,
  427. s64 dinodes)
  428. {
  429. struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
  430. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  431. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  432. struct buffer_head *l_bh;
  433. s64 x, y;
  434. int need_sync = 0;
  435. int error;
  436. error = gfs2_meta_inode_buffer(l_ip, &l_bh);
  437. if (error)
  438. return;
  439. gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
  440. spin_lock(&sdp->sd_statfs_spin);
  441. l_sc->sc_total += total;
  442. l_sc->sc_free += free;
  443. l_sc->sc_dinodes += dinodes;
  444. gfs2_statfs_change_out(l_sc, l_bh->b_data + sizeof(struct gfs2_dinode));
  445. if (sdp->sd_args.ar_statfs_percent) {
  446. x = 100 * l_sc->sc_free;
  447. y = m_sc->sc_free * sdp->sd_args.ar_statfs_percent;
  448. if (x >= y || x <= -y)
  449. need_sync = 1;
  450. }
  451. spin_unlock(&sdp->sd_statfs_spin);
  452. brelse(l_bh);
  453. if (need_sync)
  454. gfs2_wake_up_statfs(sdp);
  455. }
  456. void update_statfs(struct gfs2_sbd *sdp, struct buffer_head *m_bh,
  457. struct buffer_head *l_bh)
  458. {
  459. struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
  460. struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
  461. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  462. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  463. gfs2_trans_add_bh(l_ip->i_gl, l_bh, 1);
  464. spin_lock(&sdp->sd_statfs_spin);
  465. m_sc->sc_total += l_sc->sc_total;
  466. m_sc->sc_free += l_sc->sc_free;
  467. m_sc->sc_dinodes += l_sc->sc_dinodes;
  468. memset(l_sc, 0, sizeof(struct gfs2_statfs_change));
  469. memset(l_bh->b_data + sizeof(struct gfs2_dinode),
  470. 0, sizeof(struct gfs2_statfs_change));
  471. spin_unlock(&sdp->sd_statfs_spin);
  472. gfs2_trans_add_bh(m_ip->i_gl, m_bh, 1);
  473. gfs2_statfs_change_out(m_sc, m_bh->b_data + sizeof(struct gfs2_dinode));
  474. }
  475. int gfs2_statfs_sync(struct super_block *sb, int type)
  476. {
  477. struct gfs2_sbd *sdp = sb->s_fs_info;
  478. struct gfs2_inode *m_ip = GFS2_I(sdp->sd_statfs_inode);
  479. struct gfs2_inode *l_ip = GFS2_I(sdp->sd_sc_inode);
  480. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  481. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  482. struct gfs2_holder gh;
  483. struct buffer_head *m_bh, *l_bh;
  484. int error;
  485. error = gfs2_glock_nq_init(m_ip->i_gl, LM_ST_EXCLUSIVE, GL_NOCACHE,
  486. &gh);
  487. if (error)
  488. return error;
  489. error = gfs2_meta_inode_buffer(m_ip, &m_bh);
  490. if (error)
  491. goto out;
  492. spin_lock(&sdp->sd_statfs_spin);
  493. gfs2_statfs_change_in(m_sc, m_bh->b_data +
  494. sizeof(struct gfs2_dinode));
  495. if (!l_sc->sc_total && !l_sc->sc_free && !l_sc->sc_dinodes) {
  496. spin_unlock(&sdp->sd_statfs_spin);
  497. goto out_bh;
  498. }
  499. spin_unlock(&sdp->sd_statfs_spin);
  500. error = gfs2_meta_inode_buffer(l_ip, &l_bh);
  501. if (error)
  502. goto out_bh;
  503. error = gfs2_trans_begin(sdp, 2 * RES_DINODE, 0);
  504. if (error)
  505. goto out_bh2;
  506. update_statfs(sdp, m_bh, l_bh);
  507. sdp->sd_statfs_force_sync = 0;
  508. gfs2_trans_end(sdp);
  509. out_bh2:
  510. brelse(l_bh);
  511. out_bh:
  512. brelse(m_bh);
  513. out:
  514. gfs2_glock_dq_uninit(&gh);
  515. return error;
  516. }
  517. struct lfcc {
  518. struct list_head list;
  519. struct gfs2_holder gh;
  520. };
  521. /**
  522. * gfs2_lock_fs_check_clean - Stop all writes to the FS and check that all
  523. * journals are clean
  524. * @sdp: the file system
  525. * @state: the state to put the transaction lock into
  526. * @t_gh: the hold on the transaction lock
  527. *
  528. * Returns: errno
  529. */
  530. static int gfs2_lock_fs_check_clean(struct gfs2_sbd *sdp,
  531. struct gfs2_holder *t_gh)
  532. {
  533. struct gfs2_inode *ip;
  534. struct gfs2_jdesc *jd;
  535. struct lfcc *lfcc;
  536. LIST_HEAD(list);
  537. struct gfs2_log_header_host lh;
  538. int error;
  539. list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
  540. lfcc = kmalloc(sizeof(struct lfcc), GFP_KERNEL);
  541. if (!lfcc) {
  542. error = -ENOMEM;
  543. goto out;
  544. }
  545. ip = GFS2_I(jd->jd_inode);
  546. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_SHARED, 0, &lfcc->gh);
  547. if (error) {
  548. kfree(lfcc);
  549. goto out;
  550. }
  551. list_add(&lfcc->list, &list);
  552. }
  553. error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_DEFERRED,
  554. GL_NOCACHE, t_gh);
  555. list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
  556. error = gfs2_jdesc_check(jd);
  557. if (error)
  558. break;
  559. error = gfs2_find_jhead(jd, &lh);
  560. if (error)
  561. break;
  562. if (!(lh.lh_flags & GFS2_LOG_HEAD_UNMOUNT)) {
  563. error = -EBUSY;
  564. break;
  565. }
  566. }
  567. if (error)
  568. gfs2_glock_dq_uninit(t_gh);
  569. out:
  570. while (!list_empty(&list)) {
  571. lfcc = list_entry(list.next, struct lfcc, list);
  572. list_del(&lfcc->list);
  573. gfs2_glock_dq_uninit(&lfcc->gh);
  574. kfree(lfcc);
  575. }
  576. return error;
  577. }
  578. /**
  579. * gfs2_freeze_fs - freezes the file system
  580. * @sdp: the file system
  581. *
  582. * This function flushes data and meta data for all machines by
  583. * aquiring the transaction log exclusively. All journals are
  584. * ensured to be in a clean state as well.
  585. *
  586. * Returns: errno
  587. */
  588. int gfs2_freeze_fs(struct gfs2_sbd *sdp)
  589. {
  590. int error = 0;
  591. mutex_lock(&sdp->sd_freeze_lock);
  592. if (!sdp->sd_freeze_count++) {
  593. error = gfs2_lock_fs_check_clean(sdp, &sdp->sd_freeze_gh);
  594. if (error)
  595. sdp->sd_freeze_count--;
  596. }
  597. mutex_unlock(&sdp->sd_freeze_lock);
  598. return error;
  599. }
  600. /**
  601. * gfs2_unfreeze_fs - unfreezes the file system
  602. * @sdp: the file system
  603. *
  604. * This function allows the file system to proceed by unlocking
  605. * the exclusively held transaction lock. Other GFS2 nodes are
  606. * now free to acquire the lock shared and go on with their lives.
  607. *
  608. */
  609. void gfs2_unfreeze_fs(struct gfs2_sbd *sdp)
  610. {
  611. mutex_lock(&sdp->sd_freeze_lock);
  612. if (sdp->sd_freeze_count && !--sdp->sd_freeze_count)
  613. gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
  614. mutex_unlock(&sdp->sd_freeze_lock);
  615. }
  616. /**
  617. * gfs2_write_inode - Make sure the inode is stable on the disk
  618. * @inode: The inode
  619. * @sync: synchronous write flag
  620. *
  621. * Returns: errno
  622. */
  623. static int gfs2_write_inode(struct inode *inode, struct writeback_control *wbc)
  624. {
  625. struct gfs2_inode *ip = GFS2_I(inode);
  626. struct gfs2_sbd *sdp = GFS2_SB(inode);
  627. struct gfs2_holder gh;
  628. struct buffer_head *bh;
  629. struct timespec atime;
  630. struct gfs2_dinode *di;
  631. int ret = 0;
  632. /* Check this is a "normal" inode, etc */
  633. if (current->flags & PF_MEMALLOC)
  634. return 0;
  635. ret = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  636. if (ret)
  637. goto do_flush;
  638. ret = gfs2_trans_begin(sdp, RES_DINODE, 0);
  639. if (ret)
  640. goto do_unlock;
  641. ret = gfs2_meta_inode_buffer(ip, &bh);
  642. if (ret == 0) {
  643. di = (struct gfs2_dinode *)bh->b_data;
  644. atime.tv_sec = be64_to_cpu(di->di_atime);
  645. atime.tv_nsec = be32_to_cpu(di->di_atime_nsec);
  646. if (timespec_compare(&inode->i_atime, &atime) > 0) {
  647. gfs2_trans_add_bh(ip->i_gl, bh, 1);
  648. gfs2_dinode_out(ip, bh->b_data);
  649. }
  650. brelse(bh);
  651. }
  652. gfs2_trans_end(sdp);
  653. do_unlock:
  654. gfs2_glock_dq_uninit(&gh);
  655. do_flush:
  656. if (wbc->sync_mode == WB_SYNC_ALL)
  657. gfs2_log_flush(GFS2_SB(inode), ip->i_gl);
  658. return ret;
  659. }
  660. /**
  661. * gfs2_make_fs_ro - Turn a Read-Write FS into a Read-Only one
  662. * @sdp: the filesystem
  663. *
  664. * Returns: errno
  665. */
  666. static int gfs2_make_fs_ro(struct gfs2_sbd *sdp)
  667. {
  668. struct gfs2_holder t_gh;
  669. int error;
  670. flush_workqueue(gfs2_delete_workqueue);
  671. gfs2_quota_sync(sdp->sd_vfs, 0, 1);
  672. gfs2_statfs_sync(sdp->sd_vfs, 0);
  673. error = gfs2_glock_nq_init(sdp->sd_trans_gl, LM_ST_SHARED, GL_NOCACHE,
  674. &t_gh);
  675. if (error && !test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  676. return error;
  677. gfs2_meta_syncfs(sdp);
  678. gfs2_log_shutdown(sdp);
  679. clear_bit(SDF_JOURNAL_LIVE, &sdp->sd_flags);
  680. if (t_gh.gh_gl)
  681. gfs2_glock_dq_uninit(&t_gh);
  682. gfs2_quota_cleanup(sdp);
  683. return error;
  684. }
  685. static int gfs2_umount_recovery_wait(void *word)
  686. {
  687. schedule();
  688. return 0;
  689. }
  690. /**
  691. * gfs2_put_super - Unmount the filesystem
  692. * @sb: The VFS superblock
  693. *
  694. */
  695. static void gfs2_put_super(struct super_block *sb)
  696. {
  697. struct gfs2_sbd *sdp = sb->s_fs_info;
  698. int error;
  699. struct gfs2_jdesc *jd;
  700. /* Unfreeze the filesystem, if we need to */
  701. mutex_lock(&sdp->sd_freeze_lock);
  702. if (sdp->sd_freeze_count)
  703. gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
  704. mutex_unlock(&sdp->sd_freeze_lock);
  705. /* No more recovery requests */
  706. set_bit(SDF_NORECOVERY, &sdp->sd_flags);
  707. smp_mb();
  708. /* Wait on outstanding recovery */
  709. restart:
  710. spin_lock(&sdp->sd_jindex_spin);
  711. list_for_each_entry(jd, &sdp->sd_jindex_list, jd_list) {
  712. if (!test_bit(JDF_RECOVERY, &jd->jd_flags))
  713. continue;
  714. spin_unlock(&sdp->sd_jindex_spin);
  715. wait_on_bit(&jd->jd_flags, JDF_RECOVERY,
  716. gfs2_umount_recovery_wait, TASK_UNINTERRUPTIBLE);
  717. goto restart;
  718. }
  719. spin_unlock(&sdp->sd_jindex_spin);
  720. kthread_stop(sdp->sd_quotad_process);
  721. kthread_stop(sdp->sd_logd_process);
  722. if (!(sb->s_flags & MS_RDONLY)) {
  723. error = gfs2_make_fs_ro(sdp);
  724. if (error)
  725. gfs2_io_error(sdp);
  726. }
  727. /* At this point, we're through modifying the disk */
  728. /* Release stuff */
  729. iput(sdp->sd_jindex);
  730. iput(sdp->sd_statfs_inode);
  731. iput(sdp->sd_rindex);
  732. iput(sdp->sd_quota_inode);
  733. gfs2_glock_put(sdp->sd_rename_gl);
  734. gfs2_glock_put(sdp->sd_trans_gl);
  735. if (!sdp->sd_args.ar_spectator) {
  736. gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
  737. gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
  738. gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
  739. gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
  740. iput(sdp->sd_sc_inode);
  741. iput(sdp->sd_qc_inode);
  742. }
  743. gfs2_glock_dq_uninit(&sdp->sd_live_gh);
  744. gfs2_clear_rgrpd(sdp);
  745. gfs2_jindex_free(sdp);
  746. /* Take apart glock structures and buffer lists */
  747. invalidate_inodes(sdp->sd_vfs);
  748. gfs2_gl_hash_clear(sdp);
  749. /* Unmount the locking protocol */
  750. gfs2_lm_unmount(sdp);
  751. /* At this point, we're through participating in the lockspace */
  752. gfs2_sys_fs_del(sdp);
  753. }
  754. /**
  755. * gfs2_sync_fs - sync the filesystem
  756. * @sb: the superblock
  757. *
  758. * Flushes the log to disk.
  759. */
  760. static int gfs2_sync_fs(struct super_block *sb, int wait)
  761. {
  762. if (wait && sb->s_fs_info)
  763. gfs2_log_flush(sb->s_fs_info, NULL);
  764. return 0;
  765. }
  766. /**
  767. * gfs2_freeze - prevent further writes to the filesystem
  768. * @sb: the VFS structure for the filesystem
  769. *
  770. */
  771. static int gfs2_freeze(struct super_block *sb)
  772. {
  773. struct gfs2_sbd *sdp = sb->s_fs_info;
  774. int error;
  775. if (test_bit(SDF_SHUTDOWN, &sdp->sd_flags))
  776. return -EINVAL;
  777. for (;;) {
  778. error = gfs2_freeze_fs(sdp);
  779. if (!error)
  780. break;
  781. switch (error) {
  782. case -EBUSY:
  783. fs_err(sdp, "waiting for recovery before freeze\n");
  784. break;
  785. default:
  786. fs_err(sdp, "error freezing FS: %d\n", error);
  787. break;
  788. }
  789. fs_err(sdp, "retrying...\n");
  790. msleep(1000);
  791. }
  792. return 0;
  793. }
  794. /**
  795. * gfs2_unfreeze - reallow writes to the filesystem
  796. * @sb: the VFS structure for the filesystem
  797. *
  798. */
  799. static int gfs2_unfreeze(struct super_block *sb)
  800. {
  801. gfs2_unfreeze_fs(sb->s_fs_info);
  802. return 0;
  803. }
  804. /**
  805. * statfs_fill - fill in the sg for a given RG
  806. * @rgd: the RG
  807. * @sc: the sc structure
  808. *
  809. * Returns: 0 on success, -ESTALE if the LVB is invalid
  810. */
  811. static int statfs_slow_fill(struct gfs2_rgrpd *rgd,
  812. struct gfs2_statfs_change_host *sc)
  813. {
  814. gfs2_rgrp_verify(rgd);
  815. sc->sc_total += rgd->rd_data;
  816. sc->sc_free += rgd->rd_free;
  817. sc->sc_dinodes += rgd->rd_dinodes;
  818. return 0;
  819. }
  820. /**
  821. * gfs2_statfs_slow - Stat a filesystem using asynchronous locking
  822. * @sdp: the filesystem
  823. * @sc: the sc info that will be returned
  824. *
  825. * Any error (other than a signal) will cause this routine to fall back
  826. * to the synchronous version.
  827. *
  828. * FIXME: This really shouldn't busy wait like this.
  829. *
  830. * Returns: errno
  831. */
  832. static int gfs2_statfs_slow(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
  833. {
  834. struct gfs2_holder ri_gh;
  835. struct gfs2_rgrpd *rgd_next;
  836. struct gfs2_holder *gha, *gh;
  837. unsigned int slots = 64;
  838. unsigned int x;
  839. int done;
  840. int error = 0, err;
  841. memset(sc, 0, sizeof(struct gfs2_statfs_change_host));
  842. gha = kcalloc(slots, sizeof(struct gfs2_holder), GFP_KERNEL);
  843. if (!gha)
  844. return -ENOMEM;
  845. error = gfs2_rindex_hold(sdp, &ri_gh);
  846. if (error)
  847. goto out;
  848. rgd_next = gfs2_rgrpd_get_first(sdp);
  849. for (;;) {
  850. done = 1;
  851. for (x = 0; x < slots; x++) {
  852. gh = gha + x;
  853. if (gh->gh_gl && gfs2_glock_poll(gh)) {
  854. err = gfs2_glock_wait(gh);
  855. if (err) {
  856. gfs2_holder_uninit(gh);
  857. error = err;
  858. } else {
  859. if (!error)
  860. error = statfs_slow_fill(
  861. gh->gh_gl->gl_object, sc);
  862. gfs2_glock_dq_uninit(gh);
  863. }
  864. }
  865. if (gh->gh_gl)
  866. done = 0;
  867. else if (rgd_next && !error) {
  868. error = gfs2_glock_nq_init(rgd_next->rd_gl,
  869. LM_ST_SHARED,
  870. GL_ASYNC,
  871. gh);
  872. rgd_next = gfs2_rgrpd_get_next(rgd_next);
  873. done = 0;
  874. }
  875. if (signal_pending(current))
  876. error = -ERESTARTSYS;
  877. }
  878. if (done)
  879. break;
  880. yield();
  881. }
  882. gfs2_glock_dq_uninit(&ri_gh);
  883. out:
  884. kfree(gha);
  885. return error;
  886. }
  887. /**
  888. * gfs2_statfs_i - Do a statfs
  889. * @sdp: the filesystem
  890. * @sg: the sg structure
  891. *
  892. * Returns: errno
  893. */
  894. static int gfs2_statfs_i(struct gfs2_sbd *sdp, struct gfs2_statfs_change_host *sc)
  895. {
  896. struct gfs2_statfs_change_host *m_sc = &sdp->sd_statfs_master;
  897. struct gfs2_statfs_change_host *l_sc = &sdp->sd_statfs_local;
  898. spin_lock(&sdp->sd_statfs_spin);
  899. *sc = *m_sc;
  900. sc->sc_total += l_sc->sc_total;
  901. sc->sc_free += l_sc->sc_free;
  902. sc->sc_dinodes += l_sc->sc_dinodes;
  903. spin_unlock(&sdp->sd_statfs_spin);
  904. if (sc->sc_free < 0)
  905. sc->sc_free = 0;
  906. if (sc->sc_free > sc->sc_total)
  907. sc->sc_free = sc->sc_total;
  908. if (sc->sc_dinodes < 0)
  909. sc->sc_dinodes = 0;
  910. return 0;
  911. }
  912. /**
  913. * gfs2_statfs - Gather and return stats about the filesystem
  914. * @sb: The superblock
  915. * @statfsbuf: The buffer
  916. *
  917. * Returns: 0 on success or error code
  918. */
  919. static int gfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  920. {
  921. struct super_block *sb = dentry->d_inode->i_sb;
  922. struct gfs2_sbd *sdp = sb->s_fs_info;
  923. struct gfs2_statfs_change_host sc;
  924. int error;
  925. if (gfs2_tune_get(sdp, gt_statfs_slow))
  926. error = gfs2_statfs_slow(sdp, &sc);
  927. else
  928. error = gfs2_statfs_i(sdp, &sc);
  929. if (error)
  930. return error;
  931. buf->f_type = GFS2_MAGIC;
  932. buf->f_bsize = sdp->sd_sb.sb_bsize;
  933. buf->f_blocks = sc.sc_total;
  934. buf->f_bfree = sc.sc_free;
  935. buf->f_bavail = sc.sc_free;
  936. buf->f_files = sc.sc_dinodes + sc.sc_free;
  937. buf->f_ffree = sc.sc_free;
  938. buf->f_namelen = GFS2_FNAMESIZE;
  939. return 0;
  940. }
  941. /**
  942. * gfs2_remount_fs - called when the FS is remounted
  943. * @sb: the filesystem
  944. * @flags: the remount flags
  945. * @data: extra data passed in (not used right now)
  946. *
  947. * Returns: errno
  948. */
  949. static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
  950. {
  951. struct gfs2_sbd *sdp = sb->s_fs_info;
  952. struct gfs2_args args = sdp->sd_args; /* Default to current settings */
  953. struct gfs2_tune *gt = &sdp->sd_tune;
  954. int error;
  955. spin_lock(&gt->gt_spin);
  956. args.ar_commit = gt->gt_logd_secs;
  957. args.ar_quota_quantum = gt->gt_quota_quantum;
  958. if (gt->gt_statfs_slow)
  959. args.ar_statfs_quantum = 0;
  960. else
  961. args.ar_statfs_quantum = gt->gt_statfs_quantum;
  962. spin_unlock(&gt->gt_spin);
  963. error = gfs2_mount_args(&args, data);
  964. if (error)
  965. return error;
  966. /* Not allowed to change locking details */
  967. if (strcmp(args.ar_lockproto, sdp->sd_args.ar_lockproto) ||
  968. strcmp(args.ar_locktable, sdp->sd_args.ar_locktable) ||
  969. strcmp(args.ar_hostdata, sdp->sd_args.ar_hostdata))
  970. return -EINVAL;
  971. /* Some flags must not be changed */
  972. if (args_neq(&args, &sdp->sd_args, spectator) ||
  973. args_neq(&args, &sdp->sd_args, ignore_local_fs) ||
  974. args_neq(&args, &sdp->sd_args, localflocks) ||
  975. args_neq(&args, &sdp->sd_args, localcaching) ||
  976. args_neq(&args, &sdp->sd_args, meta))
  977. return -EINVAL;
  978. if (sdp->sd_args.ar_spectator)
  979. *flags |= MS_RDONLY;
  980. if ((sb->s_flags ^ *flags) & MS_RDONLY) {
  981. if (*flags & MS_RDONLY)
  982. error = gfs2_make_fs_ro(sdp);
  983. else
  984. error = gfs2_make_fs_rw(sdp);
  985. if (error)
  986. return error;
  987. }
  988. sdp->sd_args = args;
  989. if (sdp->sd_args.ar_posix_acl)
  990. sb->s_flags |= MS_POSIXACL;
  991. else
  992. sb->s_flags &= ~MS_POSIXACL;
  993. if (sdp->sd_args.ar_nobarrier)
  994. set_bit(SDF_NOBARRIERS, &sdp->sd_flags);
  995. else
  996. clear_bit(SDF_NOBARRIERS, &sdp->sd_flags);
  997. spin_lock(&gt->gt_spin);
  998. gt->gt_logd_secs = args.ar_commit;
  999. gt->gt_quota_quantum = args.ar_quota_quantum;
  1000. if (args.ar_statfs_quantum) {
  1001. gt->gt_statfs_slow = 0;
  1002. gt->gt_statfs_quantum = args.ar_statfs_quantum;
  1003. }
  1004. else {
  1005. gt->gt_statfs_slow = 1;
  1006. gt->gt_statfs_quantum = 30;
  1007. }
  1008. spin_unlock(&gt->gt_spin);
  1009. gfs2_online_uevent(sdp);
  1010. return 0;
  1011. }
  1012. /**
  1013. * gfs2_drop_inode - Drop an inode (test for remote unlink)
  1014. * @inode: The inode to drop
  1015. *
  1016. * If we've received a callback on an iopen lock then its because a
  1017. * remote node tried to deallocate the inode but failed due to this node
  1018. * still having the inode open. Here we mark the link count zero
  1019. * since we know that it must have reached zero if the GLF_DEMOTE flag
  1020. * is set on the iopen glock. If we didn't do a disk read since the
  1021. * remote node removed the final link then we might otherwise miss
  1022. * this event. This check ensures that this node will deallocate the
  1023. * inode's blocks, or alternatively pass the baton on to another
  1024. * node for later deallocation.
  1025. */
  1026. static int gfs2_drop_inode(struct inode *inode)
  1027. {
  1028. struct gfs2_inode *ip = GFS2_I(inode);
  1029. if (inode->i_nlink) {
  1030. struct gfs2_glock *gl = ip->i_iopen_gh.gh_gl;
  1031. if (gl && test_bit(GLF_DEMOTE, &gl->gl_flags))
  1032. clear_nlink(inode);
  1033. }
  1034. return generic_drop_inode(inode);
  1035. }
  1036. static int is_ancestor(const struct dentry *d1, const struct dentry *d2)
  1037. {
  1038. do {
  1039. if (d1 == d2)
  1040. return 1;
  1041. d1 = d1->d_parent;
  1042. } while (!IS_ROOT(d1));
  1043. return 0;
  1044. }
  1045. /**
  1046. * gfs2_show_options - Show mount options for /proc/mounts
  1047. * @s: seq_file structure
  1048. * @mnt: vfsmount
  1049. *
  1050. * Returns: 0 on success or error code
  1051. */
  1052. static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  1053. {
  1054. struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
  1055. struct gfs2_args *args = &sdp->sd_args;
  1056. int val;
  1057. if (is_ancestor(mnt->mnt_root, sdp->sd_master_dir))
  1058. seq_printf(s, ",meta");
  1059. if (args->ar_lockproto[0])
  1060. seq_printf(s, ",lockproto=%s", args->ar_lockproto);
  1061. if (args->ar_locktable[0])
  1062. seq_printf(s, ",locktable=%s", args->ar_locktable);
  1063. if (args->ar_hostdata[0])
  1064. seq_printf(s, ",hostdata=%s", args->ar_hostdata);
  1065. if (args->ar_spectator)
  1066. seq_printf(s, ",spectator");
  1067. if (args->ar_ignore_local_fs)
  1068. seq_printf(s, ",ignore_local_fs");
  1069. if (args->ar_localflocks)
  1070. seq_printf(s, ",localflocks");
  1071. if (args->ar_localcaching)
  1072. seq_printf(s, ",localcaching");
  1073. if (args->ar_debug)
  1074. seq_printf(s, ",debug");
  1075. if (args->ar_upgrade)
  1076. seq_printf(s, ",upgrade");
  1077. if (args->ar_posix_acl)
  1078. seq_printf(s, ",acl");
  1079. if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
  1080. char *state;
  1081. switch (args->ar_quota) {
  1082. case GFS2_QUOTA_OFF:
  1083. state = "off";
  1084. break;
  1085. case GFS2_QUOTA_ACCOUNT:
  1086. state = "account";
  1087. break;
  1088. case GFS2_QUOTA_ON:
  1089. state = "on";
  1090. break;
  1091. default:
  1092. state = "unknown";
  1093. break;
  1094. }
  1095. seq_printf(s, ",quota=%s", state);
  1096. }
  1097. if (args->ar_suiddir)
  1098. seq_printf(s, ",suiddir");
  1099. if (args->ar_data != GFS2_DATA_DEFAULT) {
  1100. char *state;
  1101. switch (args->ar_data) {
  1102. case GFS2_DATA_WRITEBACK:
  1103. state = "writeback";
  1104. break;
  1105. case GFS2_DATA_ORDERED:
  1106. state = "ordered";
  1107. break;
  1108. default:
  1109. state = "unknown";
  1110. break;
  1111. }
  1112. seq_printf(s, ",data=%s", state);
  1113. }
  1114. if (args->ar_discard)
  1115. seq_printf(s, ",discard");
  1116. val = sdp->sd_tune.gt_logd_secs;
  1117. if (val != 30)
  1118. seq_printf(s, ",commit=%d", val);
  1119. val = sdp->sd_tune.gt_statfs_quantum;
  1120. if (val != 30)
  1121. seq_printf(s, ",statfs_quantum=%d", val);
  1122. val = sdp->sd_tune.gt_quota_quantum;
  1123. if (val != 60)
  1124. seq_printf(s, ",quota_quantum=%d", val);
  1125. if (args->ar_statfs_percent)
  1126. seq_printf(s, ",statfs_percent=%d", args->ar_statfs_percent);
  1127. if (args->ar_errors != GFS2_ERRORS_DEFAULT) {
  1128. const char *state;
  1129. switch (args->ar_errors) {
  1130. case GFS2_ERRORS_WITHDRAW:
  1131. state = "withdraw";
  1132. break;
  1133. case GFS2_ERRORS_PANIC:
  1134. state = "panic";
  1135. break;
  1136. default:
  1137. state = "unknown";
  1138. break;
  1139. }
  1140. seq_printf(s, ",errors=%s", state);
  1141. }
  1142. if (test_bit(SDF_NOBARRIERS, &sdp->sd_flags))
  1143. seq_printf(s, ",nobarrier");
  1144. if (test_bit(SDF_DEMOTE, &sdp->sd_flags))
  1145. seq_printf(s, ",demote_interface_used");
  1146. return 0;
  1147. }
  1148. /*
  1149. * We have to (at the moment) hold the inodes main lock to cover
  1150. * the gap between unlocking the shared lock on the iopen lock and
  1151. * taking the exclusive lock. I'd rather do a shared -> exclusive
  1152. * conversion on the iopen lock, but we can change that later. This
  1153. * is safe, just less efficient.
  1154. */
  1155. static void gfs2_evict_inode(struct inode *inode)
  1156. {
  1157. struct gfs2_sbd *sdp = inode->i_sb->s_fs_info;
  1158. struct gfs2_inode *ip = GFS2_I(inode);
  1159. struct gfs2_holder gh;
  1160. int error;
  1161. if (inode->i_nlink)
  1162. goto out;
  1163. error = gfs2_glock_nq_init(ip->i_gl, LM_ST_EXCLUSIVE, 0, &gh);
  1164. if (unlikely(error)) {
  1165. gfs2_glock_dq_uninit(&ip->i_iopen_gh);
  1166. goto out;
  1167. }
  1168. error = gfs2_check_blk_type(sdp, ip->i_no_addr, GFS2_BLKST_UNLINKED);
  1169. if (error)
  1170. goto out_truncate;
  1171. gfs2_glock_dq_wait(&ip->i_iopen_gh);
  1172. gfs2_holder_reinit(LM_ST_EXCLUSIVE, LM_FLAG_TRY_1CB | GL_NOCACHE, &ip->i_iopen_gh);
  1173. error = gfs2_glock_nq(&ip->i_iopen_gh);
  1174. if (error)
  1175. goto out_truncate;
  1176. if (S_ISDIR(inode->i_mode) &&
  1177. (ip->i_diskflags & GFS2_DIF_EXHASH)) {
  1178. error = gfs2_dir_exhash_dealloc(ip);
  1179. if (error)
  1180. goto out_unlock;
  1181. }
  1182. if (ip->i_eattr) {
  1183. error = gfs2_ea_dealloc(ip);
  1184. if (error)
  1185. goto out_unlock;
  1186. }
  1187. if (!gfs2_is_stuffed(ip)) {
  1188. error = gfs2_file_dealloc(ip);
  1189. if (error)
  1190. goto out_unlock;
  1191. }
  1192. error = gfs2_dinode_dealloc(ip);
  1193. if (error)
  1194. goto out_unlock;
  1195. out_truncate:
  1196. error = gfs2_trans_begin(sdp, 0, sdp->sd_jdesc->jd_blocks);
  1197. if (error)
  1198. goto out_unlock;
  1199. /* Needs to be done before glock release & also in a transaction */
  1200. truncate_inode_pages(&inode->i_data, 0);
  1201. gfs2_trans_end(sdp);
  1202. out_unlock:
  1203. if (test_bit(HIF_HOLDER, &ip->i_iopen_gh.gh_iflags))
  1204. gfs2_glock_dq(&ip->i_iopen_gh);
  1205. gfs2_holder_uninit(&ip->i_iopen_gh);
  1206. gfs2_glock_dq_uninit(&gh);
  1207. if (error && error != GLR_TRYFAILED && error != -EROFS)
  1208. fs_warn(sdp, "gfs2_evict_inode: %d\n", error);
  1209. out:
  1210. truncate_inode_pages(&inode->i_data, 0);
  1211. end_writeback(inode);
  1212. ip->i_gl->gl_object = NULL;
  1213. gfs2_glock_put(ip->i_gl);
  1214. ip->i_gl = NULL;
  1215. if (ip->i_iopen_gh.gh_gl) {
  1216. ip->i_iopen_gh.gh_gl->gl_object = NULL;
  1217. gfs2_glock_dq_uninit(&ip->i_iopen_gh);
  1218. }
  1219. }
  1220. static struct inode *gfs2_alloc_inode(struct super_block *sb)
  1221. {
  1222. struct gfs2_inode *ip;
  1223. ip = kmem_cache_alloc(gfs2_inode_cachep, GFP_KERNEL);
  1224. if (ip) {
  1225. ip->i_flags = 0;
  1226. ip->i_gl = NULL;
  1227. }
  1228. return &ip->i_inode;
  1229. }
  1230. static void gfs2_destroy_inode(struct inode *inode)
  1231. {
  1232. kmem_cache_free(gfs2_inode_cachep, inode);
  1233. }
  1234. const struct super_operations gfs2_super_ops = {
  1235. .alloc_inode = gfs2_alloc_inode,
  1236. .destroy_inode = gfs2_destroy_inode,
  1237. .write_inode = gfs2_write_inode,
  1238. .evict_inode = gfs2_evict_inode,
  1239. .put_super = gfs2_put_super,
  1240. .sync_fs = gfs2_sync_fs,
  1241. .freeze_fs = gfs2_freeze,
  1242. .unfreeze_fs = gfs2_unfreeze,
  1243. .statfs = gfs2_statfs,
  1244. .remount_fs = gfs2_remount_fs,
  1245. .drop_inode = gfs2_drop_inode,
  1246. .show_options = gfs2_show_options,
  1247. };