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

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

 



Hello, Karel.

Thank you!
I reviewed. beautiful.

--
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

----- original message -----
From: "Karel Zak" <kzak@xxxxxxxxxx>
To: "Hajime Taira" <htaira@xxxxxxxxxx>
Cc: "Yann Droneaud" <yann@xxxxxxxxxxx>, "Américo Wang" <xiyou.wangcong@xxxxxxxxx>, util-linux-ng@xxxxxxxxxxxxxxx
送信済み: 2010年5月13日, 木曜日 午後 8:42:10 GMT+09:00日本
件名: Re: [PATCH] fsfreeze: suspend and resume access to an filesystem

On Wed, May 12, 2010 at 06:27:16AM -0400, Hajime Taira wrote:
> I'm sorry. My source code was so dirty.
> I fixed all problem. Thank you for your advice.

 Thanks. I have a little modified the code to match with 
 the rest of util-linux-ng (or at least with new utils in the
 package). Please, review.

    Karel

>From 5d3cf69cc712babe40f81d6723e61a092c5e6b5c Mon Sep 17 00:00:00 2001
From: Hajime Taira <htaira@xxxxxxxxxx>
Date: Thu, 13 May 2010 13:23:49 +0200
Subject: [PATCH] fsfreeze: new command

[kzak@xxxxxxxxxx: - cleanup
                  - add long options
                  - add note about DM to the man page
                  - use err.h and nls.h]

Signed-off-by: Hajime Taira <htaira@xxxxxxxxxx>
Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
 include/blkdev.h      |    5 ++
 sys-utils/.gitignore  |    1 +
 sys-utils/Makefile.am |    4 +-
 sys-utils/fsfreeze.8  |   75 +++++++++++++++++++++++++++++
 sys-utils/fsfreeze.c  |  127 +++++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 210 insertions(+), 2 deletions(-)
 create mode 100644 sys-utils/fsfreeze.8
 create mode 100644 sys-utils/fsfreeze.c

diff --git a/include/blkdev.h b/include/blkdev.h
index 34e4e92..0eea01c 100644
--- a/include/blkdev.h
+++ b/include/blkdev.h
@@ -45,6 +45,11 @@
 #define BLKPBSZGET _IO(0x12,123)
 #endif
 
+#ifndef FIFREEZE
+#define FIFREEZE   _IOWR('X', 119, int)    /* Freeze */
+#define FITHAW     _IOWR('X', 120, int)    /* Thaw */
+#endif
+
 #ifndef HDIO_GETGEO
 # ifdef __linux__
 #  define HDIO_GETGEO 0x0301
diff --git a/sys-utils/.gitignore b/sys-utils/.gitignore
index 7985d7a..f82d107 100644
--- a/sys-utils/.gitignore
+++ b/sys-utils/.gitignore
@@ -4,6 +4,7 @@ cytune
 dmesg
 fallocate
 flock
+fsfreeze
 i386.8
 ia64.8
 ipcmk
diff --git a/sys-utils/Makefile.am b/sys-utils/Makefile.am
index 76828cc..957fd6e 100644
--- a/sys-utils/Makefile.am
+++ b/sys-utils/Makefile.am
@@ -10,12 +10,12 @@ dist_man_MANS = flock.1 ipcrm.1 ipcs.1 ipcmk.1 renice.1 setsid.1 \
 
 if LINUX
 bin_PROGRAMS += dmesg
-sbin_PROGRAMS += ctrlaltdel
+sbin_PROGRAMS += ctrlaltdel fsfreeze
 usrbin_exec_PROGRAMS += cytune setarch lscpu
 usrsbin_exec_PROGRAMS += ldattach tunelp rtcwake
 
 dist_man_MANS += dmesg.1 ctrlaltdel.8 cytune.8 setarch.8 \
-		ldattach.8 lscpu.1 tunelp.8 rtcwake.8
+		ldattach.8 lscpu.1 tunelp.8 rtcwake.8 fsfreeze.8
 endif
 
 cytune_SOURCES = cytune.c cyclades.h
