ops_super.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401
  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/vmalloc.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 <asm/semaphore.h>
  21. #include "gfs2.h"
  22. #include "glock.h"
  23. #include "inode.h"
  24. #include "lm.h"
  25. #include "log.h"
  26. #include "mount.h"
  27. #include "ops_super.h"
  28. #include "page.h"
  29. #include "quota.h"
  30. #include "recovery.h"
  31. #include "rgrp.h"
  32. #include "super.h"
  33. #include "sys.h"
  34. /**
  35. * gfs2_write_inode - Make sure the inode is stable on the disk
  36. * @inode: The inode
  37. * @sync: synchronous write flag
  38. *
  39. * Returns: errno
  40. */
  41. static int gfs2_write_inode(struct inode *inode, int sync)
  42. {
  43. struct gfs2_inode *ip = get_v2ip(inode);
  44. atomic_inc(&ip->i_sbd->sd_ops_super);
  45. if (current->flags & PF_MEMALLOC)
  46. return 0;
  47. if (ip && sync)
  48. gfs2_log_flush_glock(ip->i_gl);
  49. return 0;
  50. }
  51. /**
  52. * gfs2_put_super - Unmount the filesystem
  53. * @sb: The VFS superblock
  54. *
  55. */
  56. static void gfs2_put_super(struct super_block *sb)
  57. {
  58. struct gfs2_sbd *sdp = get_v2sdp(sb);
  59. int error;
  60. if (!sdp)
  61. return;
  62. atomic_inc(&sdp->sd_ops_super);
  63. /* Unfreeze the filesystem, if we need to */
  64. mutex_lock(&sdp->sd_freeze_lock);
  65. if (sdp->sd_freeze_count)
  66. gfs2_glock_dq_uninit(&sdp->sd_freeze_gh);
  67. mutex_unlock(&sdp->sd_freeze_lock);
  68. kthread_stop(sdp->sd_inoded_process);
  69. kthread_stop(sdp->sd_quotad_process);
  70. kthread_stop(sdp->sd_logd_process);
  71. kthread_stop(sdp->sd_recoverd_process);
  72. while (sdp->sd_glockd_num--)
  73. kthread_stop(sdp->sd_glockd_process[sdp->sd_glockd_num]);
  74. kthread_stop(sdp->sd_scand_process);
  75. if (!(sb->s_flags & MS_RDONLY)) {
  76. error = gfs2_make_fs_ro(sdp);
  77. if (error)
  78. gfs2_io_error(sdp);
  79. }
  80. /* At this point, we're through modifying the disk */
  81. /* Release stuff */
  82. iput(sdp->sd_master_dir);
  83. iput(sdp->sd_jindex);
  84. iput(sdp->sd_inum_inode);
  85. iput(sdp->sd_statfs_inode);
  86. iput(sdp->sd_rindex);
  87. iput(sdp->sd_quota_inode);
  88. iput(sdp->sd_root_dir);
  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. /* Get rid of any extra inodes */
  113. while (invalidate_inodes(sb))
  114. yield();
  115. vfree(sdp);
  116. set_v2sdp(sb, NULL);
  117. }
  118. /**
  119. * gfs2_write_super - disk commit all incore transactions
  120. * @sb: the filesystem
  121. *
  122. * This function is called every time sync(2) is called.
  123. * After this exits, all dirty buffers and synced.
  124. */
  125. static void gfs2_write_super(struct super_block *sb)
  126. {
  127. struct gfs2_sbd *sdp = get_v2sdp(sb);
  128. atomic_inc(&sdp->sd_ops_super);
  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 = get_v2sdp(sb);
  139. int error;
  140. atomic_inc(&sdp->sd_ops_super);
  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 = get_v2sdp(sb);
  165. atomic_inc(&sdp->sd_ops_super);
  166. gfs2_unfreeze_fs(sdp);
  167. }
  168. /**
  169. * gfs2_statfs - Gather and return stats about the filesystem
  170. * @sb: The superblock
  171. * @statfsbuf: The buffer
  172. *
  173. * Returns: 0 on success or error code
  174. */
  175. static int gfs2_statfs(struct super_block *sb, struct kstatfs *buf)
  176. {
  177. struct gfs2_sbd *sdp = get_v2sdp(sb);
  178. struct gfs2_statfs_change sc;
  179. int error;
  180. atomic_inc(&sdp->sd_ops_super);
  181. if (gfs2_tune_get(sdp, gt_statfs_slow))
  182. error = gfs2_statfs_slow(sdp, &sc);
  183. else
  184. error = gfs2_statfs_i(sdp, &sc);
  185. if (error)
  186. return error;
  187. memset(buf, 0, sizeof(struct kstatfs));
  188. buf->f_type = GFS2_MAGIC;
  189. buf->f_bsize = sdp->sd_sb.sb_bsize;
  190. buf->f_blocks = sc.sc_total;
  191. buf->f_bfree = sc.sc_free;
  192. buf->f_bavail = sc.sc_free;
  193. buf->f_files = sc.sc_dinodes + sc.sc_free;
  194. buf->f_ffree = sc.sc_free;
  195. buf->f_namelen = GFS2_FNAMESIZE;
  196. return 0;
  197. }
  198. /**
  199. * gfs2_remount_fs - called when the FS is remounted
  200. * @sb: the filesystem
  201. * @flags: the remount flags
  202. * @data: extra data passed in (not used right now)
  203. *
  204. * Returns: errno
  205. */
  206. static int gfs2_remount_fs(struct super_block *sb, int *flags, char *data)
  207. {
  208. struct gfs2_sbd *sdp = get_v2sdp(sb);
  209. int error;
  210. atomic_inc(&sdp->sd_ops_super);
  211. error = gfs2_mount_args(sdp, data, 1);
  212. if (error)
  213. return error;
  214. if (sdp->sd_args.ar_spectator)
  215. *flags |= MS_RDONLY;
  216. else {
  217. if (*flags & MS_RDONLY) {
  218. if (!(sb->s_flags & MS_RDONLY))
  219. error = gfs2_make_fs_ro(sdp);
  220. } else if (!(*flags & MS_RDONLY) &&
  221. (sb->s_flags & MS_RDONLY)) {
  222. error = gfs2_make_fs_rw(sdp);
  223. }
  224. }
  225. if (*flags & (MS_NOATIME | MS_NODIRATIME))
  226. set_bit(SDF_NOATIME, &sdp->sd_flags);
  227. else
  228. clear_bit(SDF_NOATIME, &sdp->sd_flags);
  229. /* Don't let the VFS update atimes. GFS2 handles this itself. */
  230. *flags |= MS_NOATIME | MS_NODIRATIME;
  231. return error;
  232. }
  233. /**
  234. * gfs2_clear_inode - Deallocate an inode when VFS is done with it
  235. * @inode: The VFS inode
  236. *
  237. */
  238. static void gfs2_clear_inode(struct inode *inode)
  239. {
  240. struct gfs2_inode *ip = get_v2ip(inode);
  241. atomic_inc(&get_v2sdp(inode->i_sb)->sd_ops_super);
  242. if (ip) {
  243. spin_lock(&ip->i_spin);
  244. ip->i_vnode = NULL;
  245. set_v2ip(inode, NULL);
  246. spin_unlock(&ip->i_spin);
  247. gfs2_glock_schedule_for_reclaim(ip->i_gl);
  248. gfs2_inode_put(ip);
  249. }
  250. }
  251. /**
  252. * gfs2_show_options - Show mount options for /proc/mounts
  253. * @s: seq_file structure
  254. * @mnt: vfsmount
  255. *
  256. * Returns: 0 on success or error code
  257. */
  258. static int gfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  259. {
  260. struct gfs2_sbd *sdp = get_v2sdp(mnt->mnt_sb);
  261. struct gfs2_args *args = &sdp->sd_args;
  262. atomic_inc(&sdp->sd_ops_super);
  263. if (args->ar_lockproto[0])
  264. seq_printf(s, ",lockproto=%s", args->ar_lockproto);
  265. if (args->ar_locktable[0])
  266. seq_printf(s, ",locktable=%s", args->ar_locktable);
  267. if (args->ar_hostdata[0])
  268. seq_printf(s, ",hostdata=%s", args->ar_hostdata);
  269. if (args->ar_spectator)
  270. seq_printf(s, ",spectator");
  271. if (args->ar_ignore_local_fs)
  272. seq_printf(s, ",ignore_local_fs");
  273. if (args->ar_localflocks)
  274. seq_printf(s, ",localflocks");
  275. if (args->ar_localcaching)
  276. seq_printf(s, ",localcaching");
  277. if (args->ar_debug)
  278. seq_printf(s, ",debug");
  279. if (args->ar_upgrade)
  280. seq_printf(s, ",upgrade");
  281. if (args->ar_num_glockd != GFS2_GLOCKD_DEFAULT)
  282. seq_printf(s, ",num_glockd=%u", args->ar_num_glockd);
  283. if (args->ar_posix_acl)
  284. seq_printf(s, ",acl");
  285. if (args->ar_quota != GFS2_QUOTA_DEFAULT) {
  286. char *state;
  287. switch (args->ar_quota) {
  288. case GFS2_QUOTA_OFF:
  289. state = "off";
  290. break;
  291. case GFS2_QUOTA_ACCOUNT:
  292. state = "account";
  293. break;
  294. case GFS2_QUOTA_ON:
  295. state = "on";
  296. break;
  297. default:
  298. state = "unknown";
  299. break;
  300. }
  301. seq_printf(s, ",quota=%s", state);
  302. }
  303. if (args->ar_suiddir)
  304. seq_printf(s, ",suiddir");
  305. if (args->ar_data != GFS2_DATA_DEFAULT) {
  306. char *state;
  307. switch (args->ar_data) {
  308. case GFS2_DATA_WRITEBACK:
  309. state = "writeback";
  310. break;
  311. case GFS2_DATA_ORDERED:
  312. state = "ordered";
  313. break;
  314. default:
  315. state = "unknown";
  316. break;
  317. }
  318. seq_printf(s, ",data=%s", state);
  319. }
  320. return 0;
  321. }
  322. struct super_operations gfs2_super_ops = {
  323. .write_inode = gfs2_write_inode,
  324. .put_super = gfs2_put_super,
  325. .write_super = gfs2_write_super,
  326. .write_super_lockfs = gfs2_write_super_lockfs,
  327. .unlockfs = gfs2_unlockfs,
  328. .statfs = gfs2_statfs,
  329. .remount_fs = gfs2_remount_fs,
  330. .clear_inode = gfs2_clear_inode,
  331. .show_options = gfs2_show_options,
  332. };