diff --git a/common/device-scan.c b/common/device-scan.c index c04c2388..39669ae1 100644 --- a/common/device-scan.c +++ b/common/device-scan.c @@ -208,7 +208,11 @@ int btrfs_add_to_fsid(struct btrfs_trans_handle *trans, ret = sbwrite(fd, buf, BTRFS_SUPER_INFO_OFFSET); /* Ensure super block was written to the device */ - BUG_ON(ret != BTRFS_SUPER_INFO_SIZE); + if (ret != BTRFS_SUPER_INFO_SIZE) { + error_msg(ERROR_MSG_WRITE, "superblock when adding device: %m"); + ret = -EIO; + goto out; + } free(buf); list_add(&device->dev_list, &fs_info->fs_devices->devices); device->fs_devices = fs_info->fs_devices; diff --git a/common/messages.c b/common/messages.c index 2970122a..a349965b 100644 --- a/common/messages.c +++ b/common/messages.c @@ -25,6 +25,8 @@ static const char *common_error_string[] = { [ERROR_MSG_START_TRANS] = "failed to start transaction", [ERROR_MSG_COMMIT_TRANS] = "failed to commit transaction", [ERROR_MSG_UNEXPECTED] = "unexpected condition, probably corruption", + [ERROR_MSG_READ] = "write() failed", + [ERROR_MSG_WRITE] = "read() failed", }; __attribute__ ((format (printf, 1, 2))) diff --git a/common/messages.h b/common/messages.h index 511b949c..d6d4044d 100644 --- a/common/messages.h +++ b/common/messages.h @@ -191,6 +191,8 @@ enum common_error { ERROR_MSG_START_TRANS, ERROR_MSG_COMMIT_TRANS, ERROR_MSG_UNEXPECTED, + ERROR_MSG_READ, + ERROR_MSG_WRITE, }; __attribute__ ((format (printf, 2, 3)))