ops_super.c 8.3 KB

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