ops_super.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  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. gfs2_glock_put(sdp->sd_rename_gl);
  91. gfs2_glock_put(sdp->sd_trans_gl);
  92. if (!sdp->sd_args.ar_spectator) {
  93. gfs2_glock_dq_uninit(&sdp->sd_journal_gh);
  94. gfs2_glock_dq_uninit(&sdp->sd_jinode_gh);
  95. gfs2_glock_dq_uninit(&sdp->sd_ir_gh);
  96. gfs2_glock_dq_uninit(&sdp->sd_sc_gh);
  97. gfs2_glock_dq_uninit(&sdp->sd_ut_gh);
  98. gfs2_glock_dq_uninit(&sdp->sd_qc_gh);
  99. iput(sdp->sd_ir_inode);
  100. iput(sdp->sd_sc_inode);
  101. iput(sdp->sd_ut_inode);
  102. iput(sdp->sd_qc_inode);
  103. }
  104. gfs2_glock_dq_uninit(&sdp->sd_live_gh);
  105. gfs2_clear_rgrpd(sdp);
  106. gfs2_jindex_free(sdp);
  107. /* Take apart glock structures and buffer lists */
  108. gfs2_gl_hash_clear(sdp, WAIT);
  109. /* Unmount the locking protocol */
  110. gfs2_lm_unmount(sdp);
  111. /* At this point, we're through participating in the lockspace */
  112. gfs2_sys_fs_del(sdp);
  113. /* Get rid of any extra inodes */
  114. while (invalidate_inodes(sb))
  115. yield();
  116. vfree(sdp);
  117. sb->s_fs_info = NULL;
  118. }
  119. /**
  120. * gfs2_write_super - disk commit all incore transactions
  121. * @sb: the filesystem
  122. *
  123. * This function is called every time sync(2) is called.
  124. * After this exits, all dirty buffers and synced.
  125. */
  126. static void gfs2_write_super(struct super_block *sb)
  127. {
  128. struct gfs2_sbd *sdp = sb->s_fs_info;
  129. gfs2_log_flush(sdp);
  130. }
  131. /**
  132. * gfs2_write_super_lockfs - prevent further writes to the filesystem
  133. * @sb: the VFS structure for the filesystem
  134. *
  135. */
  136. static void gfs2_write_super_lockfs(struct super_block *sb)
  137. {
  138. struct gfs2_sbd *sdp = sb->s_fs_info;
  139. int error;
  140. for (;;) {
  141. error = gfs2_freeze_fs(sdp);
  142. if (!error)
  143. break;
  144. switch (error) {
  145. case -EBUSY:
  146. fs_err(sdp, "waiting for recovery before freeze\n");
  147. break;
  148. default:
  149. fs_err(sdp, "error freezing FS: %d\n", error);
  150. break;
  151. }
  152. fs_err(sdp, "retrying...\n");
  153. msleep(1000);
  154. }
  155. }
  156. /**
  157. * gfs2_unlockfs - reallow writes to the filesystem
  158. * @sb: the VFS structure for the filesystem
  159. *
  160. */
  161. static void gfs2_unlockfs(struct super_block *sb)
  162. {
  163. struct gfs2_sbd *sdp = sb->s_fs_info;
  164. gfs2_unfreeze_fs(sdp);
  165. }
  166. /**
  167. * gfs2_statfs - Gather and return stats about the filesystem
  168. * @sb: The superblock
  169. * @statfsbuf: The buffer
  170. *
  171. * Returns: 0 on success or error code
  172. */
  173. static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf)
  174. {
  175. struct gfs2_sbd *sdp = sb->s_fs_info;
  176. struct gfs2_statfs_change sc;
  177. int error;
  178. if (gfs2_tune_get(sdp, gt_statfs_slow))
  179. error = gfs2_statfs_slow(sdp, &sc);
  180. else
  181. error = gfs2_statfs_i(sdp, &sc);
  182. if (error)
  183. return error;
  184. memset(buf, 0, sizeof(struct kstatfs));
  185. buf->f_type = GFS2_MAGIC;
  186. buf->f_bsize = sdp->sd_sb.sb_bsize;
  187. buf->f_blocks = sc.sc_total;
  188. buf->f_bfree = sc.sc_free;
  189. buf->f_bavail = sc.sc_free;
  190. buf->f_files = sc.sc_dinodes + sc.sc_free;
  191. buf->f_ffree = sc.sc_free;
  192. buf->f_namelen = GFS2_FNAMESIZE;
  193. return 0;
  194. }
  195. /**
  196. * gfs2_remount_fs - called when the FS is remounted
  197. * @sb: the filesystem
  198. * @flags: the remount flags
  199. * @data: extra data passed in (not used right now)
  200. *
  201. * Returns: errno
  202. */
  203. static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
  204. {
  205. struct gfs2_sbd *sdp = sb->s_fs_info;
  206. int error;
  207. error = gfs2_mount_args(sdp, data, 1);
  208. if (error)
  209. return error;
  210. if (sdp->sd_args.ar_spectator)
  211. *flags |= MS_RDONLY;
  212. else {
  213. if (*flags & MS_RDONLY) {
  214. if (!(sb->s_flags & MS_RDONLY))
  215. error = gfs2_make_fs_ro(sdp);
  216. } else if (!(*flags & MS_RDONLY) &&
  217. (sb->s_flags & MS_RDONLY)) {
  218. error = gfs2_make_fs_rw(sdp);
  219. }
  220. }
  221. if (*flags & (MS_NOATIME | MS_NODIRATIME))
  222. set_bit(SDF_NOATIME, &sdp->sd_flags);
  223. else
  224. clear_bit(SDF_NOATIME, &sdp->sd_flags);
  225. /* Don't let the VFS update atimes. GFS2 handles this itself. */
  226. *flags |= MS_NOATIME | MS_NODIRATIME;
  227. return error;
  228. }
  229. /**
  230. * gfs2_clear_inode - Deallocate an inode when VFS is done with it
  231. * @inode: The VFS inode
  232. *
  233. */
  234. static void gfs2_clear_inode(struct inode *inode)
  235. {
  236. struct gfs2_inode *ip = inode->u.generic_ip;
  237. if (ip) {
  238. spin_lock(&ip->i_spin);
  239. ip->i_vnode = NULL;
  240. inode->u.generic_ip = NULL;
  241. spin_unlock(&ip->i_spin);
  242. gfs2_glock_schedule_for_reclaim(ip->i_gl);
  243. gfs2_inode_put(ip);
  244. }
  245. }
  246. /**
  247. * gfs2_show_options - Show mount options for /proc/mounts
  248. * @s: seq_file structure
  249. * @mnt: vfsmount
  250. *
  251. * Returns: 0 on success or error code
  252. */
  253. static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  254. {
  255. struct gfs2_sbd *sdp = mnt->mnt_sb->s_fs_info;
  256. struct gfs2_args *args = &sdp->sd_args;
  257. if (args->ar_lockproto[0])
  258. seq_printf(s, ",lockproto=%s", args->ar_lockproto);
  259. if (args->ar_locktable[0])
  260. seq_printf(s, ",locktable=%s", args->ar_locktable);
  261. if (args->ar_hostdata[0])
  262. seq_printf(s, ",hostdata=%s", args->ar_hostdata);
  263. if (args->ar_spectator)
  264. seq_printf(s, ",spectator");
  265. if (args->ar_ignore_local_fs)
  266. seq_printf(s, ",ignore_local_fs");
  267. if (args->ar_localflocks)
  268. seq_printf(s, ",localflocks");
  269. if (args->ar_localcaching)
  270. seq_printf(s, ",localcaching");
  271. if (args->ar_debug)
  272. seq_printf(s, ",debug");
  273. if (args->ar_upgrade)
  274. seq_printf(s, ",upgrade");
  275. if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT)
  276. seq_printf(s, ",num_glockd=%u", args->ar_num_glockd);
  277. if (args->ar_posix_acl)
  278. seq_printf(s, ",acl");
  279. if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
  280. char *state;
  281. switch (args->ar_quota) {
  282. case GFS2_QUOTA_OFF:
  283. state = "off";
  284. break;
  285. case GFS2_QUOTA_ACCOUNT:
  286. state = "account";
  287. break;
  288. case GFS2_QUOTA_ON:
  289. state = "on";
  290. break;
  291. default:
  292. state = "unknown";
  293. break;
  294. }
  295. seq_printf(s, ",quota=%s", state);
  296. }
  297. if (args->ar_suiddir)
  298. seq_printf(s, ",suiddir");
  299. if (args->ar_data != GFS2_DATA_DEFAULT) {
  300. char *state;
  301. switch (args->ar_data) {
  302. case GFS2_DATA_WRITEBACK:
  303. state = "writeback";
  304. break;
  305. case GFS2_DATA_ORDERED:
  306. state = "ordered";
  307. break;
  308. default:
  309. state = "unknown";
  310. break;
  311. }
  312. seq_printf(s, ",data=%s", state);
  313. }
  314. return 0;
  315. }
  316. struct super_operations gfs2_super_ops = {
  317. .write_inode = gfs2_write_inode,
  318. .put_super = gfs2_put_super,
  319. .write_super = gfs2_write_super,
  320. .write_super_lockfs = gfs2_write_super_lockfs,
  321. .unlockfs = gfs2_unlockfs,
  322. .statfs = gfs2_statfs,
  323. .remount_fs = gfs2_remount_fs,
  324. .clear_inode = gfs2_clear_inode,
  325. .show_options = gfs2_show_options,
  326. };