From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andrew Price Date: Fri, 29 Jun 2012 14:39:07 +0100 Subject: [Cluster-devel] [PATCH] gfs2-utils: Remove obsolete tools Message-ID: <1340977147-11591-1-git-send-email-anprice@redhat.com> List-Id: To: cluster-devel.redhat.com MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit From: Andrew Price gfs2_tool and gfs2_quota have been destined for removal for some time and now that Fedora 15 has EOL'd the time has come to do so. Users of gfs2_quota should now use the generic quota utilities Users of gfs2_tool should now use tunegfs2, mount options and the generic dmsetup and chattr/lsattr tools. This also removes the mount.gfs2 manpage as mount.gfs2 was removed some time ago. Mount options can be found in the gfs2(5) manpage. Signed-off-by: Andrew Price --- configure.ac | 2 - gfs2/Makefile.am | 2 +- gfs2/man/Makefile.am | 3 - gfs2/man/gfs2_quota.8 | 105 ------ gfs2/man/gfs2_tool.8 | 117 ------ gfs2/man/mount.gfs2.8 | 233 ------------ gfs2/quota/Makefile.am | 14 - gfs2/quota/check.c | 601 ------------------------------- gfs2/quota/gfs2_quota.h | 95 ----- gfs2/quota/main.c | 911 ----------------------------------------------- gfs2/quota/names.c | 83 ----- gfs2/quota/target.mk | 3 - gfs2/tool/Makefile.am | 13 - gfs2/tool/gfs2_tool.h | 64 ---- gfs2/tool/iflags.h | 40 --- gfs2/tool/main.c | 198 ---------- gfs2/tool/misc.c | 343 ------------------ gfs2/tool/ondisk.c | 13 - gfs2/tool/sb.c | 229 ------------ gfs2/tool/target.mk | 3 - gfs2/tool/tune.c | 146 -------- 21 files changed, 1 insertion(+), 3217 deletions(-) delete mode 100644 gfs2/man/gfs2_quota.8 delete mode 100644 gfs2/man/gfs2_tool.8 delete mode 100644 gfs2/man/mount.gfs2.8 delete mode 100644 gfs2/quota/Makefile.am delete mode 100644 gfs2/quota/check.c delete mode 100644 gfs2/quota/gfs2_quota.h delete mode 100644 gfs2/quota/main.c delete mode 100644 gfs2/quota/names.c delete mode 100644 gfs2/quota/target.mk delete mode 100644 gfs2/tool/Makefile.am delete mode 100644 gfs2/tool/gfs2_tool.h delete mode 100644 gfs2/tool/iflags.h delete mode 100644 gfs2/tool/main.c delete mode 100644 gfs2/tool/misc.c delete mode 100644 gfs2/tool/ondisk.c delete mode 100644 gfs2/tool/sb.c delete mode 100644 gfs2/tool/target.mk delete mode 100644 gfs2/tool/tune.c diff --git a/configure.ac b/configure.ac index e58aac9..570f826 100644 --- a/configure.ac +++ b/configure.ac @@ -280,8 +280,6 @@ AC_CONFIG_FILES([Makefile gfs2/edit/Makefile gfs2/fsck/Makefile gfs2/mkfs/Makefile - gfs2/quota/Makefile - gfs2/tool/Makefile gfs2/tune/Makefile gfs2/man/Makefile gfs2/lockgather/Makefile diff --git a/gfs2/Makefile.am b/gfs2/Makefile.am index 1011739..710ba8b 100644 --- a/gfs2/Makefile.am +++ b/gfs2/Makefile.am @@ -1,4 +1,4 @@ MAINTAINERCLEANFILES = Makefile.in -SUBDIRS = libgfs2 convert edit fsck mkfs quota tool man \ +SUBDIRS = libgfs2 convert edit fsck mkfs man \ tune include lockgather #init.d diff --git a/gfs2/man/Makefile.am b/gfs2/man/Makefile.am index 648ed84..caf4658 100644 --- a/gfs2/man/Makefile.am +++ b/gfs2/man/Makefile.am @@ -6,9 +6,6 @@ dist_man_MANS = fsck.gfs2.8 \ gfs2_edit.8 \ gfs2_grow.8 \ gfs2_jadd.8 \ - gfs2_quota.8 \ - gfs2_tool.8 \ mkfs.gfs2.8 \ gfs2_lockgather.8 \ - mount.gfs2.8 \ tunegfs2.8 diff --git a/gfs2/man/gfs2_quota.8 b/gfs2/man/gfs2_quota.8 deleted file mode 100644 index 04e09e8..0000000 --- a/gfs2/man/gfs2_quota.8 +++ /dev/null @@ -1,105 +0,0 @@ -.TH gfs2_quota 8 - -.SH NAME -gfs2_quota - Manipulate GFS2 disk quotas - -.SH SYNOPSIS -.B gfs2_quota - [\fIOPTION\fR]... - -.SH DESCRIPTION -gfs2_quota is used to examine and change quota values in a GFS2 filesystem. -This command has a number of different actions. - -GFS2 introduced a new linked list format for the quotas in the quota file. -This list format allows for faster \fBlist\fP, \fBcheck\fP and \fBinit\fP -operations. Older GFS2 quota files may be migrated to this newer format using -the \fBgfs2_quota reset\fP command. - -.SH ACTIONS -.TP -\fBlist\fP -List the contents of the quota file. Only IDs that have a non-zero hard limit, -warn limit, or value are printed. -.TP -\fBsync\fP -Sync any local quota changes to the quota file. -.TP -\fBget\fP -Get the current data for the ID specified by the -u or -g argument. -.TP -\fBlimit\fP -Set the current hard limit for the ID specified by the -u or -g argument to -the value specified by the -l argument on the specified filesystem. -The filesystem won't let the user or group use more than this much space. -A value of zero here means that no limit is enforced. -.TP -\fBwarn\fP -Set the current warn limit for the ID specified by the -u or -g argument to -the value specified by the -l argument on the specified filesystem. -The filesystem will start complaining to the user or group when more -than this much space is used. A value of zero here means that the -user won't ever be warned. -.TP -\fBcheck\fP -Scan a filesystem and make sure that what's out there on the disk matches -what's in the quota file. This is only accurate if the filesystem is -idle when this is running. If there is a mismatch, it is printed to -stdout. Note: GFS2 quotas are transactional and a quota check is \fBnot\fP -needed every time there is a system crash. -.TP -\fBinit\fP -Scan a filesystem and initialize the quota file with the values obtained -from the scan. The filesystem should be idle when this is run. You should -only need to do this if you upgrade a pre-quota GFS2 filesystem (pre-GFS2 5.1). -.TP -\fBreset\fP -The \fBreset\fP operation will truncate the quota file and all quota -information (values, limits, warnings) will be lost. All quota limits and -warnings will have to be reassigned after this operation. - -.SH OPTIONS -\fB-b\fP -The units for disk space are filesystem blocks. -.TP -\fB-f\fP \fIDirectory\fR -Specifies which filesystem to perform the action on. -.TP -\fB-g\fP \fIGID\fR -Specifies the group ID for get, limit, or warn. It can be either -the group name from the group file, or the GID number. -.TP -\fB-h\fP -Print out a help message describing available -options, then exit. -.TP -\fB-k\fP -The units for disk space are kilobytes. -.TP -\fB-l\fP \fISize\fR -Specifies the new value for the limit or warn actions. -The value is assumed to be in the units specified by the --m, -k, -s, -b arguments. The default is megabytes. -.TP -\fB-m\fP -The units for disk space are megabytes. This is the default. -.TP -\fB-n\fP -Don't try to resolve UIDs and GIDs into user and group names. -.TP -\fB-s\fP -The units for disk space are sectors (512-byte blocks). -.TP -\fB-u\fP \fIUID\fR -Specifies the user ID for get, limit, or warn. It can be either -the username from the password file, or the UID number. -.TP -\fB-V\fP -Print program version information, then exit. - -.SH EXAMPLE -To set the hard limit for user "nobody" to -1048576 kilobytes on filesystem /gfs20 - -gfs2_quota limit -l 1048576 -k -u nobody -f /gfs20 - diff --git a/gfs2/man/gfs2_tool.8 b/gfs2/man/gfs2_tool.8 deleted file mode 100644 index dccd631..0000000 --- a/gfs2/man/gfs2_tool.8 +++ /dev/null @@ -1,117 +0,0 @@ -.TH gfs2_tool 8 - -.SH NAME -gfs2_tool - interface to gfs2 ioctl/sysfs calls - -.SH SYNOPSIS -.B gfs2_tool -\fICOMMAND\fR [\fIOPTION\fR]... - -.SH DESCRIPTION -gfs2_tool is an interface to a variety of the GFS2 ioctl/sysfs calls. Some -of the functions of gfs_tool have been replaced by standard system tools -such as mount and chattr, so gfs2_tool doesn't have as many options -as gfs_tool used to. - -.SH COMMANDS -.TP -\fBclearflag\fP \fIFlag\fR \fIFile1\fR \fIFile2\fR \fI...\fR -Clear an attribute flag on a file. This is now obsolete and kept -only for backward compatibility, chattr is the preferred way to -clear attribute flags. See \fBsetflag\fP for available flags. This -option will probably be removed at a future date. -.TP -\fBfreeze\fP \fIMountPoint\fR -Freeze (quiesce) a GFS2 cluster. -.TP -\fBgettune\fP \fIMountPoint\fR -Print out the current values of the tuning parameters in a running -filesystem. A better source of similar (more comprehensive) information -is that in the /proc/mounts file. Running the mount command with no -arguments will also provide the same information. This option is -considered obsolete and will probably be removed at some future -date. -.TP -\fBjournals\fP \fIMountPoint\fR -Print out information about the journals in a mounted filesystem. -.TP -\fBlockdump\fP \fIMountPoint\fR -Print out information about the locks this machine holds for a given -filesystem. This information is also available via the debugfs -glock dump file, and accessing that file is the preferred method -of obtaining a dump of the glock state. -.\".TP -.\"\fBrindex\fP \fIMountPoint\fR -.\"Print out the resource group index of a mounted filesystem. -.TP -\fBsb\fP \fIdevice\fR \fBproto\fP \fI[newvalue]\fR -View (and possibly replace) the name of the locking protocol in the -file system superblock. The file system shouldn't be mounted by any -client when you do this. -.TP -\fBsb\fP \fIdevice\fR \fBtable\fP \fI[newvalue]\fR -View (and possibly replace) the name of the locking table in the -file system superblock. The file system shouldn't be mounted by any -client when you do this. -.TP -\fBsb\fP \fIdevice\fR \fBondisk\fP \fI[newvalue]\fR -View (and possibly replace) the ondisk format number in the -file system superblock. The file system shouldn't be mounted by any -client when you do this. No one should have to use this. -.TP -\fBsb\fP \fIdevice\fR \fBmultihost\fP \fI[newvalue]\fR -View (and possibly replace) the multihost format number in the -file system superblock. The file system shouldn't be mounted by any -client when you do this. No one should have to use this. -.TP -\fBsb\fP \fIdevice\fR \fBuuid\fP \fI[newvalue]\fR -View (and possibly replace) the uuid in the file system superblock. -The file system shouldn't be mounted by any client when you do this. -The new uuid value should be in the standard uuid format. For -example: 1AEA8269-15C5-72BD-6D83-8720B17AA4EE -.TP -\fBsb\fP \fIdevice\fR \fBall\fP -Print out the superblock. -.TP -\fBsetflag\fP \fIFlag\fR \fIFile1\fR \fIFile2\fR \fI...\fR -Set an attribute flag on a file. The currently supported flags are -jdata, immutable, appendonly, noatime, and sync. The -chattr command is the preferred way to set attributes on -files. This option will probably be removed at a future date. - -The \fIjdata\fR flag causes all the data written to a file -to be journaled. If the \fIjdata\fR flag is set for a directory, -all files and directories subsequently created within that directory -are also journaled. This behavior replaces the old \fIinherit_jdata\fR -flag from gfs. Same as chattr +j. - -The \fIimmutable\fR flag marks the file immutable. The behavior is -similar to the immutable flag in the ext2/3 filesystems. All write -access is denied. Same as chattr +i. - -The \fIappendonly\fR flag causes all data to be written at the end of -the file. Same as chattr +a. - -The \fInoatime\fR flag disables updates to the file's access time. -Same as chattr +A. - -The \fIsync\fR flag causes data written to the file to be sync'ed to -stable storage immediately. Same as chattr +S. -.TP -\fBsettune\fP \fIMountPoint\fR \fIparameter\fR \fInewvalue\fR -Set the value of tuning parameter. Use \fBgettune\fP for a listing of -tunable parameters. The mount -oremount command is the preferred way -to set the values of tunable parameters. At some future stage, when -all parameters can be set via mount, this option will be removed. -.TP -\fBunfreeze\fP \fIMountPoint\fR -Unfreeze a GFS2 cluster. -.TP -\fBversion\fP -Print out the version of GFS2 that this program goes with. -.TP -\fBwithdraw\fP \fIMountPoint\fR -Cause GFS2 to abnormally shutdown a given filesystem on this node. -This feature is only useful for testing and should not be used -during normal filesystem operation. - diff --git a/gfs2/man/mount.gfs2.8 b/gfs2/man/mount.gfs2.8 deleted file mode 100644 index 4f0f7b3..0000000 --- a/gfs2/man/mount.gfs2.8 +++ /dev/null @@ -1,233 +0,0 @@ -.TH mount.gfs2 8 - -.SH NAME -mount.gfs2 - GFS2 mount options - -.SH SYNOPSIS -.BI "mount \-a [\-fnrsvw] \-t " gfs2 " [\-O " options "] -.br -.BI "mount [\-fnrsvw] \-t " gfs2 " [\-o " options " ] " "device dir" - -.SH DESCRIPTION -For details on the common mount options, please see the -\fBmount\fP(8) command man page. -The \fIdevice\fR may be any block device on which you -have created a GFS2 filesystem. Examples include a -single disk partition (e.g. /dev/sdb3), a loopback device, a device exported -from another node (e.g. an iSCSI device), or a -logical volume (typically comprised of a number of individual disks). - -\fIdevice\fR does not necessarily need to match the device name as seen on -another node in the cluster, nor does it need to be a logical volume. However, -the use of a cluster-aware volume manager such as CLVM2 (see \fBlvm\fP(8)) -will guarantee that the managed devices are named identically on each node in a -cluster (for much easier management), and will allow you to configure a very -large volume from multiple storage units (e.g. disk drives). - -\fIdevice\fR must make the entire filesystem storage area visible to the -computer. That is, you cannot mount different parts of a single filesystem on -different computers. Each computer must see an entire filesystem. You -may, however, mount several GFS2 filesystems if you want to distribute your -data storage in a controllable way. - -This man page describes GFS2-specific options that can be passed to the GFS2 -file system at mount time, using the \fB-o\fP flag. There are many other -\fB-o\fP options handled by the generic mount command \fBmount\fP(8). -However, the options described below are specifically for GFS2, and are not -interpreted by the mount command nor by the kernel's Virtual File System. GFS2 -and non-GFS2 options may be intermingled after the \fB-o\fP, separated by -commas (but no spaces). - -The options commit, discard, errors, quota_quantum, statfs_quantum, statfs_percent, barrier, acl, quota, suiddir, and data can be -changed after mount using the "mount -o remount,option /mountpoint" command. -The options quota, discard, barrier, acl, and suiddir support the "no" -prefix. For example, "noacl" turns off what "acl" turns on. - -If you have trouble mounting GFS2, check the syslog (e.g. /var/log/messages) -for specific error messages. - -.SH OPTIONS -.TP -\fBlockproto=\fP\fILockProtoName\fR -This specifies which inter-node lock protocol is used by the GFS2 filesystem -for this mount, overriding the default lock protocol name stored in the -filesystem's on-disk superblock. - -The \fILockProtoName\fR must be one of the supported locking protocols, -currently these are \fIlock_nolock\fR and \fIlock_dlm\fR. - -The default lock protocol name is written to disk initially when creating the -filesystem with \fBmkfs.gfs2\fP(8), -p option. It can be changed on-disk by -using the \fBgfs2_tool\fP(8) utility's \fBsb proto\fP command. - -The \fBlockproto\fP mount option should be used only under special -circumstances in which you want to temporarily use a different lock protocol -without changing the on-disk default. Using the incorrect lock protocol -on a cluster filesystem mounted from more than one node will almost -certainly result in filesystem corruption. -.TP -\fBlocktable=\fP\fILockTableName\fR -This specifies the identity of the cluster and of the filesystem for this -mount, overriding the default cluster/filesystem identify stored in the -filesystem's on-disk superblock. The cluster/filesystem name is recognized -globally throughout the cluster, and establishes a unique namespace for -the inter-node locking system, enabling the mounting of multiple GFS2 -filesystems. - -The format of \fILockTableName\fR is lock-module-specific. For -\fIlock_dlm\fR, the format is \fIclustername:fsname\fR. For -\fIlock_nolock\fR, the field is ignored. - -The default cluster/filesystem name is written to disk initially when creating -the filesystem with \fBmkfs.gfs2\fP(8), -t option. It can be changed on-disk -by using the \fBgfs2_tool\fP(8) utility's \fBsb table\fP command. - -The \fBlocktable\fP mount option should be used only under special -circumstances in which you want to mount the filesystem in a different cluster, -or mount it as a different filesystem name, without changing the on-disk -default. -.TP -\fBlocalcaching\fP -This flag tells GFS2 that it is running as a local (not clustered) filesystem, -so it can turn on some block caching optimizations that can't be used when -running in cluster mode. - -This is turned on automatically by the lock_nolock module, -but can be overridden by using the \fBignore_local_fs\fP option. -.TP -\fBlocalflocks\fP -This flag tells GFS2 that it is running as a local (not clustered) filesystem, -so it can allow the kernel VFS layer to do all flock and fcntl file locking. -When running in cluster mode, these file locks require inter-node locks, -and require the support of GFS2. When running locally, better performance -is achieved by letting VFS handle the whole job. - -This is turned on automatically by the lock_nolock module, -but can be overridden by using the \fBignore_local_fs\fP option. -.TP -\fBerrors=\fP\fI[panic|withdraw]\fR -Setting errors=panic causes GFS2 to oops when encountering an error that -would otherwise cause the -mount to withdraw or print an assertion warning. The default setting -is errors=withdraw. This option should not be used in a production system. -It replaces the earlier \fBdebug\fP option on kernel versions 2.6.31 and -above. -.TP -\fBignore_local_fs\fP -By default, using the nolock lock module automatically turns on the -\fBlocalcaching\fP and \fBlocalflocks\fP optimizations. \fBignore_local_fs\fP -forces GFS2 to treat the filesystem as if it were a multihost (clustered) -filesystem, with \fBlocalcaching\fP and \fBlocalflocks\fP optimizations -turned off. -.TP -\fBupgrade\fP -This flag tells GFS2 to upgrade the filesystem's on-disk format to the version -supported by the current GFS2 software installation on this computer. -If you try to mount an old-version disk image, GFS2 will notify you via a syslog -message that you need to upgrade. Try mounting again, using the -\fB-o upgrade\fP option. When upgrading, only one node may mount the GFS2 -filesystem. -.TP -\fBacl\fP -Enables POSIX Access Control List \fBacl\fP(5) support within GFS2. -.TP -\fBspectator\fP -Mount this filesystem using a special form of read-only mount. The mount -does not use one of the filesystem's journals. The node is unable to -recover journals for other nodes. -.TP -\fBsuiddir\fP -Sets owner of any newly created file or directory to be that of parent -directory, if parent directory has S_ISUID permission attribute bit set. -Sets S_ISUID in any new directory, if its parent directory's S_ISUID is set. -Strips all execution bits on a new file, if parent directory owner is different -from owner of process creating the file. Set this option only if you know -why you are setting it. -.TP -\fBquota=\fP\fI[off/account/on]\fR -Turns quotas on or off for a filesystem. Setting the quotas to be in -the "account" state causes the per UID/GID usage statistics to be -correctly maintained by the filesystem, limit and warn values are -ignored. The default value is "off". -.TP -\fBdiscard\fP -Causes GFS2 to generate "discard" I/O requests for blocks which have -been freed. These can be used by suitable hardware to implement -thin-provisioning and similar schemes. This feature is supported -in kernel version 2.6.30 and above. -.TP -\fBbarrier\fP -This option, which defaults to on, causes GFS2 to send I/O barriers -when flushing the journal. The option is automatically turned off -if the underlying device does not support I/O barriers. We highly -recommend the use of I/O barriers with GFS2 at all times unless -the block device is designed so that it cannot lose its write cache -content (e.g. its on a UPS, or it doesn't have a write cache) -.TP -\fBcommit=\fP\fIsecs\fR -This is similar to the ext3 \fBcommit=\fP option in that it sets -the maximum number of seconds between journal commits if there is -dirty data in the journal. The default is 60 seconds. This option -is only provided in kernel versions 2.6.31 and above. -.TP -\fBdata=\fP\fI[ordered|writeback]\fR -When data=ordered is set, the user data modified by a transaction is -flushed to the disk before the transaction is committed to disk. This -should prevent the user from seeing uninitialized blocks in a file -after a crash. Data=writeback mode writes the user data to the disk -at any time after it's dirtied. This doesn't provide the same -consistency guarantee as ordered mode, but it should be slightly -faster for some workloads. The default is ordered mode. -.TP -\fBmeta\fP -This option results in selecting the meta filesystem root rather than -the normal filesystem root. This option is normally only used by -the GFS2 utility functions. Altering any file on the GFS2 meta filesystem -may render the filesystem unusable, so only experts in the GFS2 -on-disk layout should use this option. -.TP -\fBquota_quantum=\fP\fIsecs\fR -This sets the number of seconds for which a change in the quota -information may sit on one node before being written to the quota -file. This is the preferred way to set this parameter. The value -is an integer number of seconds greater than zero. The default is -60 seconds. Shorter settings result in faster updates of the lazy -quota information and less likelihood of someone exceeding their -quota. Longer settings make filesystem operations involving quotas -faster and more efficient. -.TP -\fBstatfs_quantum=\fP\fIsecs\fR -Setting statfs_quantum to 0 is the preferred way to set the slow version -of statfs. The default value is 30 secs which sets the maximum time -period before statfs changes will be syned to the master statfs file. -This can be adjusted to allow for faster, less accurate statfs values -or slower more accurate values. When set to 0, statfs will always -report the true values. -.TP -\fBstatfs_percent=\fP\fIvalue\fR -This setting provides a bound on the maximum percentage change in -the statfs information on a local basis before it is synced back -to the master statfs file, even if the time period has not -expired. If the setting of statfs_quantum is 0, then this setting -is ignored. - -.SH BUGS - -GFS2 doesn't support \fBerrors=\fP\fIremount-ro\fR or \fBdata=\fP\fIjournal\fR. -It is not possible to switch support for user and group quotas on and -off independently of each other. Some of the error messages are rather -cryptic, if you encounter one of these messages check firstly that gfs_controld -is running and secondly that you have enough journals on the filesystem -for the number of nodes in use. - -.SH SEE ALSO - -\fBgfs2\fP(5), -\fBmount\fP(8) for general mount options, -\fBchmod\fP(1) and \fBchmod\fP(2) for access permission flags, -\fBacl\fP(5) for access control lists, -\fBlvm\fP(8) for volume management, -\fBccs\fP(7) for cluster management, -\fBumount\fP(8), -\fBinitrd\fP(4). - diff --git a/gfs2/quota/Makefile.am b/gfs2/quota/Makefile.am deleted file mode 100644 index 9d75d20..0000000 --- a/gfs2/quota/Makefile.am +++ /dev/null @@ -1,14 +0,0 @@ -MAINTAINERCLEANFILES = Makefile.in - -sbin_PROGRAMS = gfs2_quota - -noinst_HEADERS = gfs2_quota.h - -gfs2_quota_SOURCES = check.c main.c names.c - -gfs2_quota_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE \ - -DHELPER_PROGRAM \ - -I$(top_srcdir)/gfs2/include \ - -I$(top_srcdir)/gfs2/libgfs2 - -gfs2_quota_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la diff --git a/gfs2/quota/check.c b/gfs2/quota/check.c deleted file mode 100644 index 9afb0ad..0000000 --- a/gfs2/quota/check.c +++ /dev/null @@ -1,601 +0,0 @@ -#include "clusterautoconfig.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define __user -#include "osi_list.h" - -#include "gfs2_quota.h" - -#define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap) - -struct values { - osi_list_t v_list; - - uint32_t v_id; - int64_t v_blocks; -}; -typedef struct values values_t; - -struct hardlinks { - osi_list_t hl_list; - - ino_t hl_ino; -}; -typedef struct hardlinks hardlinks_t; - -/** - * add_value - add a ID / Allocated Blocks pair to the list - * @list: the list - * @id: the ID number - * @blocks: the number of blocks to add - * - */ - -static void -add_value(osi_list_t *list, uint32_t id, int64_t blocks) -{ - osi_list_t *tmp; - values_t *v; - - for (tmp = list->next; tmp != list; tmp = tmp->next) { - v = osi_list_entry(tmp, values_t, v_list); - if (v->v_id != id) - continue; - - v->v_blocks += blocks; - - osi_list_del(&v->v_list); - osi_list_add(&v->v_list, list); - - return; - } - - type_zalloc(v, values_t, 1); - - v->v_id = id; - v->v_blocks = blocks; - - osi_list_add(&v->v_list, list); -} - -/** - * test_and_add_hard_link - Add a inode that has hard links to the list - * @list: the list of inodes with hard links - * @ino: the number of the inode to add - * - * Returns: Returns TRUE if the inode was already on the list, FALSE if it wasn't - */ - -static int -test_and_add_hard_link(osi_list_t *list, ino_t ino) -{ - osi_list_t *tmp; - hardlinks_t *hl; - - for (tmp = list->next; tmp != list; tmp = tmp->next) { - hl = osi_list_entry(tmp, hardlinks_t, hl_list); - if (hl->hl_ino != ino) - continue; - - return TRUE; - } - - type_zalloc(hl, hardlinks_t, 1); - - hl->hl_ino = ino; - - osi_list_add(&hl->hl_list, list); - - return FALSE; -} - -/** - * scan_fs - recursively scan a filesystem and figure out what IDs have what - * @device: the device the filesystem is on - * @dirname: the name of the directory to read - * @uid: returned list of UIDs for this FS - * @gid: returned list of GIDs for this FS - * @hl: returned list of hard links for this FS - * - */ - -static void -scan_fs(dev_t device, char *dirname, - osi_list_t *uid, osi_list_t *gid, osi_list_t *hl) -{ - DIR *dir; - struct dirent *de; - struct stat st; - char *name; - int error; - - dir = opendir(dirname); - if (!dir) - die("can't open directory %s: %s\n", dirname, strerror(errno)); - - while ((de = readdir(dir))) { - if (strcmp(de->d_name, "..") == 0) - continue; - - type_alloc(name, char, - strlen(dirname) + strlen(de->d_name) + 2); - if (dirname[strlen(dirname) - 1] == '/') - sprintf(name, "%s%s", dirname, de->d_name); - else - sprintf(name, "%s/%s", dirname, de->d_name); - - error = lstat(name, &st); - if (error) - die("can't stat file %s: %s\n", name, strerror(errno)); - - if (st.st_dev != device) - die("umount %s and try again\n", name); - - if (S_ISDIR(st.st_mode)) { - if (strcmp(de->d_name, ".") == 0) { - add_value(uid, st.st_uid, st.st_blocks); - add_value(gid, st.st_gid, st.st_blocks); - } else - scan_fs(device, name, uid, gid, hl); - } else if (st.st_nlink == 1 || - !test_and_add_hard_link(hl, st.st_ino)) { - add_value(uid, st.st_uid, st.st_blocks); - add_value(gid, st.st_gid, st.st_blocks); - } - - free(name); - } - - closedir(dir); -} - -/** - * read_quota_file - read the quota file and return list of its contents - * @comline: the command line arguments - * @uid: returned list of UIDs for the filesystem - * @gid: returned list of GIDs for the filesystem - * - */ -static void -read_quota_file(struct gfs2_sbd *sdp, commandline_t *comline, - osi_list_t *uid, osi_list_t *gid) -{ - int fd; - uint32_t id, startq; - int error = 0; - char quota_file[BUF_SIZE]; - uint64_t quota_file_size = 0; - struct fiemap fmap = { 0, }, *fmap2; - struct stat statbuf; - - strcpy(sdp->path_name, comline->filesystem); - if (check_for_gfs2(sdp)) { - if (errno == EINVAL) - fprintf(stderr, "Not a valid GFS2 mount point: %s\n", - sdp->path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - read_superblock(&sdp->sd_sb, sdp); - if (mount_gfs2_meta(sdp)) { - fprintf(stderr, "Error mounting GFS2 metafs: %s\n", - strerror(errno)); - exit(-1); - } - - strcpy(quota_file, sdp->metafs_path); - strcat(quota_file, "/quota"); - - fd = open(quota_file, O_RDONLY); - if (fd < 0) { - close(sdp->metafs_fd); - cleanup_metafs(sdp); - die("can't open file %s: %s\n", comline->filesystem, - strerror(errno)); - } - if (fstat(fd, &statbuf) < 0) { - close(fd); - close(sdp->metafs_fd); - cleanup_metafs(sdp); - die("can't stat file %s: %s\n", quota_file, - strerror(errno)); - } - quota_file_size = statbuf.st_size; - /* First find the number of extents in the quota file */ - fmap.fm_flags = 0; - fmap.fm_start = 0; - fmap.fm_length = (~0ULL); - error = ioctl(fd, FS_IOC_FIEMAP, &fmap); - if (error == -1) { - fprintf(stderr, "fiemap error (%d): %s\n", errno, strerror(errno)); - goto out; - } - fmap2 = malloc(sizeof(struct fiemap) + - fmap.fm_mapped_extents * sizeof(struct fiemap_extent)); - if (fmap2 == NULL) { - fprintf(stderr, "malloc error (%d): %s\n", errno, strerror(errno)); - goto out; - } - fmap2->fm_flags = 0; - fmap2->fm_start = 0; - fmap2->fm_length = (~0ULL); - fmap2->fm_extent_count = fmap.fm_mapped_extents; - error = ioctl(fd, FS_IOC_FIEMAP, fmap2); - if (error == -1) { - fprintf(stderr, "fiemap error (%d): %s\n", errno, strerror(errno)); - goto fmap2_free; - } - if (fmap2->fm_mapped_extents) { - int i; - for (i=0; ifm_mapped_extents; i++) { - struct fiemap_extent *fe = &fmap2->fm_extents[i]; - uint64_t end = fe->fe_logical + fe->fe_length, val_off; - unsigned int v_off; - - end = end > quota_file_size ? quota_file_size : end; - /* we only need to get the value fields, not the whole quota - * This also works when struct gfs2_quota straddle page - * boundaries. Getting only the value field avoids the - * complexity of fetching two parts of the struct gfs2_quota - * from two successive pages - */ - /* offset of the value field within struct gfs2_quota */ - v_off = (unsigned long)(&((struct gfs2_quota *)NULL)->qu_value); - /* startq could be at the end of previous extent... */ - startq = fe->fe_logical / sizeof(struct gfs2_quota); - /* but the value field could be in this extent */ - if ((startq * sizeof(struct gfs2_quota) + v_off) >= fe->fe_logical) - val_off = startq * sizeof(struct gfs2_quota) + v_off; - else /* if the start of the extent doesn't have a split quota */ - val_off = ++startq * sizeof(struct gfs2_quota) + v_off; - - while ((val_off + sizeof(uint64_t)) <= end) - { - uint64_t value; - /* read hidden quota file here */ - lseek(fd, val_off, SEEK_SET); - error = read(fd, (unsigned char*)&value, sizeof(uint64_t)); - if (error < 0) { - fprintf(stderr, "read error (%d): %s\n", - errno, strerror(errno)); - goto fmap2_free; - } - value = be64_to_cpu(value); - id = startq >> 1; - /* We want value in 512 byte blocks (1 << 9 = 512) */ - value <<= sdp->sd_sb.sb_bsize_shift - 9; - if (value) { - /* if startq is even, it's a uid, else gid */ - if (startq % 2) - add_value(gid, id, value); - else - add_value(uid, id, value); - } - startq++; - val_off += sizeof(struct gfs2_quota); - } - } - } -fmap2_free: - free(fmap2); -out: - close(fd); - close(sdp->metafs_fd); - cleanup_metafs(sdp); -} - -/** - * do_compare - compare to ID lists and see if they match - * @type: the type of list (UID or GID) - * @fs_list: the list derived from scaning the FS - * @qf_list: the list derived from reading the quota file - * - * Returns: TRUE if there was a mismatch - */ - -static int -do_compare(const char *type, osi_list_t *fs_list, osi_list_t *qf_list) -{ - osi_list_t *tmp1, *tmp2; - values_t *v1, *v2; - int found; - int mismatch = FALSE; - - for (tmp1 = fs_list->next; tmp1 != fs_list; tmp1 = tmp1->next) { - v1 = osi_list_entry(tmp1, values_t, v_list); - - found = FALSE; - - for (tmp2 = qf_list->next; tmp2 != qf_list; tmp2 = tmp2->next) { - v2 = osi_list_entry(tmp2, values_t, v_list); - if (v1->v_id != v2->v_id) - continue; - - if (v1->v_blocks != v2->v_blocks) { - printf("mismatch: %s %u: scan = %lld, quotafile = %lld\n", - type, v1->v_id, - (long long)v1->v_blocks, (long long)v2->v_blocks); - mismatch = TRUE; - } - - osi_list_del(&v2->v_list); - free(v2); - - found = TRUE; - break; - } - - if (!found) { - printf("mismatch: %s %u: scan = %lld, quotafile = %lld\n", - type, v1->v_id, - (long long)v1->v_blocks, 0LL); - mismatch = TRUE; - } - } - - for (tmp2 = qf_list->next; tmp2 != qf_list; tmp2 = tmp2->next) { - v2 = osi_list_entry(tmp2, values_t, v_list); - - printf("mismatch: %s %u: scan = %lld, quotafile = %lld\n", - type, v2->v_id, - 0LL, (long long)v2->v_blocks); - mismatch = TRUE; - } - - return mismatch; -} - -/** - * verify_pathname - make sure the path on the command line is a mount point - * @comline: the command line arguments - * - * Returns: the device the filesystem is on - */ - -static dev_t -verify_pathname(commandline_t *comline) -{ - struct stat st1, st2; - dev_t device; - char *name; - int error; - - if (!*comline->filesystem) - die("need a filesystem to work on\n"); - - error = lstat(comline->filesystem, &st1); - if (error) - die("can't stat %s: %s\n", comline->filesystem, - strerror(errno)); - - if (!S_ISDIR(st1.st_mode)) - die("%s must be a directory\n", comline->filesystem); - - device = st1.st_dev; - - for (;;) { - type_alloc(name, char, strlen(comline->filesystem) + 4); - sprintf(name, "%s/..", comline->filesystem); - - error = lstat(name, &st2); - if (error) - die("can't stat %s: %s\n", name, strerror(errno)); - - if (st2.st_dev != device || st2.st_ino == st1.st_ino) { - free(name); - break; - } - - if (!realpath(name, comline->filesystem)) - die("error resolving filesystem pathname: %s\n", - strerror(errno)); - - free(name); - - st1 = st2; - } - - return device; -} - -/** - * do_check - Check what's in the quota file - * @comline: the struct containing the parsed command line arguments - * - */ - -void -do_check(struct gfs2_sbd *sdp, commandline_t *comline) -{ - dev_t device; - osi_list_t fs_uid, fs_gid, qf_uid, qf_gid; - osi_list_t hl; - int mismatch; - - osi_list_init(&fs_uid); - osi_list_init(&fs_gid); - osi_list_init(&qf_uid); - osi_list_init(&qf_gid); - osi_list_init(&hl); - - device = verify_pathname(comline); - - scan_fs(device, comline->filesystem, &fs_uid, &fs_gid, &hl); - read_quota_file(sdp, comline, &qf_uid, &qf_gid); - - mismatch = do_compare("user", &fs_uid, &qf_uid); - mismatch |= do_compare("group", &fs_gid, &qf_gid); - - if (mismatch) - exit(EXIT_FAILURE); -} - -/** - * set_list - write a list of IDs into the quota file - * @comline: the command line arguments - * @user: TRUE if this is a list of UIDs, FALSE if it is a list of GIDs - * @list: the list of IDs and block counts - * @multiplier: multiply block counts by this - * - */ - -static void -set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user, - osi_list_t *list, int64_t multiplier) -{ - int fd; - osi_list_t *tmp; - values_t *v; - uint64_t offset, max_off = 0; - int64_t value; - int error; - char quota_file[BUF_SIZE]; - char id_str[16]; - char *fs; - struct stat st; - - strcpy(sdp->path_name, comline->filesystem); - if (check_for_gfs2(sdp)) { - if (errno == EINVAL) - fprintf(stderr, "Not a valid GFS2 mount point: %s\n", - sdp->path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - read_superblock(&sdp->sd_sb, sdp); - if (mount_gfs2_meta(sdp)) { - fprintf(stderr, "Error mounting GFS2 metafs: %s\n", - strerror(errno)); - exit(-1); - } - - strcpy(quota_file, sdp->metafs_path); - strcat(quota_file, "/quota"); - - fd = open(quota_file, O_WRONLY); - if (fd < 0) { - close(sdp->metafs_fd); - cleanup_metafs(sdp); - die("can't open file %s: %s\n", comline->filesystem, - strerror(errno)); - } - - for (tmp = list->next; tmp != list; tmp = tmp->next) { - v = osi_list_entry(tmp, values_t, v_list); - - offset = (2 * (uint64_t)v->v_id + ((user) ? 0 : 1)) * - sizeof(struct gfs2_quota); - if (offset > max_off) - max_off = offset; - offset += (unsigned long)(&((struct gfs2_quota *)NULL)->qu_value); - - value = v->v_blocks * multiplier; - value >>= sdp->sd_sb.sb_bsize_shift - 9; - value = cpu_to_be64(value); - - lseek(fd, offset, SEEK_SET); - error = write(fd, (char*)&value, sizeof(uint64_t)); - if (error != sizeof(uint64_t)) { - fprintf(stderr, "can't write quota file (%d): %s\n", - error, strerror(errno)); - goto out; - } - - fs = mp2fsname(comline->filesystem); - if (!fs) { - fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n", - comline->filesystem); - exit(-1); - } - - /* Write the id to sysfs quota refresh file to refresh gfs quotas */ - sprintf(id_str, "%d", comline->id); - if (set_sysfs(fs, (user) ? "quota_refresh_user" : "quota_refresh_group", - id_str)) { - fprintf(stderr, "Error writing id to sysfs quota refresh file: %s\n", - strerror(errno)); - exit(-1); - } - } - /* If we wrote a value that extended the quota file size, - * round the size off to the nearest quota boundary - */ - error = fstat(fd, &st); - if (error) { - fprintf(stderr, "can't stat quota file (%d): %s\n", - error, strerror(errno)); - goto out; - } - if (st.st_size < (max_off + sizeof(struct gfs2_quota))) { - error = ftruncate(fd, (max_off + sizeof(struct gfs2_quota))); - if (error) - fprintf(stderr, "can't truncate quota file(%d): %s\n", - error, strerror(errno)); - } -out: - close(fd); - close(sdp->metafs_fd); - cleanup_metafs(sdp); -} - -/** - * do_quota_init - initialize the quota file - * @comline: the command line arguments - * - */ - -void -do_quota_init(struct gfs2_sbd *sdp, commandline_t *comline) -{ - dev_t device; - osi_list_t fs_uid, fs_gid, qf_uid, qf_gid; - osi_list_t hl; - values_t *v; - - osi_list_init(&fs_uid); - osi_list_init(&fs_gid); - osi_list_init(&qf_uid); - osi_list_init(&qf_gid); - osi_list_init(&hl); - - device = verify_pathname(comline); - - scan_fs(device, comline->filesystem, &fs_uid, &fs_gid, &hl); - read_quota_file(sdp, comline, &qf_uid, &qf_gid); - - type_zalloc(v, values_t, 1); - v->v_id = 0; - v->v_blocks = 0; - osi_list_add(&v->v_list, &qf_uid); - - type_zalloc(v, values_t, 1); - v->v_id = 0; - v->v_blocks = 0; - osi_list_add(&v->v_list, &qf_gid); - - set_list(sdp, comline, TRUE, &qf_uid, 0); - set_list(sdp, comline, FALSE, &qf_gid, 0); - set_list(sdp, comline, TRUE, &fs_uid, 1); - set_list(sdp, comline, FALSE, &fs_gid, 1); - - do_sync(sdp, comline); - do_check(sdp, comline); -} diff --git a/gfs2/quota/gfs2_quota.h b/gfs2/quota/gfs2_quota.h deleted file mode 100644 index 744f02b..0000000 --- a/gfs2/quota/gfs2_quota.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef __GFS2_QUOTA_DOT_H__ -#define __GFS2_QUOTA_DOT_H__ - -#include -#include "libgfs2.h" -#include - -#define DIV_RU(x, y) (((x) + (y) - 1) / (y)) - -#define type_zalloc(ptr, type, count) \ -do { \ - (ptr) = (type *)malloc(sizeof(type) * (count)); \ - if ((ptr)) \ - memset((char *)(ptr), 0, sizeof(type) * (count)); \ - else \ - die("unable to allocate memory on line %d of file %s\n", \ - __LINE__, __FILE__); \ -} while (0) - -#define type_alloc(ptr, type, count) \ -do { \ - (ptr) = (type *)malloc(sizeof(type) * (count)); \ - if (!(ptr)) \ - die("unable to allocate memory on line %d of file %s\n", \ - __LINE__, __FILE__); \ -} while (0) - -#define GQ_OP_LIST (12) -#define GQ_OP_SYNC (13) -#define GQ_OP_GET (14) -#define GQ_OP_LIMIT (15) -#define GQ_OP_WARN (16) -#define GQ_OP_CHECK (17) -#define GQ_OP_INIT (18) -#define GQ_OP_RESET (19) - -#define GQ_ID_USER (23) -#define GQ_ID_GROUP (24) - -#define GQ_UNITS_MEGABYTE (0) -#define GQ_UNITS_KILOBYTE (34) -#define GQ_UNITS_FSBLOCK (35) -#define GQ_UNITS_BASICBLOCK (36) - -#define BUF_SIZE 4096 - -struct commandline { - unsigned int operation; - - uint64_t new_value; - int new_value_set; - - unsigned int id_type; - uint32_t id; - - unsigned int units; - - int numbers; - - char filesystem[PATH_MAX]; -}; -typedef struct commandline commandline_t; - -/* main.c */ - -void do_get_super(int fd, struct gfs2_sb *sb); -void do_sync(struct gfs2_sbd *sdp, commandline_t *comline); -void cleanup(void); -void read_superblock(struct gfs2_sb *sb, struct gfs2_sbd *sdp); -void read_quota_internal(int fd, unsigned int id, int id_type, - struct gfs2_quota *q); - -/* check.c */ - -void do_check(struct gfs2_sbd *sdp, commandline_t *comline); -void do_quota_init(struct gfs2_sbd *sdp, commandline_t *comline); - -/* names.c */ - -uint32_t name_to_id(int user, char *name, int numbers); -char *id_to_name(int user, uint32_t id, int numbers); - -/* die() used to be in libgfs2.h */ -static __inline__ __attribute__((noreturn, format (printf, 1, 2))) -void die(const char *fmt, ...) -{ - va_list ap; - fprintf(stderr, "%s: ", __FILE__); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - exit(-1); -} - -#endif /* __GFS2_QUOTA_DOT_H__ */ diff --git a/gfs2/quota/main.c b/gfs2/quota/main.c deleted file mode 100644 index 733f69d..0000000 --- a/gfs2/quota/main.c +++ /dev/null @@ -1,911 +0,0 @@ -#include "clusterautoconfig.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include "gfs2_quota.h" - -#define __user - -#include "copyright.cf" - - -/* Constants */ - -#define OPTION_STRING ("bdf:g:hkl:mnsu:V") -#define FS_IOC_FIEMAP _IOWR('f', 11, struct fiemap) - -/** - * This function is for libgfs2's sake. - */ -void print_it(const char *label, const char *fmt, const char *fmt2, ...) -{ - va_list args; - - va_start(args, fmt2); - printf("%s: ", label); - vprintf(fmt, args); - va_end(args); -} - -/** - * print_usage - print usage info to the user - * @prog_name: The name of this program - */ - -static void -print_usage(const char *prog_name) -{ - printf("Usage:\n"); - printf("\n"); - printf("%s [options]\n", - prog_name); - printf("\n"); - printf("Actions:\n"); - printf(" list list the whole quota file\n"); - printf(" sync sync out unsynced quotas\n"); - printf(" get get quota values for an ID\n"); - printf(" limit set a quota limit value for an ID\n"); - printf(" warn set a quota warning value for an ID\n"); - printf(" check check the quota file\n"); - printf(" init initialize the quota file\n"); - printf(" reset reset the quota file\n"); - printf("\n"); - printf("Options:\n"); - printf(" -b sizes are in FS blocks\n"); - printf(" -f the filesystem to work on\n"); - printf(" -g get/set a group ID\n"); - printf(" -h Print this help, then exit\n"); - printf(" -k sizes are in KB\n"); - printf(" -l the new limit or warn value\n"); - printf(" -m sizes are in MB\n"); - printf(" -n print out UID/GID numbers instead of names\n"); - printf(" -s sizes are in 512-byte blocks\n"); - printf(" -u get/set a user ID\n"); - printf(" -V Print program version information, then exit\n"); -} - -/** - * decode_arguments - parse command line arguments - * @argc: well, it's argc... - * @argv: well, it's argv... - * @comline: the structure filled in with the parsed arguments - * - * Function description - * - * Returns: what is returned - */ - -static void -decode_arguments(int argc, char *argv[], commandline_t *comline) -{ - int cont = TRUE; - int optchar; - - while (cont) { - optchar = getopt(argc, argv, OPTION_STRING); - - switch (optchar) { - case 'u': - comline->id_type = GQ_ID_USER; - comline->id = name_to_id(TRUE, optarg, comline->numbers); - break; - - case 'g': - comline->id_type = GQ_ID_GROUP; - comline->id = name_to_id(FALSE, optarg, comline->numbers); - break; - - case 'l': - if (!isdigit(*optarg)) - die("argument to -l must be a number\n"); - sscanf(optarg, "%"SCNu64, &comline->new_value); - comline->new_value_set = TRUE; - break; - - case 'f': - if (!realpath(optarg, comline->filesystem)) - die("can't find %s: %s\n", optarg, - strerror(errno)); - break; - - case 'm': - comline->units = GQ_UNITS_MEGABYTE; - break; - - case 'k': - comline->units = GQ_UNITS_KILOBYTE; - break; - - case 'b': - comline->units = GQ_UNITS_FSBLOCK; - break; - - case 's': - comline->units = GQ_UNITS_BASICBLOCK; - break; - - case 'n': - comline->numbers = TRUE; - break; - - case 'V': - printf("gfs2_quota %s (built %s %s)\n", VERSION, - __DATE__, __TIME__); - printf("%s\n", REDHAT_COPYRIGHT); - exit(EXIT_SUCCESS); - break; - - case 'h': - print_usage(argv[0]); - exit(EXIT_SUCCESS); - break; - - case ':': - case '?': - fprintf(stderr, "Please use '-h' for usage.\n"); - exit(EXIT_FAILURE); - break; - - case EOF: - cont = FALSE; - break; - - default: - die("unknown option: %c\n", optchar); - break; - }; - } - - while (optind < argc) { - if (strcmp(argv[optind], "list") == 0 || - strcmp(argv[optind], "dump") == 0) { - if (comline->operation) - die("can't specify two operations\n"); - comline->operation = GQ_OP_LIST; - } else if (strcmp(argv[optind], "sync") == 0) { - if (comline->operation) - die("can't specify two operations\n"); - comline->operation = GQ_OP_SYNC; - } else if (strcmp(argv[optind], "get") == 0) { - if (comline->operation) - die("can't specify two operations\n"); - comline->operation = GQ_OP_GET; - } else if (strcmp(argv[optind], "limit") == 0) { - if (comline->operation) - die("can't specify two operations\n"); - comline->operation = GQ_OP_LIMIT; - } else if (strcmp(argv[optind], "warn") == 0) { - if (comline->operation) - die("can't specify two operations\n"); - comline->operation = GQ_OP_WARN; - } else if (strcmp(argv[optind], "check") == 0) { - if (comline->operation) - die("can't specify two operations\n"); - comline->operation = GQ_OP_CHECK; - } else if (strcmp(argv[optind], "init") == 0) { - if (comline->operation) - die("can't specify two operations\n"); - comline->operation = GQ_OP_INIT; - } else if (strcmp(argv[optind], "reset") == 0) { - if (comline->operation) - die("can't specify two operations\n"); - comline->operation = GQ_OP_RESET; - } else - die("unknown option %s\n", argv[optind]); - - optind++; - } -} - -/** - * print_quota - Print out a quota entry - * @comline: the struct containing the parsed command line arguments - * @user: TRUE if this is a user quota, FALSE if it's a group quota - * @id: the ID - * @q: the quota value - * @sb: the superblock of the filesystem this quota belongs to - * - */ - -static void -print_quota(commandline_t *comline, - int user, uint32_t id, - struct gfs2_quota *q, - struct gfs2_sb *sb) -{ - printf("%-5s %10s: ", (user) ? "user" : "group", - id_to_name(user, id, comline->numbers)); - - switch (comline->units) { - case GQ_UNITS_MEGABYTE: - printf("limit: %-10.1f warn: %-10.1f value: %-10.1f\n", - (double) q->qu_limit * sb->sb_bsize / 1048576, - (double) q->qu_warn * sb->sb_bsize / 1048576, - (double) q->qu_value * sb->sb_bsize / 1048576); - break; - - case GQ_UNITS_KILOBYTE: - if (sb->sb_bsize == 512) - printf("limit: %-10llu warn: %-10lluvalue: %-10llu\n", - (unsigned long long)q->qu_limit / 2, - (unsigned long long)q->qu_warn / 2, - (unsigned long long)q->qu_value / 2); - else - printf("limit: %-10llu warn: %-10lluvalue: %-10llu\n", - (unsigned long long) - q->qu_limit << (sb->sb_bsize_shift - 10), - (unsigned long long) - q->qu_warn << (sb->sb_bsize_shift - 10), - (unsigned long long) - q->qu_value << (sb->sb_bsize_shift - 10)); - break; - - case GQ_UNITS_FSBLOCK: - printf("limit: %-10llu warn: %-10llu value: %-10llu\n", - (unsigned long long)q->qu_limit, - (unsigned long long)q->qu_warn, - (unsigned long long)q->qu_value); - break; - - case GQ_UNITS_BASICBLOCK: - printf("limit: %-10llu warn: %-10llu value: %-10llu\n", - (unsigned long long) - q->qu_limit << (sb->sb_bsize_shift - 9), - (unsigned long long) - q->qu_warn << (sb->sb_bsize_shift - 9), - (unsigned long long) - q->qu_value << (sb->sb_bsize_shift - 9)); - break; - - default: - die("bad units\n"); - break; - } -} - -void -read_superblock(struct gfs2_sb *sb, struct gfs2_sbd *sdp) -{ - int fd; - char buf[PATH_MAX]; - struct gfs2_buffer_head dummy_bh; - - dummy_bh.b_data = buf; - fd = open(sdp->device_name, O_RDONLY); - if (fd < 0) { - die("Could not open the block device %s: %s\n", - sdp->device_name, strerror(errno)); - } - if (lseek(fd, 0x10 * 4096, SEEK_SET) != 0x10 * 4096) { - fprintf(stderr, "bad seek: %s from %s:%d: " - "superblock\n", - strerror(errno), __FUNCTION__, __LINE__); - - exit(-1); - } - if (read(fd, buf, PATH_MAX) != PATH_MAX) { - fprintf(stderr, "bad read: %s from %s:%d: superblock\n", - strerror(errno), __FUNCTION__, __LINE__); - exit(-1); - } - gfs2_sb_in(sb, &dummy_bh); - - close(fd); -} - -void -read_quota_internal(int fd, uint32_t id, int id_type, struct gfs2_quota *q) -{ - /* seek to the appropriate offset in the quota file and read the - quota info */ - uint64_t offset; - char buf[256]; - int error; - if (id_type == GQ_ID_USER) - offset = (2 * (uint64_t)id) * sizeof(struct gfs2_quota); - else - offset = (2 * (uint64_t)id + 1) * sizeof(struct gfs2_quota); - lseek(fd, offset, SEEK_SET); - error = read(fd, buf, sizeof(struct gfs2_quota)); - if (error < 0) - die("failed to read from quota file: %s\n", strerror(errno)); - if (error != sizeof(struct gfs2_quota)) - die("Couldn't read %lu bytes from quota file@offset %llu\n", - (unsigned long)sizeof(struct gfs2_quota), - (unsigned long long)offset); - gfs2_quota_in(q, buf); -} - -static inline void -write_quota_internal(int fd, uint32_t id, int id_type, struct gfs2_quota *q) -{ - /* seek to the appropriate offset in the quota file and write the - quota info */ - uint64_t offset; - char buf[256]; - int error; - if (id_type == GQ_ID_USER) - offset = (2 * (uint64_t)id) * sizeof(struct gfs2_quota); - else - offset = (2 * (uint64_t)id + 1) * sizeof(struct gfs2_quota); - lseek(fd, offset, SEEK_SET); - gfs2_quota_out(q, buf); - error = write(fd, buf, sizeof(struct gfs2_quota)); - if (error != sizeof(struct gfs2_quota)) - die("failed to write to quota file: %s\n", strerror(errno)); -} - -/** - * do_reset - Reset all the quota data for a filesystem - * @comline: the struct containing the parsed command line arguments - */ - -static void -do_reset(struct gfs2_sbd *sdp, commandline_t *comline) -{ - int fd; - char quota_file[BUF_SIZE], c; - struct gfs2_quota q; - - if (!*comline->filesystem) - die("need a filesystem to work on\n"); - - printf("This operation will permanently erase all quota information.\n" - "You will have to re-assign all quota limit/warn values.\n" - "Proceed [y/N]? "); - c = getchar(); - if (c != 'y' && c != 'Y') - return; - - strcpy(sdp->path_name, comline->filesystem); - if (check_for_gfs2(sdp)) { - if (errno == EINVAL) - fprintf(stderr, "Not a valid GFS2 mount point: %s\n", - sdp->path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - read_superblock(&sdp->sd_sb, sdp); - if (mount_gfs2_meta(sdp)) { - fprintf(stderr, "Error mounting GFS2 metafs: %s\n", - strerror(errno)); - exit(-1); - } - - strcpy(quota_file, sdp->metafs_path); - strcat(quota_file, "/quota"); - - fd = open(quota_file, O_RDWR); - if (fd < 0) { - close(sdp->metafs_fd); - cleanup_metafs(sdp); - die("can't open file %s: %s\n", quota_file, - strerror(errno)); - } - - read_quota_internal(fd, 0, GQ_ID_USER, &q); - write_quota_internal(fd, 0, GQ_ID_USER, &q); - - read_quota_internal(fd, 0, GQ_ID_GROUP, &q); - write_quota_internal(fd, 0, GQ_ID_GROUP, &q); - - /* truncate the quota file such that only the first - * two quotas(uid=0 and gid=0) remain. - */ - if (ftruncate(fd, (sizeof(struct gfs2_quota)) * 2)) - die("couldn't truncate quota file %s\n", strerror(errno)); - - close(fd); - close(sdp->metafs_fd); - cleanup_metafs(sdp); -} - -/** - * do_list - List all the quota data for a filesystem - * @comline: the struct containing the parsed command line arguments - * - */ - -static void -do_list(struct gfs2_sbd *sdp, commandline_t *comline) -{ - int fd; - struct gfs2_quota q; - char buf[sizeof(struct gfs2_quota)]; - uint64_t offset; - uint32_t id, startid; - int pass = 0; - int error = 0; - char quota_file[BUF_SIZE]; - uint64_t quota_file_size = 0; - struct fiemap fmap = { 0, }, *fmap2; - struct stat statbuf; - - if (!*comline->filesystem) - die("need a filesystem to work on\n"); - - strcpy(sdp->path_name, comline->filesystem); - if (check_for_gfs2(sdp)) { - if (errno == EINVAL) - fprintf(stderr, "Not a valid GFS2 mount point: %s\n", - sdp->path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - read_superblock(&sdp->sd_sb, sdp); - if (mount_gfs2_meta(sdp)) { - fprintf(stderr, "Error mounting GFS2 metafs: %s\n", - strerror(errno)); - exit(-1); - } - - strcpy(quota_file, sdp->metafs_path); - strcat(quota_file, "/quota"); - - fd = open(quota_file, O_RDONLY); - if (fd < 0) { - close(sdp->metafs_fd); - cleanup_metafs(sdp); - die("can't open file %s: %s\n", quota_file, - strerror(errno)); - } - if (fstat(fd, &statbuf) < 0) { - close(fd); - close(sdp->metafs_fd); - cleanup_metafs(sdp); - die("can't stat file %s: %s\n", quota_file, - strerror(errno)); - } - quota_file_size = statbuf.st_size; - /* First find the number of extents in the quota file */ - fmap.fm_flags = 0; - fmap.fm_start = 0; - fmap.fm_length = (~0ULL); - error = ioctl(fd, FS_IOC_FIEMAP, &fmap); - if (error == -1) { - fprintf(stderr, "fiemap error (%d): %s\n", errno, strerror(errno)); - goto out; - } - fmap2 = malloc(sizeof(struct fiemap) + - fmap.fm_mapped_extents * sizeof(struct fiemap_extent)); - if (fmap2 == NULL) { - fprintf(stderr, "malloc error (%d): %s\n", errno, strerror(errno)); - goto out; - } - fmap2->fm_flags = 0; - fmap2->fm_start = 0; - fmap2->fm_length = (~0ULL); - fmap2->fm_extent_count = fmap.fm_mapped_extents; - - error = ioctl(fd, FS_IOC_FIEMAP, fmap2); - if (error == -1) { - fprintf(stderr, "fiemap error (%d): %s\n", errno, strerror(errno)); - goto fmap2_free; - } - if (fmap2->fm_mapped_extents) { - int i; - again: - for (i=0; ifm_mapped_extents; i++) { - struct fiemap_extent *fe = &fmap2->fm_extents[i]; - uint64_t end = fe->fe_logical + fe->fe_length; - - end = end > quota_file_size ? quota_file_size : end; - startid = DIV_RU(fe->fe_logical, sizeof(struct gfs2_quota)); - if (startid % 2 != pass) - startid++; - offset = startid * sizeof(struct gfs2_quota); - do { - memset(buf, 0, sizeof(struct gfs2_quota)); - /* read hidden quota file here */ - lseek(fd, offset, SEEK_SET); - error = read(fd, buf, sizeof(struct gfs2_quota)); - if (error < 0) { - fprintf(stderr, "read error (%d): %s\n", - errno, strerror(errno)); - goto fmap2_free; - } - gfs2_quota_in(&q, buf); - id = (offset / sizeof(struct gfs2_quota)) >> 1; - if (q.qu_limit || q.qu_warn || q.qu_value) - print_quota(comline, (pass) ? FALSE : TRUE, id, - &q, &sdp->sd_sb); - offset += 2 * sizeof(struct gfs2_quota); - } while (offset < end); - } - if (!pass) { - pass = 1; - goto again; - } - } - -fmap2_free: - free(fmap2); -out: - close(fd); - close(sdp->metafs_fd); - cleanup_metafs(sdp); -} - -/** - * do_get_one - Get a quota value from one FS - * @comline: the struct containing the parsed command line arguments - * @filesystem: the filesystem to get from - * - */ - -static void -do_get_one(struct gfs2_sbd *sdp, commandline_t *comline, char *filesystem) -{ - int fd; - char buf[256]; - struct gfs2_quota q; - uint64_t offset; - int error; - char quota_file[BUF_SIZE]; - - strcpy(sdp->path_name, filesystem); - if (check_for_gfs2(sdp)) { - if (errno == EINVAL) - fprintf(stderr, "Not a valid GFS2 mount point: %s\n", - sdp->path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - read_superblock(&sdp->sd_sb, sdp); - if (mount_gfs2_meta(sdp)) { - fprintf(stderr, "Error mounting GFS2 metafs: %s\n", - strerror(errno)); - exit(-1); - } - - strcpy(quota_file, sdp->metafs_path); - strcat(quota_file, "/quota"); - - fd = open(quota_file, O_RDONLY); - if (fd < 0) { - close(sdp->metafs_fd); - cleanup_metafs(sdp); - die("can't open file %s: %s\n", quota_file, - strerror(errno)); - } - - if (comline->id_type == GQ_ID_USER) - offset = (2 * (uint64_t)comline->id) * sizeof(struct gfs2_quota); - else - offset = (2 * (uint64_t)comline->id + 1) * sizeof(struct gfs2_quota); - - memset(&q, 0, sizeof(struct gfs2_quota)); - - lseek(fd, offset, SEEK_SET); - error = read(fd, buf, sizeof(struct gfs2_quota)); - if (error < 0) { - close(fd); - close(sdp->metafs_fd); - cleanup_metafs(sdp); - die("can't get quota info (%d): %s\n", - error, strerror(errno)); - } - - gfs2_quota_in(&q, buf); - print_quota(comline, - (comline->id_type == GQ_ID_USER), comline->id, - &q, &sdp->sd_sb); - - close(fd); - close(sdp->metafs_fd); - cleanup_metafs(sdp); -} - -/** - * do_get - Get a quota value - * @comline: the struct containing the parsed command line arguments - * - */ - -static void -do_get(struct gfs2_sbd *sdp, commandline_t *comline) -{ - int first = TRUE; - - if (*comline->filesystem) - do_get_one(sdp, comline, comline->filesystem); - else { - char buf[256], device[256], path[256], type[256]; - FILE *file; - - file = fopen("/proc/mounts", "r"); - if (!file) - die("can't open /proc/mounts: %s\n", strerror(errno)); - - while (fgets(buf, 256, file)) { - if (sscanf(buf, "%s %s %s", device, path, type) != 3) - continue; - if (strcmp(type, "gfs2") != 0) - continue; - - if (first) - first = FALSE; - else - printf("\n"); - - printf("%s\n", path); - do_get_one(sdp, comline, path); - } - - fclose(file); - } -} - -/** - * do_sync_one - sync the quotas on one GFS2 filesystem - * @path: a file/directory in the filesystem - * - */ -static void -do_sync_one(struct gfs2_sbd *sdp, char *filesystem) -{ - char *fsname; - - fsname = mp2fsname(filesystem); - if (!fsname) { - fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n", - filesystem); - exit(-1); - } - if (set_sysfs(fsname, "quota_sync", "1")) { - fprintf(stderr, "Error writing to sysfs quota sync file: %s\n", - strerror(errno)); - exit(-1); - } -} - -/** - * do_sync - sync out unsyned quotas - * @comline: the struct containing the parsed command line arguments - * - */ - -void -do_sync(struct gfs2_sbd *sdp, commandline_t *comline) -{ - sync(); - - if (*comline->filesystem) - do_sync_one(sdp, comline->filesystem); - else { - char buf[256], device[256], path[256], type[256]; - FILE *file; - - file = fopen("/proc/mounts", "r"); - if (!file) - die("can't open /proc/mounts: %s\n", strerror(errno)); - - while (fgets(buf, 256, file)) { - if (sscanf(buf, "%s %s %s", device, path, type) != 3) - continue; - if (strcmp(type, "gfs2") != 0) - continue; - - do_sync_one(sdp, path); - } - - fclose(file); - } -} - -/** - * do_set - Set a quota value - * @comline: the struct containing the parsed command line arguments - * - */ - -static void -do_set(struct gfs2_sbd *sdp, commandline_t *comline) -{ - int fd; - uint64_t offset; - uint64_t new_value; - char quota_file[BUF_SIZE]; - char id_str[16]; - struct stat stat_buf; - struct gfs2_quota q; - char *fs; - - if (!*comline->filesystem) - die("need a filesystem to work on\n"); - if (!comline->new_value_set) - die("need a new value\n"); - - strcpy(sdp->path_name, comline->filesystem); - if (check_for_gfs2(sdp)) { - if (errno == EINVAL) - fprintf(stderr, "Not a valid GFS2 mount point: %s\n", - sdp->path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - read_superblock(&sdp->sd_sb, sdp); - if (mount_gfs2_meta(sdp)) { - fprintf(stderr, "Error mounting GFS2 metafs: %s\n", - strerror(errno)); - exit(-1); - } - - strcpy(quota_file, sdp->metafs_path); - strcat(quota_file, "/quota"); - - fd = open(quota_file, O_RDWR); - if (fd < 0) { - close(sdp->metafs_fd); - cleanup_metafs(sdp); - die("can't open file %s: %s\n", quota_file, - strerror(errno)); - } - - switch (comline->id_type) { - case GQ_ID_USER: - offset = (2 * (uint64_t)comline->id) * sizeof(struct gfs2_quota); - break; - - case GQ_ID_GROUP: - offset = (2 * (uint64_t)comline->id + 1) * sizeof(struct gfs2_quota); - break; - - default: - fprintf(stderr, "invalid user/group ID\n"); - goto out; - } - - switch (comline->units) { - case GQ_UNITS_MEGABYTE: - new_value = - comline->new_value << (20 - sdp->sd_sb.sb_bsize_shift); - break; - - case GQ_UNITS_KILOBYTE: - if (sdp->sd_sb.sb_bsize == 512) - new_value = comline->new_value * 2; - else - new_value = comline->new_value >> - (sdp->sd_sb.sb_bsize_shift - 10); - break; - - case GQ_UNITS_FSBLOCK: - new_value = comline->new_value; - break; - - case GQ_UNITS_BASICBLOCK: - new_value = comline->new_value >> - (sdp->sd_sb.sb_bsize_shift - 9); - break; - - default: - fprintf(stderr, "bad units\n"); - goto out; - } - - memset(&q, 0, sizeof(struct gfs2_quota)); - if (fstat(fd, &stat_buf)) { - fprintf(stderr, "stat failed: %s\n", strerror(errno)); - goto out; - } - if (stat_buf.st_size >= (offset + sizeof(struct gfs2_quota))) - read_quota_internal(fd, comline->id, comline->id_type, &q); - - switch (comline->operation) { - case GQ_OP_LIMIT: - q.qu_limit = new_value; break; - case GQ_OP_WARN: - q.qu_warn = new_value; break; - } - - write_quota_internal(fd, comline->id, comline->id_type, &q); - fs = mp2fsname(comline->filesystem); - if (!fs) { - fprintf(stderr, "Couldn't find GFS2 filesystem mounted at %s\n", - comline->filesystem); - exit(-1); - } - sprintf(id_str, "%d", comline->id); - if (set_sysfs(fs, comline->id_type == GQ_ID_USER ? - "quota_refresh_user" : "quota_refresh_group", id_str)) { - fprintf(stderr, "Error writing to sysfs quota refresh file: %s\n", - strerror(errno)); - exit(-1); - } - -out: - close(fd); - close(sdp->metafs_fd); - cleanup_metafs(sdp); -} - -/** - * main - Do everything - * @argc: well, it's argc... - * @argv: well, it's argv... - * - * Returns: exit status - */ - -int -main(int argc, char *argv[]) -{ - struct gfs2_sbd sbd, *sdp = &sbd; - commandline_t comline; - - memset(sdp, 0, sizeof(struct gfs2_sbd)); - memset(&comline, 0, sizeof(commandline_t)); - - decode_arguments(argc, argv, &comline); - sdp->path_name = (char*) malloc(512); - if (!sdp->path_name) - die("Can't malloc! %s\n", strerror(errno)); - - switch (comline.operation) { - case GQ_OP_LIST: - do_list(sdp, &comline); - break; - - case GQ_OP_GET: - do_get(sdp, &comline); - break; - - case GQ_OP_LIMIT: - case GQ_OP_WARN: - do_set(sdp, &comline); - break; - - case GQ_OP_SYNC: - do_sync(sdp, &comline); - break; - - case GQ_OP_CHECK: - do_sync(sdp, &comline); - do_check(sdp, &comline); - break; - - case GQ_OP_INIT: - do_sync(sdp, &comline); - do_quota_init(sdp, &comline); - break; - - case GQ_OP_RESET: - do_reset(sdp, &comline); - break; - default: - if (!comline.id_type) { - comline.id_type = GQ_ID_USER; - comline.id = geteuid(); - } - do_get(sdp, &comline); - break; - } - - free(sdp->path_name); - - exit(EXIT_SUCCESS); -} diff --git a/gfs2/quota/names.c b/gfs2/quota/names.c deleted file mode 100644 index 22474e0..0000000 --- a/gfs2/quota/names.c +++ /dev/null @@ -1,83 +0,0 @@ -#include "clusterautoconfig.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "gfs2_quota.h" - -uint32_t -name_to_id(int user, char *name, int numbers) -{ - struct passwd *u; - struct group *g; - uint32_t id; - int ok = FALSE; - - if (numbers) { - } else if (user) { - u = getpwnam(name); - if (u) { - id = u->pw_uid; - ok = TRUE; - } - } else { - g = getgrnam(name); - if (g) { - id = g->gr_gid; - ok = TRUE; - } - } - - if (!ok) { - if (!isdigit(name[0])) - die("can't find %s %s\n", - (user) ? "user" : "group", - name); - sscanf(name, "%u", &id); - } - - return id; -} - -char * -id_to_name(int user, uint32_t id, int numbers) -{ - struct passwd *u; - struct group *g; - static char name[256]; - int ok = FALSE; - - if (numbers) { - } else if (user) { - u = getpwuid(id); - if (u) { - strcpy(name, u->pw_name); - ok = TRUE; - } - } else { - g = getgrgid(id); - if (g) { - strcpy(name, g->gr_name); - ok = TRUE; - } - } - - if (!ok) - sprintf(name, "%u", id); - - return name; -} diff --git a/gfs2/quota/target.mk b/gfs2/quota/target.mk deleted file mode 100644 index fc01f6f..0000000 --- a/gfs2/quota/target.mk +++ /dev/null @@ -1,3 +0,0 @@ - -$(eval $(call make-binary,/usr/sbin/gfs2_quota,gfs2/libgfs2/libgfs2.a)) - diff --git a/gfs2/tool/Makefile.am b/gfs2/tool/Makefile.am deleted file mode 100644 index a659eea..0000000 --- a/gfs2/tool/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -MAINTAINERCLEANFILES = Makefile.in - -sbin_PROGRAMS = gfs2_tool - -noinst_HEADERS = gfs2_tool.h iflags.h - -gfs2_tool_SOURCES = main.c misc.c ondisk.c sb.c tune.c - -gfs2_tool_CPPFLAGS = -D_FILE_OFFSET_BITS=64 \ - -I$(top_srcdir)/gfs2/include \ - -I$(top_srcdir)/gfs2/libgfs2 - -gfs2_tool_LDADD = $(top_builddir)/gfs2/libgfs2/libgfs2.la diff --git a/gfs2/tool/gfs2_tool.h b/gfs2/tool/gfs2_tool.h deleted file mode 100644 index 3a181ff..0000000 --- a/gfs2/tool/gfs2_tool.h +++ /dev/null @@ -1,64 +0,0 @@ -#ifndef __GFS2_TOOL_DOT_H__ -#define __GFS2_TOOL_DOT_H__ - -#include - -#define OUTPUT_BLOCKS 0 -#define OUTPUT_K 1 -#define OUTPUT_HUMAN 2 - -extern char *action; -extern int override; -extern int expert; -extern int debug; -extern int continuous; -extern int interval; -extern int output_type; - -/* From counters.c */ - -void print_counters(int argc, char **argv); - - -/* From main.c */ - -void print_usage(void); - - -/* From misc.c */ - -void do_freeze(int argc, char **argv); -void print_lockdump(int argc, char **argv); -void set_flag(int argc, char **argv); -void print_stat(int argc, char **argv); -void print_sb(int argc, char **argv); -void print_jindex(int argc, char **argv); -void print_journals(int argc, char **argv); -void print_rindex(int argc, char **argv); -void print_quota(int argc, char **argv); -void do_withdraw(int argc, char **argv); - - -/* From sb.c */ - -void do_sb(int argc, char **argv); - - -/* From tune.c */ - -void get_tune(int argc, char **argv); -void set_tune(int argc, char **argv); - -/* die() used to be in libgfs2.h */ -static __inline__ __attribute__((noreturn, format (printf, 1, 2))) -void die(const char *fmt, ...) -{ - va_list ap; - fprintf(stderr, "%s: ", __FILE__); - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - exit(-1); -} - -#endif /* __GFS2_TOOL_DOT_H__ */ diff --git a/gfs2/tool/iflags.h b/gfs2/tool/iflags.h deleted file mode 100644 index 2d6cf18..0000000 --- a/gfs2/tool/iflags.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef __IFLAGS_DOT_H__ -#define __IFLAGS_DOT_H__ - -#define FS_IOC_GETFLAGS _IOR('f', 1, long) -#define FS_IOC_SETFLAGS _IOW('f', 2, long) -#define FS_IOC32_GETFLAGS _IOR('f', 1, int) -#define FS_IOC32_SETFLAGS _IOW('f', 2, int) - -/* - * Inode flags (FS_IOC_GETFLAGS / FS_IOC_SETFLAGS) - */ -#define FS_SECRM_FL 0x00000001 /* Secure deletion */ -#define FS_UNRM_FL 0x00000002 /* Undelete */ -#define FS_COMPR_FL 0x00000004 /* Compress file */ -#define FS_SYNC_FL 0x00000008 /* Synchronous updates */ -#define FS_IMMUTABLE_FL 0x00000010 /* Immutable file */ -#define FS_APPEND_FL 0x00000020 /* writes to file may only append */ -#define FS_NODUMP_FL 0x00000040 /* do not dump file */ -#define FS_NOATIME_FL 0x00000080 /* do not update atime */ -/* Reserved for compression usage... */ -#define FS_DIRTY_FL 0x00000100 -#define FS_COMPRBLK_FL 0x00000200 /* One or more compressed clusters */ -#define FS_NOCOMP_FL 0x00000400 /* Don't compress */ -#define FS_ECOMPR_FL 0x00000800 /* Compression error */ -/* End compression flags --- maybe not all used */ -#define FS_BTREE_FL 0x00001000 /* btree format dir */ -#define FS_INDEX_FL 0x00001000 /* hash-indexed directory */ -#define FS_IMAGIC_FL 0x00002000 /* AFS directory */ -#define FS_JOURNAL_DATA_FL 0x00004000 /* Reserved for ext3 */ -#define FS_NOTAIL_FL 0x00008000 /* file tail should not be merged */ -#define FS_DIRSYNC_FL 0x00010000 /* dirsync behaviour (directories only) */ -#define FS_TOPDIR_FL 0x00020000 /* Top of directory hierarchies*/ -#define FS_EXTENT_FL 0x00080000 /* Extents */ -#define FS_DIRECTIO_FL 0x00100000 /* Use direct i/o */ -#define FS_RESERVED_FL 0x80000000 /* reserved for ext2 lib */ - -#define FS_FL_USER_VISIBLE 0x0003DFFF /* User visible flags */ -#define FS_FL_USER_MODIFIABLE 0x000380FF /* User modifiable flags */ - -#endif /* __IFLAGS_DOT_H__ */ diff --git a/gfs2/tool/main.c b/gfs2/tool/main.c deleted file mode 100644 index 829dc76..0000000 --- a/gfs2/tool/main.c +++ /dev/null @@ -1,198 +0,0 @@ -#include "clusterautoconfig.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _(String) gettext(String) - -#include "copyright.cf" - -#include "gfs2_tool.h" -#include "libgfs2.h" - -char *action = NULL; -int override = FALSE; -int expert = FALSE; -int debug = FALSE; -int continuous = FALSE; -int interval = 1; -int output_type = OUTPUT_BLOCKS; - -static const char *usage = { - "Clear a flag on a inode\n" - " gfs2_tool clearflag flag \n" - "Freeze a GFS2 cluster:\n" - " gfs2_tool freeze \n" - "Get tuneable parameters for a filesystem\n" - " gfs2_tool gettune \n" - "List the file system's journals:\n" - " gfs2_tool journals \n" - "Have GFS2 dump its lock state:\n" - " gfs2_tool lockdump [buffersize]\n" - "Tune a GFS2 superblock\n" - " gfs2_tool sb proto [newval]\n" - " gfs2_tool sb table [newval]\n" - " gfs2_tool sb ondisk [newval]\n" - " gfs2_tool sb multihost [newval]\n" - " gfs2_tool sb all\n" - "Set a flag on a inode\n" - " gfs2_tool setflag flag \n" - "Tune a running filesystem\n" - " gfs2_tool settune \n" - "Unfreeze a GFS2 cluster:\n" - " gfs2_tool unfreeze \n" - "Print tool version information\n" - " gfs2_tool version\n" - "Withdraw this machine from participating in a filesystem:\n" - " gfs2_tool withdraw \n" -}; - -/** - * print_usage - print out usage information - * - */ - -void print_usage(void) -{ - puts( _(usage) ); -} - -/** - * print_version - - * - */ - -static void print_version(void) -{ - printf( _("gfs2_tool " VERSION " (built " __DATE__ " " __TIME__ ")\n")); - puts( _(REDHAT_COPYRIGHT "\n") ); -} - -/** - * decode_arguments - - * @argc: - * @argv: - * - */ - -static void decode_arguments(int argc, char *argv[]) -{ - int cont = TRUE; - int optchar; - - output_type = OUTPUT_BLOCKS; - while (cont) { - optchar = getopt(argc, argv, "cDhHki:OVX"); - - switch (optchar) { - case 'c': - continuous = TRUE; - break; - - case 'D': - debug = TRUE; - break; - - case 'h': - print_usage(); - exit(0); - - case 'H': - output_type = OUTPUT_HUMAN; - break; - - case 'i': - sscanf(optarg, "%u", &interval); - break; - - case 'k': - output_type = OUTPUT_K; - break; - - case 'O': - override = TRUE; - break; - - case 'V': - print_version(); - exit(0); - - case 'X': - expert = TRUE; - break; - - case EOF: - cont = FALSE; - break; - - default: - die( _("unknown option: %c\n"), optchar); - }; - } - - if (optind < argc) { - action = argv[optind]; - optind++; - } else { - die( _("no action specified\n")); - } -} - -/** - * main - Do everything - * @argc: - * @argv: - * - */ - -int main(int argc, char *argv[]) -{ - setlocale(LC_ALL, ""); - textdomain("gfs2-utils"); - - if (argc < 2) { - print_usage(); - return 0; - } - - decode_arguments(argc, argv); - - if (strcmp(action, "clearflag") == 0) - set_flag(argc, argv); - else if (strcmp(action, "freeze") == 0) - do_freeze(argc, argv); - else if (strcmp(action, "gettune") == 0) - get_tune(argc, argv); - else if (strcmp(action, "journals") == 0) - print_journals(argc, argv); - else if (strcmp(action, "lockdump") == 0) - print_lockdump(argc, argv); - else if (strcmp(action, "sb") == 0) - do_sb(argc, argv); - else if (strcmp(action, "setflag") == 0) - set_flag(argc, argv); - else if (strcmp(action, "settune") == 0) - set_tune(argc, argv); - else if (strcmp(action, "unfreeze") == 0) - do_freeze(argc, argv); - else if (strcmp(action, "version") == 0) - print_version(); - else if (strcmp(action, "withdraw") == 0) - do_withdraw(argc, argv); - else - die( _("unknown action: %s\n"), action); - - return 0; -} diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c deleted file mode 100644 index 216e4ed..0000000 --- a/gfs2/tool/misc.c +++ /dev/null @@ -1,343 +0,0 @@ -#include "clusterautoconfig.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _(String) gettext(String) - -#define __user -#include -#include - -#include "libgfs2.h" -#include "gfs2_tool.h" -#include "iflags.h" - -#ifndef FIFREZE -#define FIFREEZE _IOWR('X', 119, int) /* Freeze */ -#define FITHAW _IOWR('X', 120, int) /* Thaw */ -#endif - -/** - * do_freeze - freeze a GFS2 filesystem - * @argc: - * @argv: - * - */ - -void do_freeze(int argc, char **argv) -{ - char *command = argv[optind - 1]; - int fd; - - if (optind == argc) - die("Usage: gfs2_tool %s \n", command); - - fd = open(argv[optind], O_NOCTTY|O_RDONLY); - if (fd < 0) { - fprintf(stderr, _("Couldn't find a GFS2 filesystem mounted@%s\n"), - argv[optind]); - exit(-1); - } - - if (strcmp(command, "freeze") == 0) { - if (ioctl(fd, FIFREEZE, 0)) { - fprintf(stderr, _("Error freezing fs: %s\n"), - strerror(errno)); - exit(-1); - } - } else if (strcmp(command, "unfreeze") == 0) { - if (ioctl(fd, FITHAW, 0)) { - fprintf(stderr, _("Error thawing fs: %s\n"), - strerror(errno)); - exit(-1); - } - } - close(fd); -} - -/** - * print_lockdump - - * @argc: - * @argv: - * - */ - -void print_lockdump(int argc, char **argv) -{ - char path[PATH_MAX]; - char *name, line[PATH_MAX]; - char *debugfs; - FILE *file; - int rc = -1; - - /* See if debugfs is mounted, and if not, mount it. */ - debugfs = find_debugfs_mount(); - if (!debugfs) { - debugfs = malloc(PATH_MAX); - if (!debugfs) - die("Can't allocate memory for debugfs.\n"); - - memset(debugfs, 0, PATH_MAX); - sprintf(debugfs, "/tmp/debugfs.XXXXXX"); - - if (!mkdtemp(debugfs)) { - fprintf(stderr,_("Can't create %s mount point.\n"), - debugfs); - free(debugfs); - exit(-1); - } - - rc = mount("none", debugfs, "debugfs", 0, NULL); - if (rc) { - fprintf(stderr, - _("Can't mount debugfs. " - "Maybe your kernel doesn't support it.\n")); - free(debugfs); - exit(-1); - } - } - name = mp2fsname(argv[optind]); - if (name) { - sprintf(path, "%s/gfs2/%s/glocks", debugfs, name); - free(name); - file = fopen(path, "rt"); - if (file) { - while (fgets(line, PATH_MAX, file)) { - printf("%s", line); - } - fclose(file); - } else { - fprintf(stderr, _("Can't open %s: %s\n"), path, - strerror(errno)); - } - } else { - fprintf(stderr, _("Unable to locate sysfs for mount point %s.\n"), - argv[optind]); - } - /* Check if we mounted the debugfs and if so, unmount it. */ - if (!rc) { - umount(debugfs); - rmdir(debugfs); - } - free(debugfs); -} - -/** - * print_flags - print the flags in a dinode's di_flags field - * @di: the dinode structure - * - */ - -static void print_flags(struct gfs2_dinode *di) -{ - if (di->di_flags) { - printf( _("Flags:\n")); - if (di->di_flags & GFS2_DIF_JDATA) - printf(" jdata\n"); - if (di->di_flags & GFS2_DIF_EXHASH) - printf(" exhash\n"); - if (di->di_flags & GFS2_DIF_EA_INDIRECT) - printf(" ea_indirect\n"); - if (di->di_flags & GFS2_DIF_IMMUTABLE) - printf(" immutable\n"); - if (di->di_flags & GFS2_DIF_APPENDONLY) - printf(" appendonly\n"); - if (di->di_flags & GFS2_DIF_NOATIME) - printf( _(" noatime\n")); - if (di->di_flags & GFS2_DIF_SYNC) - printf(" sync\n"); - if (di->di_flags & GFS2_DIF_TRUNC_IN_PROG) - printf(" trunc_in_prog\n"); - } -} - -/* - * Use FS_XXX_FL flags defined in which correspond to - * GFS2_DIF_XXX - */ -static unsigned int get_flag_from_name(char *name) -{ - if (strncmp(name, "jdata", 5) == 0) - return FS_JOURNAL_DATA_FL; - else if (strncmp(name, "exhash", 6) == 0) - return FS_INDEX_FL; - else if (strncmp(name, "immutable", 9) == 0) - return FS_IMMUTABLE_FL; - else if (strncmp(name, "appendonly", 10) == 0) - return FS_APPEND_FL; - else if (strncmp(name, "noatime", 7) == 0) - return FS_NOATIME_FL; - else if (strncmp(name, "sync", 4) == 0) - return FS_SYNC_FL; - else - return 0; -} - -/** - * set_flag - set or clear flags in some dinodes - * @argc: - * @argv: - * - */ -void set_flag(int argc, char **argv) -{ - struct gfs2_dinode di; - char *flstr; - int fd, error, set; - unsigned int newflags = 0; - unsigned int flag; - if (optind == argc) { - di.di_flags = 0xFFFFFFFF; - print_flags(&di); - return; - } - - set = (strcmp(argv[optind -1], "setflag") == 0) ? 1 : 0; - flstr = argv[optind++]; - if (!(flag = get_flag_from_name(flstr))) - die( _("unrecognized flag %s\n"), argv[optind -1]); - - for (; optind < argc; optind++) { - fd = open(argv[optind], O_RDONLY); - if (fd < 0) - die( _("can't open %s: %s\n"), argv[optind], strerror(errno)); - /* first get the existing flags on the file */ - error = ioctl(fd, FS_IOC_GETFLAGS, &newflags); - if (error) - die( _("can't get flags on %s: %s\n"), - argv[optind], strerror(errno)); - newflags = set ? newflags | flag : newflags & ~flag; - /* new flags */ - error = ioctl(fd, FS_IOC_SETFLAGS, &newflags); - if (error) - die( _("can't set flags on %s: %s\n"), - argv[optind], strerror(errno)); - close(fd); - } -} - -/** - * print_journals - print out the file system journal information - * @argc: - * @argv: - * - */ - -void print_journals(int argc, char **argv) -{ - struct gfs2_sbd sbd; - DIR *jindex; - struct dirent *journal; - char jindex_name[PATH_MAX], jname[PATH_MAX]; - int jcount; - struct stat statbuf; - - memset(&sbd, 0, sizeof(struct gfs2_sbd)); - sbd.bsize = GFS2_DEFAULT_BSIZE; - sbd.rgsize = -1; - sbd.jsize = GFS2_DEFAULT_JSIZE; - sbd.qcsize = GFS2_DEFAULT_QCSIZE; - sbd.md.journals = 1; - - sbd.path_name = argv[optind]; - sbd.path_fd = open(sbd.path_name, O_RDONLY); - if (sbd.path_fd < 0) - die("can't open root directory %s: %s\n", - sbd.path_name, strerror(errno)); - if (check_for_gfs2(&sbd)) { - if (errno == EINVAL) - fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"), - sbd.path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - sbd.device_fd = open(sbd.device_name, O_RDONLY); - if (sbd.device_fd < 0) - die( _("can't open device %s: %s\n"), - sbd.device_name, strerror(errno)); - - if (mount_gfs2_meta(&sbd)) { - fprintf(stderr, _("Error mounting GFS2 metafs: %s\n"), - strerror(errno)); - exit(-1); - } - - sprintf(jindex_name, "%s/jindex", sbd.metafs_path); - jindex = opendir(jindex_name); - if (!jindex) { - die( _("Can't open %s\n"), jindex_name); - } else { - jcount = 0; - while ((journal = readdir(jindex))) { - if (journal->d_name[0] == '.') - continue; - sprintf(jname, "%s/%s", jindex_name, journal->d_name); - if (stat(jname, &statbuf)) { - statbuf.st_size = 0; - perror(jname); - } - jcount++; - printf("%s - %lluMB\n", journal->d_name, - (unsigned long long)statbuf.st_size / 1048576); - } - - printf( _("%d journal(s) found.\n"), jcount); - closedir(jindex); - } - cleanup_metafs(&sbd); - close(sbd.device_fd); - close(sbd.path_fd); -} - -/** - * do_withdraw - withdraw a GFS2 filesystem - * @argc: - * @argv: - * - */ - -void do_withdraw(int argc, char **argv) -{ - char *name; - struct gfs2_sbd sbd; - - if (optind == argc) - die("Usage: gfs2_tool withdraw \n"); - - sbd.path_name = argv[optind]; - if (check_for_gfs2(&sbd)) { - if (errno == EINVAL) - fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"), - sbd.path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - name = mp2fsname(argv[optind]); - if (!name) { - fprintf(stderr, _("Couldn't find GFS2 filesystem mounted at %s\n"), - argv[optind]); - exit(-1); - } - - if (set_sysfs(name, "withdraw", "1")) { - fprintf(stderr, _("Error writing to sysfs withdraw file: %s\n"), - strerror(errno)); - exit(-1); - } -} - diff --git a/gfs2/tool/ondisk.c b/gfs2/tool/ondisk.c deleted file mode 100644 index d58c1ef..0000000 --- a/gfs2/tool/ondisk.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "clusterautoconfig.h" - -#include -#include -#include -#include -#include -#include - -#define printk printf - -#define WANT_GFS2_CONVERSION_FUNCTIONS -#include diff --git a/gfs2/tool/sb.c b/gfs2/tool/sb.c deleted file mode 100644 index 7865664..0000000 --- a/gfs2/tool/sb.c +++ /dev/null @@ -1,229 +0,0 @@ -#include "clusterautoconfig.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _(String) gettext(String) - -#include - -#include "gfs2_tool.h" -#include "libgfs2.h" - -void print_it(const char *label, const char *fmt, const char *fmt2, ...) -{ - va_list args; - - va_start(args, fmt2); - printf("%s = ", label); - vprintf(fmt, args); - printf("\n"); - va_end(args); -} - -/** - * str_to_hexchar - convert a string consisting of two isxdigits back to hex. - * Returns: the hex character - */ -static int str_to_hexchar(const char *estring) -{ - int ch = 0; - - if (isdigit(*estring)) - ch = (*estring - '0') * 0x10; - else if (*estring >= 'a' && *estring <= 'f') - ch = (*estring - 'a' + 0x0a) * 0x10; - else if (*estring >= 'A' && *estring <= 'F') - ch = (*estring - 'A' + 0x0a) * 0x10; - - estring++; - if (isdigit(*estring)) - ch += (*estring - '0'); - else if (*estring >= 'a' && *estring <= 'f') - ch += (*estring - 'a' + 0x0a); - else if (*estring >= 'A' && *estring <= 'F') - ch += (*estring - 'A' + 0x0a); - return ch; -} - -/** - * do_sb - examine/modify a unmounted FS' superblock - * @argc: - * @argv: - * - */ - -void -do_sb(int argc, char **argv) -{ - char *device, *field, *newval = NULL; - int fd; - unsigned char buf[GFS2_BASIC_BLOCK], input[256]; - struct gfs2_sb sb; - struct gfs2_buffer_head dummy_bh; - - dummy_bh.b_data = (char *)buf; - if (optind == argc) - die("Usage: gfs2_tool sb [newval]\n"); - - device = argv[optind++]; - - if (optind == argc) - die("Usage: gfs2_tool sb [newval]\n"); - - field = argv[optind++]; - - if (optind < argc) { - if (strcmp(field, "all") == 0) - die("can't specify new value for \"all\"\n"); - newval = argv[optind++]; - } - - - fd = open(device, (newval) ? O_RDWR : O_RDONLY); - if (fd < 0) - die("can't open %s: %s\n", device, strerror(errno)); - - if (newval && !override) { - printf( _("You shouldn't change any of these values if the filesystem is mounted.\n")); - printf( _("\nAre you sure? [y/n] ")); - if(!fgets((char*)input, 255, stdin)) - die( _("unable to read from stdin\n")); - - if (input[0] != 'y') - die( _("aborted\n")); - - printf("\n"); - } - - if (lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK, SEEK_SET) != - GFS2_SB_ADDR * GFS2_BASIC_BLOCK) { - fprintf(stderr, _("bad seek: %s from %s:%d: superblock\n"), - strerror(errno), __FUNCTION__, __LINE__); - exit(-1); - } - if (read(fd, buf, GFS2_BASIC_BLOCK) != GFS2_BASIC_BLOCK) { - fprintf(stderr, _("bad read: %s from %s:%d: superblock\n"), - strerror(errno), __FUNCTION__, __LINE__); - exit(-1); - } - - gfs2_sb_in(&sb, &dummy_bh); - - if (sb.sb_header.mh_magic != GFS2_MAGIC || - sb.sb_header.mh_type != GFS2_METATYPE_SB) - die( _("there isn't a GFS2 filesystem on %s\n"), device); - - if (strcmp(field, "proto") == 0) { - printf( _("current lock protocol name = \"%s\"\n"), - sb.sb_lockproto); - - if (newval) { - if (strlen(newval) >= GFS2_LOCKNAME_LEN) - die( _("new lockproto name is too long\n")); - strcpy(sb.sb_lockproto, newval); - printf( _("new lock protocol name = \"%s\"\n"), - sb.sb_lockproto); - } - } else if (strcmp(field, "table") == 0) { - printf( _("current lock table name = \"%s\"\n"), - sb.sb_locktable); - - if (newval) { - if (strlen(newval) >= GFS2_LOCKNAME_LEN) - die( _("new locktable name is too long\n")); - strcpy(sb.sb_locktable, newval); - printf( _("new lock table name = \"%s\"\n"), - sb.sb_locktable); - } - } else if (strcmp(field, "ondisk") == 0) { - printf( _("current ondisk format = %u\n"), - sb.sb_fs_format); - - if (newval) { - sb.sb_fs_format = atoi(newval); - printf( _("new ondisk format = %u\n"), - sb.sb_fs_format); - } - } else if (strcmp(field, "multihost") == 0) { - printf( _("current multihost format = %u\n"), - sb.sb_multihost_format); - - if (newval) { - sb.sb_multihost_format = atoi(newval); - printf( _("new multihost format = %u\n"), - sb.sb_multihost_format); - } -#ifdef GFS2_HAS_UUID - } else if (strcmp(field, "uuid") == 0) { - printf( _("current uuid = %s\n"), str_uuid(sb.sb_uuid)); - - if (newval) { - int i; - unsigned char uuid[16], *cp; - - if (strlen(newval) != 36) - die( _("uuid %s is the wrong length; must be 36 " - "hex characters long.\n"), newval); - cp = uuid; - for (i = 0; i < 36; i++) { - if ((i == 8) || (i == 13) || - (i == 18) || (i == 23)) { - if (newval[i] == '-') - continue; - die( _("uuid %s has an invalid format."), - newval); - } - if (!isxdigit(newval[i])) - die( _("uuid %s has an invalid hex " - "digit '%c'@offset %d.\n"), - newval, newval[i], i + 1); - *cp = str_to_hexchar(&newval[i++]); - cp++; - } - memcpy(sb.sb_uuid, uuid, 16); - printf( _("new uuid = %s\n"), str_uuid(sb.sb_uuid)); - } -#endif - } else if (strcmp(field, "all") == 0) { - gfs2_sb_print(&sb); - newval = FALSE; - } else - die( _("unknown field %s\n"), field); - - if (newval) { - gfs2_sb_out(&sb, &dummy_bh); - - if (lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK, SEEK_SET) != - GFS2_SB_ADDR * GFS2_BASIC_BLOCK) { - fprintf(stderr, _("bad seek: %s from %s:%d: superblock\n"), - strerror(errno), __FUNCTION__, __LINE__); - exit(-1); - } - if (write(fd, buf, GFS2_BASIC_BLOCK) != GFS2_BASIC_BLOCK) { - fprintf(stderr, _("write error: %s from %s:%d: " - "superblock\n"), strerror(errno), - __FUNCTION__, __LINE__); - exit(-1); - } - - fsync(fd); - - printf( _("Done\n")); - } - - close(fd); -} diff --git a/gfs2/tool/target.mk b/gfs2/tool/target.mk deleted file mode 100644 index ba74727..0000000 --- a/gfs2/tool/target.mk +++ /dev/null @@ -1,3 +0,0 @@ - -$(eval $(call make-binary,/usr/sbin/gfs2_tool,gfs2/libgfs2/libgfs2.a)) - diff --git a/gfs2/tool/tune.c b/gfs2/tool/tune.c deleted file mode 100644 index 1bea4b2..0000000 --- a/gfs2/tool/tune.c +++ /dev/null @@ -1,146 +0,0 @@ -#include "clusterautoconfig.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#define _(String) gettext(String) - -#define __user - -#include "gfs2_tool.h" -#include "libgfs2.h" - -#define SIZE (65536) - -#define SYS_BASE "/sys/fs/gfs2" /* FIXME: Look in /proc/mounts for this */ - -/** - * get_tune - print out the current tuneable parameters for a filesystem - * @argc: - * @argv: - * - */ - -void -get_tune(int argc, char **argv) -{ - char path[PATH_MAX]; - char *fs; - DIR *d; - struct dirent *de; - double ratio; - unsigned int num, den; - struct gfs2_sbd sbd; - char *value; - - if (optind == argc) - die( _("Usage: gfs2_tool gettune \n")); - - sbd.path_name = argv[optind]; - if (check_for_gfs2(&sbd)) { - if (errno == EINVAL) - fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"), - sbd.path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - fs = mp2fsname(argv[optind]); - if (!fs) { - fprintf(stderr, _("Couldn't find GFS2 filesystem mounted at %s\n"), - argv[optind]); - exit(-1); - } - memset(path, 0, PATH_MAX); - snprintf(path, PATH_MAX - 1, "%s/%s/tune", SYS_BASE, fs); - - d = opendir(path); - if (!d) - die( _("can't open %s: %s\n"), path, strerror(errno)); - - while((de = readdir(d))) { - if (de->d_name[0] == '.') - continue; - snprintf(path, PATH_MAX - 1, "tune/%s", de->d_name); - if (strcmp(de->d_name, "quota_scale") == 0) { - value = get_sysfs(fs, "tune/quota_scale"); - if (!value) { - printf( _("quota_scale = (Not found: %s)\n"), - strerror(errno)); - continue; - } - sscanf(value, "%u %u", &num, &den); - ratio = (double)num / den; - printf( _("quota_scale = %.4f (%u, %u)\n"), ratio, num, - den); - } else - printf("%s = %s\n", de->d_name, get_sysfs(fs, path)); - } - closedir(d); -} - -/** - * set_tune - set a tuneable parameter - * @argc: - * @argv: - * - */ - -void -set_tune(int argc, char **argv) -{ - char *param, *value; - char tune_base[SIZE] = "tune/"; - char buf[256]; - char *fs; - struct gfs2_sbd sbd; - - if (optind == argc) - die( _("Usage: gfs2_tool settune \n")); - sbd.path_name = argv[optind++]; - if (optind == argc) - die( _("Usage: gfs2_tool settune \n")); - param = argv[optind++]; - if (optind == argc) - die( _("Usage: gfs2_tool settune \n")); - value = argv[optind++]; - - if (check_for_gfs2(&sbd)) { - if (errno == EINVAL) - fprintf(stderr, _("Not a valid GFS2 mount point: %s\n"), - sbd.path_name); - else - fprintf(stderr, "%s\n", strerror(errno)); - exit(-1); - } - fs = mp2fsname(sbd.path_name); - if (!fs) { - fprintf(stderr, _("Couldn't find GFS2 filesystem mounted at %s\n"), - sbd.path_name); - exit(-1); - } - - if (strcmp(param, "quota_scale") == 0) { - float s; - sscanf(value, "%f", &s); - sprintf(buf, "%u %u", (unsigned int)(s * 10000.0 + 0.5), 10000); - value = buf; - } - if (set_sysfs(fs, strcat(tune_base, param), value)) { - fprintf(stderr, _("Error writing to sysfs %s tune file: %s\n"), - param, strerror(errno)); - exit(-1); - } -} -- 1.7.10.2