From 88c7f535fbe80d96cf5ee15a3a2aa1bd1c535e1f Mon Sep 17 00:00:00 2001 From: jkar8572 Date: Mon, 16 Jul 2001 03:24:49 +0000 Subject: Fixed quotastats(8) Grace times are now set when limits are set and usage is over limit. Added LARGEFILE flag to CFLAGS. --- Makefile.in | 6 +++--- dqblk_v1.h | 1 + edquota.c | 40 +++++++++++++++++++++++++++++----------- quotacheck.c | 9 +++------ quotaio_v1.h | 11 ++++++++++- quotaops.c | 43 ++++++++++++++++++++++++++----------------- quotaops.h | 18 +++++++++--------- quotastats.c | 18 ++++++++++++++++-- setquota.c | 2 ++ 9 files changed, 99 insertions(+), 49 deletions(-) diff --git a/Makefile.in b/Makefile.in index d06bfae..0b4c794 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,5 +1,5 @@ PROGS = quotacheck quotaon quota quot repquota warnquota quotastats xqmstats edquota setquota convertquota rpc.rquotad -CFLAGS = @CFLAGS@ @EXT2_DIRECT@ -D_GNU_SOURCE -Wall +CFLAGS = @CFLAGS@ @EXT2_DIRECT@ -D_GNU_SOURCE -Wall -D_LARGEFILE64_SOURCE EXT2LIBS = @EXT2LIBS@ RPCSRC = rquota.h rquota_xdr.c rquota_clnt.c VERSIONDEF = -DQUOTA_VERSION=\"3.01\" @@ -92,8 +92,8 @@ install: all inst_mo quotaon: $(INCLUDE) quotaon.o quotaon_xfs.o $(LIBOBJS) $(CC) $(LDFLAGS) -o $@ quotaon.o quotaon_xfs.o $(LIBOBJS) -quotacheck: $(INCLUDE) quotacheck.o quotacheck_v1.o quotacheck_v2.o quotacheck.h $(LIBOBJS) - $(CC) $(LDFLAGS) -o $@ quotacheck.o quotacheck_v1.o quotacheck_v2.o $(EXT2LIBS) $(LIBOBJS) +quotacheck: $(INCLUDE) quotacheck.o quotacheck_v1.o quotacheck_v2.o quotacheck.h quotaops.o $(LIBOBJS) + $(CC) $(LDFLAGS) -o $@ quotacheck.o quotacheck_v1.o quotacheck_v2.o quotaops.o $(EXT2LIBS) $(LIBOBJS) quota: $(INCLUDE) rquota.h quota.o quotaops.o $(LIBOBJS) $(CC) $(LDFLAGS) -o $@ quota.o quotaops.o $(LIBOBJS) diff --git a/dqblk_v1.h b/dqblk_v1.h index 409a70c..4b3fa35 100644 --- a/dqblk_v1.h +++ b/dqblk_v1.h @@ -9,6 +9,7 @@ #define Q_V1_RSQUASH 0x1000 #define Q_V1_GETQUOTA 0x300 #define Q_V1_SETQUOTA 0x400 +#define Q_V1_GETSTATS 0x800 struct quotafile_ops; /* Will be defined later in quotaio.h */ diff --git a/edquota.c b/edquota.c index 84c9af7..749b1d0 100644 --- a/edquota.c +++ b/edquota.c @@ -34,7 +34,7 @@ #ident "$Copyright: (c) 1980, 1990 Regents of the University of California. $" #ident "$Copyright: All rights reserved. $" -#ident "$Id: edquota.c,v 1.4 2001/05/02 09:32:22 jkar8572 Exp $" +#ident "$Id: edquota.c,v 1.5 2001/07/16 03:24:49 jkar8572 Exp $" /* * Disk quota editor. @@ -79,7 +79,7 @@ void usage(void) int main(int argc, char **argv) { - struct dquot *q, *protoprivs, *curprivs, *pprivs, *cprivs; + struct dquot *protoprivs, *curprivs, *pprivs, *cprivs; long id, protoid; int quotatype, tmpfd, ret; char *protoname = NULL; @@ -145,10 +145,6 @@ int main(int argc, char **argv) if (pflag) { protoid = name2id(protoname, quotatype); protoprivs = getprivs(protoid, handles); - for (q = protoprivs; q; q = q->dq_next) { - q->dq_dqb.dqb_btime = 0; - q->dq_dqb.dqb_itime = 0; - } while (argc-- > 0) { id = name2id(*argv++, quotatype); curprivs = getprivs(id, handles); @@ -166,11 +162,14 @@ int main(int argc, char **argv) pprivs->dq_dqb.dqb_isoftlimit; cprivs->dq_dqb.dqb_ihardlimit = pprivs->dq_dqb.dqb_ihardlimit; + update_grace_times(cprivs); } } putprivs(curprivs); + freeprivs(curprivs); } dispose_handle_list(handles); + freeprivs(protoprivs); warn_new_kernel(fmt); exit(0); } @@ -186,17 +185,36 @@ int main(int argc, char **argv) tmpfd = mkstemp(tmpfil); fchown(tmpfd, getuid(), getgid()); if (tflag) { - writetimes(handles, tmpfd); - if (!editprivs(tmpfil) && (readtimes(handles, tmpfd) < 0)) + if (writetimes(handles, tmpfd) < 0) { + unlink(tmpfil); + die(1, _("Can't write grace times to file.\n")); + } + if (editprivs(tmpfil) < 0) { + unlink(tmpfil); + die(1, _("Error while editting grace times.\n")); + } + if (readtimes(handles, tmpfd) < 0) { + unlink(tmpfil); die(1, _("Failed to parse grace times file.\n")); + } } else { for (; argc > 0; argc--, argv++) { id = name2id(*argv, quotatype); curprivs = getprivs(id, handles); - writeprivs(curprivs, tmpfd, *argv, quotatype); - if (!editprivs(tmpfil) && !readprivs(curprivs, tmpfd)) - putprivs(curprivs); + if (writeprivs(curprivs, tmpfd, *argv, quotatype) < 0) { + errstr(_("Can't write quotas to file.\n")); + continue; + } + if (editprivs(tmpfil) < 0) { + errstr(_("Error while editting quotas.\n")); + continue; + } + if (readprivs(curprivs, tmpfd) < 0) { + errstr(_("Can't read quotas from file.\n")); + continue; + } + putprivs(curprivs); freeprivs(curprivs); } } diff --git a/quotacheck.c b/quotacheck.c index b95ac11..ea4487c 100644 --- a/quotacheck.c +++ b/quotacheck.c @@ -8,7 +8,7 @@ * New quota format implementation - Jan Kara - Sponsored by SuSE CR */ -#ident "$Id: quotacheck.c,v 1.12 2001/05/26 19:46:40 jkar8572 Exp $" +#ident "$Id: quotacheck.c,v 1.13 2001/07/16 03:24:49 jkar8572 Exp $" #include #include @@ -39,6 +39,7 @@ #include "mntopt.h" #include "bylabel.h" #include "quotacheck.h" +#include "quotaops.h" #define LINKSHASHSIZE 16384 /* Size of hashtable for hardlinked inodes */ #define DQUOTHASHSIZE 32768 /* Size of hashtable for dquots from file */ @@ -677,11 +678,7 @@ static int dump_to_file(char *mnt_fsname, struct mntent *mnt, int type) for (i = 0; i < DQUOTHASHSIZE; i++) for (dquot = dquot_hash[type][i]; dquot; dquot = dquot->dq_next) { dquot->dq_h = h; - /* Unset grace times if limit is not exceeded; if limit is not set, clear times too... */ - if (dquot->dq_dqb.dqb_bsoftlimit > toqb(dquot->dq_dqb.dqb_curspace)) - dquot->dq_dqb.dqb_btime = 0; - if (dquot->dq_dqb.dqb_isoftlimit > dquot->dq_dqb.dqb_curinodes) - dquot->dq_dqb.dqb_itime = 0; + update_grace_times(dquot); h->qh_ops->commit_dquot(dquot); } if (end_io(h) < 0) { diff --git a/quotaio_v1.h b/quotaio_v1.h index f36ed63..21c5e85 100644 --- a/quotaio_v1.h +++ b/quotaio_v1.h @@ -18,7 +18,6 @@ struct v1_disk_dqblk { u_int32_t dqb_bsoftlimit; /* preferred limit on disk blks */ u_int32_t dqb_curblocks; /* current block count */ u_int32_t dqb_ihardlimit; /* maximum # allocated inodes */ - u_int32_t dqb_isoftlimit; /* preferred inode limit */ u_int32_t dqb_curinodes; /* current # allocated inodes */ time_t dqb_btime; /* time limit for excessive disk use */ time_t dqb_itime; /* time limit for excessive files */ @@ -36,4 +35,14 @@ struct v1_kern_dqblk { time_t dqb_itime; /* time limit for excessive files */ }; +struct v1_dqstats { + u_int32_t lookups; + u_int32_t drops; + u_int32_t reads; + u_int32_t writes; + u_int32_t cache_hits; + u_int32_t allocated_dquots; + u_int32_t free_dquots; + u_int32_t syncs; +}; #endif diff --git a/quotaops.c b/quotaops.c index b9cd873..2168354 100644 --- a/quotaops.c +++ b/quotaops.c @@ -34,7 +34,7 @@ #ident "$Copyright: (c) 1980, 1990 Regents of the University of California. $" #ident "$Copyright: All rights reserved. $" -#ident "$Id: quotaops.c,v 1.4 2001/05/02 09:32:22 jkar8572 Exp $" +#ident "$Id: quotaops.c,v 1.5 2001/07/16 03:24:49 jkar8572 Exp $" #include #include @@ -49,6 +49,7 @@ #include #include #include +#include #if defined(RPC) #include "rquota.h" @@ -83,6 +84,28 @@ static int cvtatos(time_t time, char *units, time_t * seconds) return 0; } +/* + * Set grace time if needed + */ +void update_grace_times(struct dquot *q) +{ + time_t now; + + time(&now); + if (q->dq_dqb.dqb_bsoftlimit && toqb(q->dq_dqb.dqb_curspace) >= q->dq_dqb.dqb_bsoftlimit) { + if (!q->dq_dqb.dqb_btime) + q->dq_dqb.dqb_btime = now + q->dq_h->qh_info.dqi_bgrace; + } + else + q->dq_dqb.dqb_btime = 0; + if (q->dq_dqb.dqb_isoftlimit && q->dq_dqb.dqb_curinodes >= q->dq_dqb.dqb_isoftlimit) { + if (!q->dq_dqb.dqb_itime) + q->dq_dqb.dqb_itime = now + q->dq_h->qh_info.dqi_igrace; + } + else + q->dq_dqb.dqb_itime = 0; +} + /* * Collect the requested quota information. */ @@ -177,7 +200,7 @@ int editprivs(char *tmpfile) sigaddset(&nmask, SIGHUP); sigprocmask(SIG_SETMASK, &nmask, &omask); if ((pid = fork()) < 0) { - perror("fork"); + errstr("Can't fork(): %s\n", strerror(errno)); return -1; } if (pid == 0) { @@ -254,26 +277,12 @@ static void merge_to_list(struct dquot *qlist, char *dev, u_int64_t blocks, u_in if (!devcmp_handle(dev, q->dq_h)) continue; - /* - * Cause time limit to be reset when the quota is - * next used if previously had no soft limit or were - * under it, but now have a soft limit and are over - * it. - */ - if (bsoft && (toqb(q->dq_dqb.dqb_curspace) >= bsoft) && - (q->dq_dqb.dqb_bsoftlimit == 0 || - toqb(q->dq_dqb.dqb_curspace) < q->dq_dqb.dqb_bsoftlimit)) - q->dq_dqb.dqb_btime = 0; - - if (isoft && (q->dq_dqb.dqb_curinodes >= isoft) && - (q->dq_dqb.dqb_isoftlimit == 0 || - q->dq_dqb.dqb_curinodes < q->dq_dqb.dqb_isoftlimit)) q->dq_dqb.dqb_itime = 0; - q->dq_dqb.dqb_bsoftlimit = bsoft; q->dq_dqb.dqb_bhardlimit = bhard; q->dq_dqb.dqb_isoftlimit = isoft; q->dq_dqb.dqb_ihardlimit = ihard; q->dq_flags |= DQ_FOUND; + update_grace_times(q); if (blocks != toqb(q->dq_dqb.dqb_curspace)) errstr(_("WARNING - %s: cannot change current block allocation\n"), diff --git a/quotaops.h b/quotaops.h index da28bde..4eb0cb1 100644 --- a/quotaops.h +++ b/quotaops.h @@ -3,14 +3,14 @@ #include "quotaio.h" -__BEGIN_DECLS extern struct dquot *getprivs __P((qid_t id, struct quota_handle ** handles)); -extern int putprivs __P((struct dquot * qlist)); -extern int editprivs __P((char *tmpfile)); -extern int writeprivs __P((struct dquot * qlist, int outfd, char *name, int quotatype)); -extern int readprivs __P((struct dquot * qlist, int infd)); -extern int writetimes __P((struct quota_handle ** handles, int outfd)); -extern int readtimes __P((struct quota_handle ** handles, int infd)); -extern void freeprivs __P((struct dquot * qlist)); +struct dquot *getprivs(qid_t id, struct quota_handle ** handles); +int putprivs(struct dquot * qlist); +int editprivs(char *tmpfile); +int writeprivs(struct dquot * qlist, int outfd, char *name, int quotatype); +int readprivs(struct dquot * qlist, int infd); +int writetimes(struct quota_handle ** handles, int outfd); +int readtimes(struct quota_handle ** handles, int infd); +void freeprivs(struct dquot * qlist); +void update_grace_times(struct dquot *q); -__END_DECLS #endif /* _QUOTAOPS_H */ diff --git a/quotastats.c b/quotastats.c index 522f6a6..a584b72 100644 --- a/quotastats.c +++ b/quotastats.c @@ -10,7 +10,7 @@ * * Author: Marco van Wieringen * - * Version: $Id: quotastats.c,v 1.2 2001/05/02 09:32:22 jkar8572 Exp $ + * Version: $Id: quotastats.c,v 1.3 2001/07/16 03:24:49 jkar8572 Exp $ * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -21,13 +21,27 @@ #include #include #include +#include +#include #include "pot.h" #include "quota.h" +#include "quotaio_v1.h" +#include "dqblk_v1.h" static inline int get_stats(struct dqstats *dqstats) { - return quotactl(QCMD(Q_GETSTATS, 0), (char *)NULL, 0, (caddr_t)dqstats); + struct v1_dqstats old_dqstats; + + if (quotactl(QCMD(Q_GETSTATS, 0), NULL, 0, (caddr_t)dqstats) < 0) { + if (errno != EINVAL) + return -1; + if (quotactl(QCMD(Q_V1_GETSTATS, 0), NULL, 0, (caddr_t)&old_dqstats) < 0) + return -1; + memcpy(dqstats, &old_dqstats, sizeof(old_dqstats)); + dqstats->version = 0; + } + return 0; } static inline int print_stats(struct dqstats *dqstats) diff --git a/setquota.c b/setquota.c index 8721766..d5236dd 100644 --- a/setquota.c +++ b/setquota.c @@ -185,6 +185,7 @@ static void setlimits(struct quota_handle **handles) q->dq_dqb.dqb_bhardlimit = protoq->dq_dqb.dqb_bhardlimit; q->dq_dqb.dqb_isoftlimit = protoq->dq_dqb.dqb_isoftlimit; q->dq_dqb.dqb_ihardlimit = protoq->dq_dqb.dqb_ihardlimit; + update_grace_times(q); } freeprivs(protoprivs); } @@ -194,6 +195,7 @@ static void setlimits(struct quota_handle **handles) q->dq_dqb.dqb_bhardlimit = toset.dqb_bhardlimit; q->dq_dqb.dqb_isoftlimit = toset.dqb_isoftlimit; q->dq_dqb.dqb_ihardlimit = toset.dqb_ihardlimit; + update_grace_times(q); } } putprivs(curprivs); -- cgit v1.2.3