bcon: protect log file with S_SWAPFILE

Prevents truncation and also handles the case of trying to use the same
logfile twice without hanging.

Signed-off-by: Joern Engel <joern@logfs.org>
diff --git a/drivers/block/blockconsole.c b/drivers/block/blockconsole.c
index a760c3a..efa87f3 100644
--- a/drivers/block/blockconsole.c
+++ b/drivers/block/blockconsole.c
@@ -656,6 +656,10 @@
 	} else if (S_ISREG(inode->i_mode)) {
 		bc->bdev = inode->i_sb->s_bdev;
 		mutex_lock(&inode->i_mutex);
+		if (IS_SWAPFILE(inode)) {
+			mutex_unlock(&inode->i_mutex);
+			return -EBUSY;
+		}
 		return create_extent_map(bc, inode);
 	} else
 		return -EINVAL;
@@ -667,7 +671,6 @@
 	if (S_ISBLK(inode->i_mode))
 		blkdev_put(bc->bdev, FMODE_READ | FMODE_WRITE);
 	else {
-		inode->i_flags &= ~S_SWAPFILE;
 		mutex_unlock(&inode->i_mutex);
 	}
 }
@@ -748,6 +751,11 @@
 	err = __bcon_create(bc);
 	if (err)
 		goto out2;
+
+	if (S_ISREG(inode->i_mode)) {
+		inode->i_flags |= S_SWAPFILE;
+		mutex_unlock(&inode->i_mutex);
+	}
 	return err;
 
 out2: