[PATCH] fsfreeze: suspend and resume access to an filesystem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

Here is patch that add new command fsfreeze.
'fsfreeze' suspend and resume access to an filesystem (Linux Ext3/4, ReiserFS, JFS, XFS)
It like xfs_freeze command for XFS filesystem. I ported one for other filesystem.
Because util-linux-ng should have this. I think so.

usage:
  # fsfreeze -f /var/ftp
  # lvcreate -s -L 10G -n ls_ftpd_snap /dev/vg_data/lv_ftpd
  # fsfreeze -u /var/ftp


diff -Naur util-linux-ng.old/Makefile.am util-linux-ng/Makefile.am
--- util-linux-ng.old/Makefile.am	2010-05-11 11:57:56.000000000 +0900
+++ util-linux-ng/Makefile.am	2010-05-11 12:15:10.000000000 +0900
@@ -4,6 +4,7 @@
 	include \
 	disk-utils \
 	fdisk \
+	fsfreeze \
 	getopt \
 	lib \
 	shlibs \
diff -Naur util-linux-ng.old/configure.ac util-linux-ng/configure.ac
--- util-linux-ng.old/configure.ac	2010-05-11 11:57:57.000000000 +0900
+++ util-linux-ng/configure.ac	2010-05-11 12:14:38.000000000 +0900
@@ -1096,6 +1096,7 @@
 disk-utils/Makefile
 fdisk/Makefile
 fsck/Makefile
+fsfreeze/Makefile
 getopt/Makefile
 hwclock/Makefile
 include/Makefile
diff -Naur util-linux-ng.old/fsfreeze/Makefile.am util-linux-ng/fsfreeze/Makefile.am
--- util-linux-ng.old/fsfreeze/Makefile.am	1970-01-01 09:00:00.000000000 +0900
+++ util-linux-ng/fsfreeze/Makefile.am	2010-05-11 12:27:42.000000000 +0900
@@ -0,0 +1,10 @@
+include $(top_srcdir)/config/include-Makefile.am
+
+sbin_PROGRAMS = fsfreeze
+fsfreeze_SOURCES = fsfreeze.c
+
+if LINUX
+fsfreeze_SOURCES += ../lib/linux_version.c
+endif
+
+dist_man_MANS = fsfreeze.8
diff -Naur util-linux-ng.old/fsfreeze/fsfreeze.8 util-linux-ng/fsfreeze/fsfreeze.8
--- util-linux-ng.old/fsfreeze/fsfreeze.8	1970-01-01 09:00:00.000000000 +0900
+++ util-linux-ng/fsfreeze/fsfreeze.8	2010-05-11 12:49:17.000000000 +0900
@@ -0,0 +1,63 @@
+.TH fsfreeze 8
+.SH NAME
+fsfreeze \- suspend access to an filesystem (Linux Ext3/4, ReiserFS, JFS, XFS)
+.SH SYNOPSIS
+.B fsfreeze \-f
+|
+.B \-u
+.I mount-point
+.fi
+.SH DESCRIPTION
+.B fsfreeze
+suspends and resumes access to an filesystem
+.PP
+.B fsfreeze
+halts new access to the filesystem and creates a stable image on disk.
+.B fsfreeze
+is intended to be used with volume managers and hardware RAID devices
+that support the creation of snapshots.
+.PP
+The
+.I mount-point
+argument is the pathname of the directory where the filesystem
+is mounted.
+The filesystem must be mounted to be frozen (see
+.BR mount (8)).
+.PP
+The
+.B \-f
+flag requests the specified a filesystem to be
+frozen from new modifications.
+When this is selected, all ongoing transactions in the filesystem
+are allowed to complete, new write system calls are halted, other
+calls which modify the filesystem are halted, and all dirty data,
+metadata, and log information are written to disk.
+Any process attempting to write to the frozen filesystem will block
+waiting for the filesystem to be unfrozen.
+.PP
+Note that even after freezing, the on-disk filesystem can contain
+information on files that are still in the process of unlinking.
+These files will not be unlinked until the filesystem is unfrozen
+or a clean mount of the snapshot is complete.
+.PP
+The
+.B \-u
+flag is used to un-freeze the filesystem and allow
+operations to continue.
+Any filesystem modifications that were blocked by the freeze are
+unblocked and allowed to complete.
+.SH AUTHOR
+.PP
+Written by Hajime Taira.
+.SH NOTES
+.PP
+This man page based on xfs_freeze.
+One of
+.B \-f
+or
+.B \-u
+must be supplied to
+.BR fsfreeze .
+.SH SEE ALSO
+.BR lvm (8),
+.BR mount (8).
diff -Naur util-linux-ng.old/fsfreeze/fsfreeze.c util-linux-ng/fsfreeze/fsfreeze.c
--- util-linux-ng.old/fsfreeze/fsfreeze.c	1970-01-01 09:00:00.000000000 +0900
+++ util-linux-ng/fsfreeze/fsfreeze.c	2010-05-11 12:49:21.000000000 +0900
@@ -0,0 +1,93 @@
+/* fsfreeze.c -- Filesystem freeze/unfreeze IO for Linux
+ * 
+ * Copyright (C) 2010 Hajime Taira (htaira@xxxxxxxxxx)
+ *                    Masatake YAMATO (yamato@xxxxxxxxxx)
+ *
+ * This program is free software.  You can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation: either version 1 or
+ * (at your option) any later version.
+ */
+
+
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+
+int freeze_f(int fd)
+{
+	return ioctl(fd, FIFREEZE, 0);
+}
+
+int unfreeze_f(int fd)
+{
+	return ioctl(fd, FITHAW, 0);
+}
+
+void usage()
+{
+	fprintf(stderr, "fsfreeze -f | -u <mount point>\n");
+	fprintf(stderr, "\n");
+	fprintf(stderr, "fsfreeze -f /mnt/target\n");
+}
+
+int main(int argc, char **argv)
+{
+	int fd;
+	int ret = -1;
+	char *path;
+
+	if(argc == 3)
+	{
+		path = argv[2];
+		fd = open(path, O_WRONLY);
+		if(fd < 0) {
+			if (errno == EISDIR) {
+				fd = open(path, O_RDONLY);
+				if (fd < 0) {
+					perror(path);
+					return ret;
+				}
+			} else {
+				perror(path);
+				return ret;
+			}
+		}
+
+		/* freeze operation */
+		if(strcmp(argv[1],"-f") == 0)
+		{
+			ret = freeze_f(fd);
+			if (ret != 0)
+			{
+				perror("freeze");
+				close(fd);
+				return ret;
+			}
+
+		}
+		/* unfreeze operation */
+		else if(strcmp(argv[1],"-u") == 0)
+		{
+			ret = unfreeze_f(fd);
+			if (ret != 0)
+			{
+				perror("unfreeze");
+				close(fd);
+				return ret;
+			}
+		} else {
+			close(fd);
+			usage();
+		}
+
+		close(fd);
+	} else {
+		usage();
+	}
+
+	return ret;
+}

--
Best regards,

Hajime Taira <htaira@xxxxxxxxxx>
RHEL Solution Architect
Global Services
Red Hat K.K.

Ebisu Neonato 8F, 4-1-18, Ebisu,
Shibuya-ku, Tokyo, Japan 150-0013
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux