ops_super.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 v.2.
  8. */
  9. #include <linux/sched.h>
  10. #include <linux/slab.h>
  11. #include <linux/spinlock.h>
  12. #include <linux/completion.h>
  13. #include <linux/buffer_head.h>
  14. #include <linux/statfs.h>
  15. #include <linux/vmalloc.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 "gfs2.h"
  22. #include "lm_interface.h"
  23. #include "incore.h"
  24. #include "glock.h"
  25. #include "inode.h"
  26. #include "lm.h"
  27. #include "log.h"
  28. #include "mount.h"
  29. #include "ops_super.h"
  30. #include "page.h"
  31. #include "quota.h"
  32. #include "recovery.h"
  33. #include "rgrp.h"
  34. #include "super.h"
  35. #include "sys.h"
  36. #include "util.h"
  37. /**
  38. * gfs2_write_inode - Make sure the inode is stable on the disk
  39. * @inode: The inode
  40. * @sync: synchronous write flag
  41. *
  42. * Returns: errno
  43. */
  44. static int gfs2_write_inode(struct inode *inode, int sync)
  45. {
  46. struct gfs2_inode *ip = inode->u.generic_ip;
  47. if (current->flags & PF_MEMALLOC)
  48. return 0;
  49. if (ip && sync)
  50. gfs2_log_flush(ip->i_gl->gl_sbd, ip->i_gl);
  51. return 0;
  52. }
  53. /**
  54. * gfs2_put_super - Unmount the filesystem
  55. * @sb: The VFS superblock
  56. *
  57. */
  58. static void gfs2_put_super(struct super_block *sb)
  59. {
  60. struct gfs2_sbd *sdp = sb->s_fs_info;
  61. int error;
  62. if (!sdp)
  63. return;
  64. /* Unfreeze the filesystem, if we need to */
  65. mutex_lock(&sdp->sd_freeze_lock);
  66. if (sdp->sd_freeze_count)
  67. gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
  68. mutex_unlock(&sdp->sd_freeze_lock);
  69. kthread_stop(sdp->sd_inoded_process);
  70. kthread_stop(sdp->sd_quotad_process);
  71. kthread_stop(sdp->sd_logd_process);
  72. kthread_stop(sdp->sd_recoverd_process);
  73. while (sdp->sd_glockd_num--)
  74. kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
  75. kthread_stop(sdp->sd_scand_process);
  76. if (!(sb->s_flags & MS_RDONLY)) {
  77. error = gfs2_make_fs_ro(sdp);
  78. if (error)
  79. gfs2_io_error(sdp);
  80. }
  81. /* At this point, we're through modifying the disk */
  82. /* Release stuff */
  83. iput(sdp->sd_master_dir);
  84. iput(sdp->sd_jindex);
  85. iput(sdp->sd_inum_inode);
  86. iput(sdp->sd_statfs_inode);
  87. iput(sdp->sd_rindex);
  88. iput(sdp->sd_quota_inode);
  89. gfs2_glock_put(sdp->sd_rename_gl);
  90. gfs2_glock_put(sdp->sd_trans_gl);
  91. if (!sdp->sd_args.ar_spectator) {
  92. gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
  93. gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
  94. gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
  95. gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
  96. gfs2_glock_dq_uninit(&sdp->sd_ut_gh);
  97. gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
  98. iput(sdp->sd_ir_inode);
  99. iput(sdp->sd_sc_inode);
  100. iput(sdp->sd_ut_inode);
  101. iput(sdp->sd_qc_inode);
  102. }
  103. gfs2_glock_dq_uninit(&sdp->sd_live_gh);
  104. gfs2_clear_rgrpd(sdp);
  105. gfs2_jindex_free(sdp);
  106. /* Take apart glock structures and buffer lists */
  107. gfs2_gl_hash_clear(sdp, WAIT);
  108. /* Unmount the locking protocol */
  109. gfs2_lm_unmount(sdp);
  110. /* At this point, we're through participating in the lockspace */
  111. gfs2_sys_fs_del(sdp);
  112. vfree(sdp);
  113. sb->s_fs_info = NULL;
  114. }
  115. /**
  116. * gfs2_write_super - disk commit all incore transactions
  117. * @sb: the filesystem
  118. *
  119. * This function is called every time sync(2) is called.
  120. * After this exits, all dirty buffers are synced.
  121. */
  122. static void gfs2_write_super(struct super_block *sb)
  123. {
  124. struct gfs2_sbd *sdp = sb->s_fs_info;
  125. gfs2_log_flush(sdp, NULL);
  126. }
  127. /**
  128. * gfs2_write_super_lockfs - prevent further writes to the filesystem
  129. * @sb: the VFS structure for the filesystem
  130. *
  131. */
  132. static void gfs2_write_super_lockfs(struct super_block *sb)
  133. {
  134. struct gfs2_sbd *sdp = sb->s_fs_info;
  135. int error;
  136. for (;;) {
  137. error = gfs2_freeze_fs(sdp);
  138. if (!error)
  139. break;
  140. switch (error) {
  141. case -EBUSY:
  142. fs_err(sdp, "waiting for recovery before freeze\n");
  143. break;
  144. default:
  145. fs_err(sdp, "error freezing FS: %d\n", error);
  146. break;
  147. }
  148. fs_err(sdp, "retrying...\n");
  149. msleep(1000);
  150. }
  151. }
  152. /**
  153. * gfs2_unlockfs - reallow writes to the filesystem
  154. * @sb: the VFS structure for the filesystem
  155. *
  156. */
  157. static void gfs2_unlockfs(struct super_block *sb)
  158. {
  159. struct gfs2_sbd *sdp = sb->s_fs_info;
  160. gfs2_unfreeze_fs(sdp);
  161. }
  162. /**
  163. * gfs2_statfs - Gather and return stats about the filesystem
  164. * @sb: The superblock
  165. * @statfsbuf: The buffer
  166. *
  167. * Returns: 0 on success or error code
  168. */
  169. static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf)
  170. {
  171. struct gfs2_sbd *sdp = sb->s_fs_info;
  172. struct gfs2_statfs_change sc;
  173. int error;
  174. if (gfs2_tune_get(sdp, gt_statfs_slow))
  175. error = gfs2_statfs_slow(sdp, &sc);
  176. else
  177. error = gfs2_statfs_i(sdp, &sc);
  178. if (error)
  179. return error;
  180. memset(buf, 0, sizeof(struct kstatfs));
  181. buf->f_type = GFS2_MAGIC;
  182. buf->f_bsize = sdp->sd_sb.sb_bsize;
  183. buf->f_blocks = sc.sc_total;
  184. buf->f_bfree = sc.sc_free;
  185. buf->f_bavail = sc.sc_free;
  186. buf->f_files = sc.sc_dinodes + sc.sc_free;
  187. buf->f_ffree = sc.sc_free;
  188. buf->f_namelen = GFS2_FNAMESIZE;
  189. return 0;
  190. }
  191. /**
  192. * gfs2_remount_fs - called when the FS is remounted
  193. * @sb: the filesystem
  194. * @flags: the remount flags
  195. * @data: extra data passed in (not used right now)
  196. *
  197. * Returns: errno
  198. */
  199. static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
  200. {
  201. struct gfs2_sbd *sdp = sb->s_fs_info;
  202. int error;
  203. error = gfs2_mount_args(sdp, data, 1);
  204. if (error)
  205. return error;
  206. if (sdp->sd_args.ar_spectator)
  207. *flags |= MS_RDONLY;
  208. else {
  209. if (*flags & MS_RDONLY) {
  210. if (!(sb->s_flags & MS_RDONLY))
  211. error = gfs2_make_fs_ro(sdp);
  212. } else if (!(*flags & MS_RDONLY) &&
  213. (sb->s_flags & MS_RDONLY)) {
  214. error = gfs2_make_fs_rw(sdp);
  215. }
  216. }
  217. if (*flags & (MS_NOATIME | MS_NODIRATIME))
  218. set_bit(SDF_NOATIME, &sdp->sd_flags);
  219. else
  220. clear_bit(SDF_NOATIME, &sdp->sd_flags);
  221. /* Don't let the VFS update atimes. GFS2 handles this itself. */
  222. *flags |= MS_NOATIME | MS_NODIRATIME;
  223. return error;
  224. }
  225. /**
  226. * gfs2_clear_inode - Deallocate an inode when VFS is done with it
  227. * @inode: The VFS inode
  228. *
  229. */
  230. static void gfs2_clear_inode(struct inode *inode)
  231. {
  232. struct gfs2_inode *ip = inode->u.generic_ip;
  233. if (ip) {
  234. spin_lock(&ip->i_spin);
  235. ip->i_vnode = NULL;
  236. inode->u.generic_ip = NULL;
  237. spin_unlock(&ip->i_spin);
  238. gfs2_glock_schedule_for_reclaim(ip->i_gl);
  239. gfs2_inode_put(ip);
  240. }
  241. }
  242. /**
  243. * gfs2_show_options - Show mount options for /proc/mounts
  244. * @s: seq_file structure
  245. * @mnt: vfsmount
  246. *
  247. * Returns: 0 on success or error code
  248. */
  249. static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  250. {
  251. struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
  252. struct gfs2_args *args = &sdp->sd_args;
  253. if (args->ar_lockproto[0])
  254. seq_printf(s, ",lockproto=%s", args->ar_lockproto);
  255. if (args->ar_locktable[0])
  256. seq_printf(s, ",locktable=%s", args->ar_locktable);
  257. if (args->ar_hostdata[0])
  258. seq_printf(s, ",hostdata=%s", args->ar_hostdata);
  259. if (args->ar_spectator)
  260. seq_printf(s, ",spectator");
  261. if (args->ar_ignore_local_fs)
  262. seq_printf(s, ",ignore_local_fs");
  263. if (args->ar_localflocks)
  264. seq_printf(s, ",localflocks");
  265. if (args->ar_localcaching)
  266. seq_printf(s, ",localcaching");
  267. if (args->ar_debug)
  268. seq_printf(s, ",debug");
  269. if (args->ar_upgrade)
  270. seq_printf(s, ",upgrade");
  271. if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT)
  272. seq_printf(s, ",num_glockd=%u", args->ar_num_glockd);
  273. if (args->ar_posix_acl)
  274. seq_printf(s, ",acl");
  275. if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
  276. char *state;
  277. switch (args->ar_quota) {
  278. case GFS2_QUOTA_OFF:
  279. state = "off";
  280. break;
  281. case GFS2_QUOTA_ACCOUNT:
  282. state = "account";
  283. break;
  284. case GFS2_QUOTA_ON:
  285. state = "on";
  286. break;
  287. default:
  288. state = "unknown";
  289. break;
  290. }
  291. seq_printf(s, ",quota=%s", state);
  292. }
  293. if (args->ar_suiddir)
  294. seq_printf(s, ",suiddir");
  295. if (args->ar_data != GFS2_DATA_DEFAULT) {
  296. char *state;
  297. switch (args->ar_data) {
  298. case GFS2_DATA_WRITEBACK:
  299. state = "writeback";
  300. break;
  301. case GFS2_DATA_ORDERED:
  302. state = "ordered";
  303. break;
  304. default:
  305. state = "unknown";
  306. break;
  307. }
  308. seq_printf(s, ",data=%s", state);
  309. }
  310. return 0;
  311. }
  312. struct super_operations gfs2_super_ops = {
  313. .write_inode = gfs2_write_inode,
  314. .put_super = gfs2_put_super,
  315. .write_super = gfs2_write_super,
  316. .write_super_lockfs = gfs2_write_super_lockfs,
  317. .unlockfs = gfs2_unlockfs,
  318. .statfs = gfs2_statfs,
  319. .remount_fs = gfs2_remount_fs,
  320. .clear_inode = gfs2_clear_inode,
  321. .show_options = gfs2_show_options,
  322. };