diff --git a/sys-utils/fsfreeze.8 b/sys-utils/fsfreeze.8
new file mode 100644
index 0000000..4408bdd
--- /dev/null
+++ b/sys-utils/fsfreeze.8
@@ -0,0 +1,75 @@
+.\" -*- nroff -*-
+.TH FSFREEZE 8 "May 2010"
+.SH NAME
+fsfreeze \- suspend access to an filesystem (Linux Ext3/4, ReiserFS, JFS, XFS).
+.SH SYNOPSIS
+.B fsfreeze
+.RB \-f
+.I mountpoint
+
+.B fsfreeze
+.RB \-u
+.I mountpoint
+
+.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 hardware RAID devices that support the creation 
+of snapshots.
+.PP
+.B fsfreeze
+is unncessary for
+.B device-mapper
+devices. The device-mapper (and LVM)
+automatically freezes filesystem on the device when a snapshot creation is requested.
+For more details see the
+.BR dmsetup (8)
+man page.
+.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)).
+.SH OPTIONS
+.IP "\fB\-h, \-\-help\fP"
+Print help and exit.
+.IP "\fB\-f, \-\-freeze\fP"
+This option 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.
+
+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.
+.IP "\fB\-u, \-\-unfreeze\fP
+This option 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 mount (8)
+.SH AVAILABILITY
+The fsfreeze command is part of the util-linux-ng package and is available from
+ftp://ftp.kernel.org/pub/linux/utils/util-linux-ng/.
+
diff --git a/sys-utils/fsfreeze.c b/sys-utils/fsfreeze.c
new file mode 100644
index 0000000..0e250e1
--- /dev/null
+++ b/sys-utils/fsfreeze.c
@@ -0,0 +1,127 @@
+/*
+ * 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 <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <linux/fs.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <getopt.h>
+#include <err.h>
+
+#include "blkdev.h"
+#include "nls.h"
+#include "c.h"
+
+static int freeze_f(int fd)
+{
+	return ioctl(fd, FIFREEZE, 0);
+}
+
+static int unfreeze_f(int fd)
+{
+	return ioctl(fd, FITHAW, 0);
+}
+
+static void __attribute__((__noreturn__)) usage(FILE *out)
+{
+	fprintf(out, _("Usage: %s [options] <mount point>\n\nOptions:\n"),
+			program_invocation_short_name);
+
+	fprintf(out, _(
+		" -h, --help          this help\n"
+		" -f, --freeze        freeze the filesystem\n"
+		" -u, --unfreeze      unfreeze the filesystem\n"));
+
+	fprintf(out, _("\nFor more information see fsfreeze(8).\n"));
+
+	exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
+}
+
+int main(int argc, char **argv)
+{
+	int fd = -1, c;
+	int freeze = -1, rc = EXIT_FAILURE;
+	char *path;
+	struct stat sb;
+
+	struct option longopts[] = {
+	    { "help",      0, 0, 'h' },
+	    { "freeze",    0, 0, 'f' },
+	    { "unfreeze",  0, 0, 'u' },
+	    { NULL,        0, 0, 0 }
+	};
+
+	setlocale(LC_ALL, "");
+	bindtextdomain(PACKAGE, LOCALEDIR);
+	textdomain(PACKAGE);
+
+	while ((c = getopt_long(argc, argv, "hfu", longopts, NULL)) != -1) {
+		switch(c) {
+		case 'h':
+			usage(stdout);
+			break;
+		case 'f':
+			freeze = TRUE;
+			break;
+		case 'u':
+			freeze = FALSE;
+			break;
+		default:
+			usage(stderr);
+			break;
+		}
+	}
+
+	if (freeze == -1)
+		errx(EXIT_FAILURE, _("no action specified"));
+	if (optind == argc)
+		errx(EXIT_FAILURE, _("no filename specified"));
+
+	path = argv[optind++];
+	fd = open(path, O_RDONLY);
+	if (fd < 0)
+		err(EXIT_FAILURE, _("%s: open failed"), path);
+
+	if (fstat(fd, &sb) == -1) {
+		warn(_("%s: fstat failed"), path);
+		goto done;
+	}
+
+	if (!S_ISDIR(sb.st_mode)) {
+		warnx(_("%s: is not a directory"), path);
+		goto done;
+	}
+
+	if (freeze) {
+		if (freeze_f(fd)) {
+			warn(_("%s: freeze failed"), path);
+			goto done;
+		}
+	} else {
+		if (unfreeze_f(fd)) {
+			warn(_("%s: unfreeze failed"), path);
+			goto done;
+		}
+	}
+
+	rc = EXIT_SUCCESS;
+done:
+	if (fd >= 0)
+		close(fd);
+	return rc;
+}
+
-- 
1.6.6.1


--
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