ops_super.c 8.4 KB

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