Restored the "reallocblks" code to its former glory. What this does is

basically do a on-the-fly defragmentation of the FFS filesystem, changing
file block allocations to make them contiguous. Thanks to Kirk McKusick
for providing hints on what needed to be done to get this working.
This commit is contained in:
David Greenman 1998-11-13 01:01:44 +00:00
parent 468662e864
commit 1c680b45a2
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=41124
4 changed files with 38 additions and 31 deletions

View File

@ -33,7 +33,7 @@
* SUCH DAMAGE.
*
* @(#)vfs_cluster.c 8.7 (Berkeley) 2/13/94
* $Id: vfs_cluster.c,v 1.70 1998/09/04 08:06:55 dfr Exp $
* $Id: vfs_cluster.c,v 1.71 1998/10/25 17:44:52 phk Exp $
*/
#include "opt_debug_cluster.h"
@ -43,6 +43,7 @@
#include <sys/proc.h>
#include <sys/buf.h>
#include <sys/vnode.h>
#include <sys/malloc.h>
#include <sys/mount.h>
#include <sys/resourcevar.h>
#include <vm/vm.h>
@ -57,10 +58,10 @@ static int rcluster= 0;
SYSCTL_INT(_debug, OID_AUTO, rcluster, CTLFLAG_RW, &rcluster, 0, "");
#endif
#ifdef notyet_block_reallocation_enabled
static MALLOC_DEFINE(M_SEGMENT, "cluster_save buffer", "cluster_save buffer");
static struct cluster_save *
cluster_collectbufs __P((struct vnode *vp, struct buf *last_bp));
#endif
static struct buf *
cluster_rbuild __P((struct vnode *vp, u_quad_t filesize, daddr_t lbn,
daddr_t blkno, long size, int run, struct buf *fbp));
@ -539,16 +540,7 @@ cluster_write(bp, filesize)
* reallocating to make it sequential.
*/
cursize = vp->v_lastw - vp->v_cstart + 1;
#ifndef notyet_block_reallocation_enabled
if (((u_quad_t) bp->b_offset + lblocksize) != filesize ||
lbn != vp->v_lastw + 1 ||
vp->v_clen <= cursize) {
if (!async)
cluster_wbuild(vp, lblocksize,
vp->v_cstart, cursize);
}
#else
if ((lbn + 1) * lblocksize != filesize ||
lbn != vp->v_lastw + 1 || vp->v_clen <= cursize) {
if (!async)
cluster_wbuild(vp, lblocksize,
@ -583,7 +575,6 @@ cluster_write(bp, filesize)
return;
}
}
#endif /* notyet_block_reallocation_enabled */
}
/*
* Consider beginning a cluster. If at end of file, make
@ -822,7 +813,6 @@ cluster_wbuild(vp, size, start_lbn, len)
return totalwritten;
}
#ifdef notyet_block_reallocation_enabled
/*
* Collect together all the buffers in a cluster.
* Plus add one additional buffer.
@ -848,4 +838,3 @@ cluster_collectbufs(vp, last_bp)
buflist->bs_nchildren = i + 1;
return (buflist);
}
#endif /* notyet_block_reallocation_enabled */

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)buf.h 8.9 (Berkeley) 3/30/95
* $Id: buf.h,v 1.59 1998/10/03 16:19:27 bde Exp $
* $Id: buf.h,v 1.60 1998/10/31 14:05:11 peter Exp $
*/
#ifndef _SYS_BUF_H_
@ -184,6 +184,20 @@ struct buf_queue_head {
struct buf *switch_point;
};
/*
* This structure describes a clustered I/O. It is stored in the b_saveaddr
* field of the buffer on which I/O is done. At I/O completion, cluster
* callback uses the structure to parcel I/O's to individual buffers, and
* then free's this structure.
*/
struct cluster_save {
long bs_bcount; /* Saved b_bcount. */
long bs_bufsize; /* Saved b_bufsize. */
void *bs_saveaddr; /* Saved b_addr. */
int bs_nchildren; /* Number of associated buffers. */
struct buf **bs_children; /* List of associated buffers. */
};
static __inline void bufq_init __P((struct buf_queue_head *head));
static __inline void bufq_insert_tail __P((struct buf_queue_head *head,

View File

@ -36,7 +36,7 @@
* SUCH DAMAGE.
*
* @(#)buf.h 8.9 (Berkeley) 3/30/95
* $Id: buf.h,v 1.59 1998/10/03 16:19:27 bde Exp $
* $Id: buf.h,v 1.60 1998/10/31 14:05:11 peter Exp $
*/
#ifndef _SYS_BUF_H_
@ -184,6 +184,20 @@ struct buf_queue_head {
struct buf *switch_point;
};
/*
* This structure describes a clustered I/O. It is stored in the b_saveaddr
* field of the buffer on which I/O is done. At I/O completion, cluster
* callback uses the structure to parcel I/O's to individual buffers, and
* then free's this structure.
*/
struct cluster_save {
long bs_bcount; /* Saved b_bcount. */
long bs_bufsize; /* Saved b_bufsize. */
void *bs_saveaddr; /* Saved b_addr. */
int bs_nchildren; /* Number of associated buffers. */
struct buf **bs_children; /* List of associated buffers. */
};
static __inline void bufq_init __P((struct buf_queue_head *head));
static __inline void bufq_insert_tail __P((struct buf_queue_head *head,

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE.
*
* @(#)ffs_alloc.c 8.18 (Berkeley) 5/26/95
* $Id: ffs_alloc.c,v 1.52 1998/09/05 14:13:12 phk Exp $
* $Id: ffs_alloc.c,v 1.53 1998/09/07 11:50:18 bde Exp $
*/
#include "opt_quota.h"
@ -42,13 +42,13 @@
#include <sys/proc.h>
#include <sys/vnode.h>
#include <sys/mount.h>
#ifdef notyet
#include <sys/kernel.h>
#include <sys/sysctl.h>
#endif
#include <sys/syslog.h>
#include <ufs/ufs/quota.h>
#include <ufs/ufs/inode.h>
#include <ufs/ufs/ufs_extern.h>
#include <ufs/ufs/ufsmount.h>
#include <ufs/ffs/fs.h>
@ -65,10 +65,8 @@ static int ffs_checkblk __P((struct inode *, ufs_daddr_t, long));
#endif
static void ffs_clusteracct __P((struct fs *, struct cg *, ufs_daddr_t,
int));
#ifdef notyet
static ufs_daddr_t ffs_clusteralloc __P((struct inode *, int, ufs_daddr_t,
int));
#endif
static ino_t ffs_dirpref __P((struct fs *));
static ufs_daddr_t ffs_fragextend __P((struct inode *, int, long, int, int));
static void ffs_fserr __P((struct fs *, u_int, char *));
@ -323,7 +321,6 @@ ffs_realloccg(ip, lbprev, bpref, osize, nsize, cred, bpp)
return (ENOSPC);
}
#ifdef notyet
SYSCTL_NODE(_vfs, OID_AUTO, ffs, CTLFLAG_RW, 0, "FFS filesystem");
/*
@ -347,7 +344,6 @@ static int doreallocblks = 1;
SYSCTL_INT(_vfs_ffs, FFS_REALLOCBLKS, doreallocblks, CTLFLAG_RW, &doreallocblks, 0, "");
static int prtrealloc = 0;
#endif
int
ffs_reallocblks(ap)
@ -356,9 +352,6 @@ ffs_reallocblks(ap)
struct cluster_save *a_buflist;
} */ *ap;
{
#if !defined (not_yes)
return (ENOSPC);
#else
struct fs *fs;
struct inode *ip;
struct vnode *vp;
@ -509,7 +502,7 @@ ffs_reallocblks(ap)
} else {
ip->i_flag |= IN_CHANGE | IN_UPDATE;
if (!doasyncfree) {
gettime(&tv);
getmicrotime(&tv);
UFS_UPDATE(vp, &tv, &tv, 1);
}
}
@ -553,7 +546,6 @@ ffs_reallocblks(ap)
if (sbap != &ip->i_db[0])
brelse(sbp);
return (ENOSPC);
#endif
}
/*
@ -1087,7 +1079,6 @@ ffs_alloccgblk(ip, bp, bpref)
return (blkno);
}
#ifdef notyet
/*
* Determine whether a cluster can be allocated.
*
@ -1196,7 +1187,6 @@ ffs_clusteralloc(ip, cg, bpref, len)
brelse(bp);
return (0);
}
#endif
/*
* Determine whether an inode can be allocated.