diff mbox

[v5,4/4] rbd: Add bdrv_truncate implementation

Message ID 1306355687-4647-5-git-send-email-josh.durgin@dreamhost.com (mailing list archive)
State New, archived
Headers show

Commit Message

Josh Durgin May 25, 2011, 8:34 p.m. UTC
Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
---
 block/rbd.c |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

Comments

Kevin Wolf May 26, 2011, 8:05 a.m. UTC | #1
Am 25.05.2011 22:34, schrieb Josh Durgin:
> Signed-off-by: Josh Durgin <josh.durgin@dreamhost.com>
> ---
>  block/rbd.c |   15 +++++++++++++++
>  1 files changed, 15 insertions(+), 0 deletions(-)
> 
> diff --git a/block/rbd.c b/block/rbd.c
> index a44d160..b95b1eb 100644
> --- a/block/rbd.c
> +++ b/block/rbd.c
> @@ -688,6 +688,20 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
>      return info.size;
>  }
>  
> +static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset)
> +{
> +    BDRVRBDState *s = bs->opaque;
> +    int r;
> +
> +    r = rbd_resize(s->image, offset);
> +    if (r < 0) {
> +        error_report("failed to resize rbd image");
> +        return -EIO;
> +    }

Don't print an error message here. The caller will do it, too, so we end
up with two error messages saying the same.

What kind of error code does rbd_resize return? If it is a valid errno
value, you should return r instead of turning it into EIO.

Kevin
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Josh Durgin May 26, 2011, 11:09 p.m. UTC | #2
On 05/26/2011 01:05 AM, Kevin Wolf wrote:
> Am 25.05.2011 22:34, schrieb Josh Durgin:
>> Signed-off-by: Josh Durgin<josh.durgin@dreamhost.com>
>> ---
>>   block/rbd.c |   15 +++++++++++++++
>>   1 files changed, 15 insertions(+), 0 deletions(-)
>>
>> diff --git a/block/rbd.c b/block/rbd.c
>> index a44d160..b95b1eb 100644
>> --- a/block/rbd.c
>> +++ b/block/rbd.c
>> @@ -688,6 +688,20 @@ static int64_t qemu_rbd_getlength(BlockDriverState *bs)
>>       return info.size;
>>   }
>>
>> +static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset)
>> +{
>> +    BDRVRBDState *s = bs->opaque;
>> +    int r;
>> +
>> +    r = rbd_resize(s->image, offset);
>> +    if (r<  0) {
>> +        error_report("failed to resize rbd image");
>> +        return -EIO;
>> +    }
>
> Don't print an error message here. The caller will do it, too, so we end
> up with two error messages saying the same.

Fixed.

> What kind of error code does rbd_resize return? If it is a valid errno
> value, you should return r instead of turning it into EIO.
>
> Kevin

The error code is a standard errno value.

Josh
--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/block/rbd.c b/block/rbd.c
index a44d160..b95b1eb 100644
--- a/block/rbd.c
+++ b/block/rbd.c
@@ -688,6 +688,20 @@  static int64_t qemu_rbd_getlength(BlockDriverState *bs)
     return info.size;
 }
 
+static int qemu_rbd_truncate(BlockDriverState *bs, int64_t offset)
+{
+    BDRVRBDState *s = bs->opaque;
+    int r;
+
+    r = rbd_resize(s->image, offset);
+    if (r < 0) {
+        error_report("failed to resize rbd image");
+        return -EIO;
+    }
+
+    return 0;
+}
+
 static int qemu_rbd_snap_create(BlockDriverState *bs,
                                 QEMUSnapshotInfo *sn_info)
 {
@@ -784,6 +798,7 @@  static BlockDriver bdrv_rbd = {
     .bdrv_get_info      = qemu_rbd_getinfo,
     .create_options     = qemu_rbd_create_options,
     .bdrv_getlength     = qemu_rbd_getlength,
+    .bdrv_truncate      = qemu_rbd_truncate,
     .protocol_name      = "rbd",
 
     .bdrv_aio_readv     = qemu_rbd_aio_readv,