ffs_snapshot.c (108050) | ffs_snapshot.c (109623) |
---|---|
1/* 2 * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved. 3 * 4 * Further information about snapshots can be obtained from: 5 * 6 * Marshall Kirk McKusick http://www.mckusick.com/softdep/ 7 * 1614 Oxford Street mckusick@mckusick.com 8 * Berkeley, CA 94709-1608 +1-510-843-9542 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ffs_snapshot.c 8.11 (McKusick) 7/23/00 | 1/* 2 * Copyright 2000 Marshall Kirk McKusick. All Rights Reserved. 3 * 4 * Further information about snapshots can be obtained from: 5 * 6 * Marshall Kirk McKusick http://www.mckusick.com/softdep/ 7 * 1614 Oxford Street mckusick@mckusick.com 8 * Berkeley, CA 94709-1608 +1-510-843-9542 --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)ffs_snapshot.c 8.11 (McKusick) 7/23/00 |
34 * $FreeBSD: head/sys/ufs/ffs/ffs_snapshot.c 108050 2002-12-18 19:50:28Z mckusick $ | 34 * $FreeBSD: head/sys/ufs/ffs/ffs_snapshot.c 109623 2003-01-21 08:56:16Z alfred $ |
35 */ 36 37#include <sys/param.h> 38#include <sys/stdint.h> 39#include <sys/kernel.h> 40#include <sys/systm.h> 41#include <sys/conf.h> 42#include <sys/bio.h> --- 221 unchanged lines hidden (view full) --- 264 * Copy all the cylinder group maps. Although the 265 * filesystem is still active, we hope that only a few 266 * cylinder groups will change between now and when we 267 * suspend operations. Thus, we will be able to quickly 268 * touch up the few cylinder groups that changed during 269 * the suspension period. 270 */ 271 len = howmany(fs->fs_ncg, NBBY); | 35 */ 36 37#include <sys/param.h> 38#include <sys/stdint.h> 39#include <sys/kernel.h> 40#include <sys/systm.h> 41#include <sys/conf.h> 42#include <sys/bio.h> --- 221 unchanged lines hidden (view full) --- 264 * Copy all the cylinder group maps. Although the 265 * filesystem is still active, we hope that only a few 266 * cylinder groups will change between now and when we 267 * suspend operations. Thus, we will be able to quickly 268 * touch up the few cylinder groups that changed during 269 * the suspension period. 270 */ 271 len = howmany(fs->fs_ncg, NBBY); |
272 MALLOC(fs->fs_active, int *, len, M_DEVBUF, M_WAITOK); | 272 MALLOC(fs->fs_active, int *, len, M_DEVBUF, 0); |
273 bzero(fs->fs_active, len); 274 for (cg = 0; cg < fs->fs_ncg; cg++) { 275 error = UFS_BALLOC(vp, (off_t)(cgtod(fs, cg)) << fs->fs_fshift, 276 fs->fs_bsize, KERNCRED, 0, &nbp); 277 if (error) 278 goto out; 279 error = cgaccount(cg, vp, nbp, 1); 280 bawrite(nbp); --- 73 unchanged lines hidden (view full) --- 354 if ((fs->fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) == 0) 355 copy_fs->fs_clean = 1; 356 if (fs->fs_sbsize < SBLOCKSIZE) 357 bzero(&sbp->b_data[loc + fs->fs_sbsize], 358 SBLOCKSIZE - fs->fs_sbsize); 359 size = blkroundup(fs, fs->fs_cssize); 360 if (fs->fs_contigsumsize > 0) 361 size += fs->fs_ncg * sizeof(int32_t); | 273 bzero(fs->fs_active, len); 274 for (cg = 0; cg < fs->fs_ncg; cg++) { 275 error = UFS_BALLOC(vp, (off_t)(cgtod(fs, cg)) << fs->fs_fshift, 276 fs->fs_bsize, KERNCRED, 0, &nbp); 277 if (error) 278 goto out; 279 error = cgaccount(cg, vp, nbp, 1); 280 bawrite(nbp); --- 73 unchanged lines hidden (view full) --- 354 if ((fs->fs_flags & (FS_UNCLEAN | FS_NEEDSFSCK)) == 0) 355 copy_fs->fs_clean = 1; 356 if (fs->fs_sbsize < SBLOCKSIZE) 357 bzero(&sbp->b_data[loc + fs->fs_sbsize], 358 SBLOCKSIZE - fs->fs_sbsize); 359 size = blkroundup(fs, fs->fs_cssize); 360 if (fs->fs_contigsumsize > 0) 361 size += fs->fs_ncg * sizeof(int32_t); |
362 space = malloc((u_long)size, M_UFSMNT, M_WAITOK); | 362 space = malloc((u_long)size, M_UFSMNT, 0); |
363 copy_fs->fs_csp = space; 364 bcopy(fs->fs_csp, copy_fs->fs_csp, fs->fs_cssize); 365 (char *)space += fs->fs_cssize; 366 loc = howmany(fs->fs_cssize, fs->fs_fsize); 367 i = fs->fs_frag - loc % fs->fs_frag; 368 len = (i == fs->fs_frag) ? 0 : i * fs->fs_fsize; 369 if (len > 0) { 370 if ((error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + loc), --- 97 unchanged lines hidden (view full) --- 468 VI_LOCK(vp); 469 vp->v_vnlock = ITOV(xp)->v_vnlock; 470 VI_UNLOCK(devvp); 471 } else { 472 struct lock *lkp; 473 474 VI_UNLOCK(devvp); 475 MALLOC(lkp, struct lock *, sizeof(struct lock), M_UFSMNT, | 363 copy_fs->fs_csp = space; 364 bcopy(fs->fs_csp, copy_fs->fs_csp, fs->fs_cssize); 365 (char *)space += fs->fs_cssize; 366 loc = howmany(fs->fs_cssize, fs->fs_fsize); 367 i = fs->fs_frag - loc % fs->fs_frag; 368 len = (i == fs->fs_frag) ? 0 : i * fs->fs_fsize; 369 if (len > 0) { 370 if ((error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + loc), --- 97 unchanged lines hidden (view full) --- 468 VI_LOCK(vp); 469 vp->v_vnlock = ITOV(xp)->v_vnlock; 470 VI_UNLOCK(devvp); 471 } else { 472 struct lock *lkp; 473 474 VI_UNLOCK(devvp); 475 MALLOC(lkp, struct lock *, sizeof(struct lock), M_UFSMNT, |
476 M_WAITOK); | 476 0); |
477 lockinit(lkp, PVFS, "snaplk", VLKTIMEOUT, 478 LK_CANRECURSE | LK_NOPAUSE); 479 VI_LOCK(vp); 480 vp->v_vnlock = lkp; 481 } 482 vn_lock(vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY, td); 483 transferlockers(&vp->v_lock, vp->v_vnlock); 484 lockmgr(&vp->v_lock, LK_RELEASE, NULL, td); --- 46 unchanged lines hidden (view full) --- 531 } 532 } 533 /* 534 * Allocate the space for the list of preallocated snapshot blocks. 535 */ 536 snaplistsize = fs->fs_ncg + howmany(fs->fs_cssize, fs->fs_bsize) + 537 FSMAXSNAP + 1 /* superblock */ + 1 /* last block */ + 1 /* size */; 538 MALLOC(snapblklist, daddr_t *, snaplistsize * sizeof(daddr_t), | 477 lockinit(lkp, PVFS, "snaplk", VLKTIMEOUT, 478 LK_CANRECURSE | LK_NOPAUSE); 479 VI_LOCK(vp); 480 vp->v_vnlock = lkp; 481 } 482 vn_lock(vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY, td); 483 transferlockers(&vp->v_lock, vp->v_vnlock); 484 lockmgr(&vp->v_lock, LK_RELEASE, NULL, td); --- 46 unchanged lines hidden (view full) --- 531 } 532 } 533 /* 534 * Allocate the space for the list of preallocated snapshot blocks. 535 */ 536 snaplistsize = fs->fs_ncg + howmany(fs->fs_cssize, fs->fs_bsize) + 537 FSMAXSNAP + 1 /* superblock */ + 1 /* last block */ + 1 /* size */; 538 MALLOC(snapblklist, daddr_t *, snaplistsize * sizeof(daddr_t), |
539 M_UFSMNT, M_WAITOK); | 539 M_UFSMNT, 0); |
540 ip->i_snapblklist = &snapblklist[1]; 541 /* 542 * Expunge the blocks used by the snapshots from the set of 543 * blocks marked as used in the snapshot bitmaps. Also, collect 544 * the list of allocated blocks in i_snapblklist. 545 */ 546 if (ip->i_ump->um_fstype == UFS1) 547 error = expunge_ufs1(vp, ip, copy_fs, mapacct_ufs1, BLK_SNAP); --- 319 unchanged lines hidden (view full) --- 867 return (error); 868 } 869 /* 870 * Account for the block pointers in this indirect block. 871 */ 872 last = howmany(remblks, blksperindir); 873 if (last > NINDIR(fs)) 874 last = NINDIR(fs); | 540 ip->i_snapblklist = &snapblklist[1]; 541 /* 542 * Expunge the blocks used by the snapshots from the set of 543 * blocks marked as used in the snapshot bitmaps. Also, collect 544 * the list of allocated blocks in i_snapblklist. 545 */ 546 if (ip->i_ump->um_fstype == UFS1) 547 error = expunge_ufs1(vp, ip, copy_fs, mapacct_ufs1, BLK_SNAP); --- 319 unchanged lines hidden (view full) --- 867 return (error); 868 } 869 /* 870 * Account for the block pointers in this indirect block. 871 */ 872 last = howmany(remblks, blksperindir); 873 if (last > NINDIR(fs)) 874 last = NINDIR(fs); |
875 MALLOC(bap, ufs1_daddr_t *, fs->fs_bsize, M_DEVBUF, M_WAITOK); | 875 MALLOC(bap, ufs1_daddr_t *, fs->fs_bsize, M_DEVBUF, 0); |
876 bcopy(bp->b_data, (caddr_t)bap, fs->fs_bsize); 877 bqrelse(bp); 878 error = (*acctfunc)(snapvp, &bap[0], &bap[last], fs, 879 level == 0 ? rlbn : -1, expungetype); 880 if (error || level == 0) 881 goto out; 882 /* 883 * Account for the block pointers in each of the indirect blocks --- 258 unchanged lines hidden (view full) --- 1142 return (error); 1143 } 1144 /* 1145 * Account for the block pointers in this indirect block. 1146 */ 1147 last = howmany(remblks, blksperindir); 1148 if (last > NINDIR(fs)) 1149 last = NINDIR(fs); | 876 bcopy(bp->b_data, (caddr_t)bap, fs->fs_bsize); 877 bqrelse(bp); 878 error = (*acctfunc)(snapvp, &bap[0], &bap[last], fs, 879 level == 0 ? rlbn : -1, expungetype); 880 if (error || level == 0) 881 goto out; 882 /* 883 * Account for the block pointers in each of the indirect blocks --- 258 unchanged lines hidden (view full) --- 1142 return (error); 1143 } 1144 /* 1145 * Account for the block pointers in this indirect block. 1146 */ 1147 last = howmany(remblks, blksperindir); 1148 if (last > NINDIR(fs)) 1149 last = NINDIR(fs); |
1150 MALLOC(bap, ufs2_daddr_t *, fs->fs_bsize, M_DEVBUF, M_WAITOK); | 1150 MALLOC(bap, ufs2_daddr_t *, fs->fs_bsize, M_DEVBUF, 0); |
1151 bcopy(bp->b_data, (caddr_t)bap, fs->fs_bsize); 1152 bqrelse(bp); 1153 error = (*acctfunc)(snapvp, &bap[0], &bap[last], fs, 1154 level == 0 ? rlbn : -1, expungetype); 1155 if (error || level == 0) 1156 goto out; 1157 /* 1158 * Account for the block pointers in each of the indirect blocks --- 567 unchanged lines hidden (view full) --- 1726 VI_LOCK(vp); 1727 vp->v_vnlock = ITOV(xp)->v_vnlock; 1728 VI_UNLOCK(devvp); 1729 } else { 1730 struct lock *lkp; 1731 1732 VI_UNLOCK(devvp); 1733 MALLOC(lkp, struct lock *, sizeof(struct lock), | 1151 bcopy(bp->b_data, (caddr_t)bap, fs->fs_bsize); 1152 bqrelse(bp); 1153 error = (*acctfunc)(snapvp, &bap[0], &bap[last], fs, 1154 level == 0 ? rlbn : -1, expungetype); 1155 if (error || level == 0) 1156 goto out; 1157 /* 1158 * Account for the block pointers in each of the indirect blocks --- 567 unchanged lines hidden (view full) --- 1726 VI_LOCK(vp); 1727 vp->v_vnlock = ITOV(xp)->v_vnlock; 1728 VI_UNLOCK(devvp); 1729 } else { 1730 struct lock *lkp; 1731 1732 VI_UNLOCK(devvp); 1733 MALLOC(lkp, struct lock *, sizeof(struct lock), |
1734 M_UFSMNT, M_WAITOK); | 1734 M_UFSMNT, 0); |
1735 lockinit(lkp, PVFS, "snaplk", VLKTIMEOUT, 1736 LK_CANRECURSE | LK_NOPAUSE); 1737 VI_LOCK(vp); 1738 vp->v_vnlock = lkp; 1739 } 1740 vn_lock(vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY, td); 1741 transferlockers(&vp->v_lock, vp->v_vnlock); 1742 lockmgr(&vp->v_lock, LK_RELEASE, NULL, td); --- 31 unchanged lines hidden (view full) --- 1774 auio.uio_td = td; 1775 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); 1776 if ((error = VOP_READ(vp, &auio, IO_UNIT, td->td_ucred)) != 0) { 1777 printf("ffs_snapshot_mount: read_1 failed %d\n", error); 1778 VOP_UNLOCK(vp, 0, td); 1779 return; 1780 } 1781 MALLOC(snapblklist, void *, snaplistsize * sizeof(daddr_t), | 1735 lockinit(lkp, PVFS, "snaplk", VLKTIMEOUT, 1736 LK_CANRECURSE | LK_NOPAUSE); 1737 VI_LOCK(vp); 1738 vp->v_vnlock = lkp; 1739 } 1740 vn_lock(vp, LK_INTERLOCK | LK_EXCLUSIVE | LK_RETRY, td); 1741 transferlockers(&vp->v_lock, vp->v_vnlock); 1742 lockmgr(&vp->v_lock, LK_RELEASE, NULL, td); --- 31 unchanged lines hidden (view full) --- 1774 auio.uio_td = td; 1775 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); 1776 if ((error = VOP_READ(vp, &auio, IO_UNIT, td->td_ucred)) != 0) { 1777 printf("ffs_snapshot_mount: read_1 failed %d\n", error); 1778 VOP_UNLOCK(vp, 0, td); 1779 return; 1780 } 1781 MALLOC(snapblklist, void *, snaplistsize * sizeof(daddr_t), |
1782 M_UFSMNT, M_WAITOK); | 1782 M_UFSMNT, 0); |
1783 auio.uio_iovcnt = 1; 1784 aiov.iov_base = snapblklist; 1785 aiov.iov_len = snaplistsize * sizeof (daddr_t); 1786 auio.uio_resid = aiov.iov_len; 1787 auio.uio_offset -= sizeof(snaplistsize); 1788 if ((error = VOP_READ(vp, &auio, IO_UNIT, td->td_ucred)) != 0) { 1789 printf("ffs_snapshot_mount: read_2 failed %d\n", error); 1790 VOP_UNLOCK(vp, 0, td); --- 254 unchanged lines hidden --- | 1783 auio.uio_iovcnt = 1; 1784 aiov.iov_base = snapblklist; 1785 aiov.iov_len = snaplistsize * sizeof (daddr_t); 1786 auio.uio_resid = aiov.iov_len; 1787 auio.uio_offset -= sizeof(snaplistsize); 1788 if ((error = VOP_READ(vp, &auio, IO_UNIT, td->td_ucred)) != 0) { 1789 printf("ffs_snapshot_mount: read_2 failed %d\n", error); 1790 VOP_UNLOCK(vp, 0, td); --- 254 unchanged lines hidden --- |