super.c 33 KB

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