From c83e05380e3934b3fe212cc97984a7c9d5e09c6f Mon Sep 17 00:00:00 2001 From: tegge Date: Sun, 14 May 2006 00:02:48 +0000 Subject: [PATCH] MFC: Detect the snapshot file being prematurely unlinked. --- sys/ufs/ffs/ffs_snapshot.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sys/ufs/ffs/ffs_snapshot.c b/sys/ufs/ffs/ffs_snapshot.c index d6c876b945d2..f11a9d713e7a 100644 --- a/sys/ufs/ffs/ffs_snapshot.c +++ b/sys/ufs/ffs/ffs_snapshot.c @@ -405,6 +405,11 @@ restart: vn_start_write(NULL, &wrtmp, V_WAIT); } vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); + if (ip->i_effnlink == 0) { + error = ENOENT; /* Snapshot file unlinked */ + sn = NULL; + goto out1; + } if (collectsnapstats) nanotime(&starttime); /* @@ -763,12 +768,17 @@ out1: * the inode for this snapshot then a deadlock can occur. Drop * the snapshot lock until the buffer has been written. */ + VREF(vp); /* Protect against ffs_snapgone() */ VOP_UNLOCK(vp, 0, td); (void) bread(ip->i_devvp, fsbtodb(fs, ino_to_fsba(fs, ip->i_number)), (int) fs->fs_bsize, NOCRED, &nbp); brelse(nbp); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td); + if (ip->i_effnlink == 0) + error = ENOENT; /* Snapshot file unlinked */ + else + vrele(vp); /* Drop extra reference */ done: FREE(copy_fs->fs_csp, M_UFSMNT); bawrite(sbp);