[sheepdog] [PATCH v3 2/5] md: fix a fatal bug in check_and_move()
MORITA Kazutaka
morita.kazutaka at gmail.com
Wed Apr 17 18:03:33 CEST 2013
At Wed, 17 Apr 2013 23:50:38 +0800,
Liu Yuan wrote:
>
> From: Liu Yuan <tailai.ly at taobao.com>
>
> We can't rename(2) objects accross devices and this will cause recovery to fail.
>
> Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
> ---
> sheep/md.c | 39 +++++++++++++++++++++++++++++++++++++--
> 1 file changed, 37 insertions(+), 2 deletions(-)
>
> diff --git a/sheep/md.c b/sheep/md.c
> index 0bfadd0..d3c1bee 100644
> --- a/sheep/md.c
> +++ b/sheep/md.c
> @@ -22,9 +22,11 @@
> #include <dirent.h>
> #include <pthread.h>
> #include <string.h>
> +#include <fcntl.h>
>
> #include "sheep_priv.h"
> #include "util.h"
> +#include "strbuf.h"
>
> #define MD_DEFAULT_VDISKS 128
> #define MD_MAX_VDISK (MD_MAX_DISK * MD_DEFAULT_VDISKS)
> @@ -474,6 +476,38 @@ static int get_old_new_path(uint64_t oid, uint32_t epoch, char *path,
> return 0;
> }
>
> +static int move_object(uint64_t oid, char *old, char *new)
> +{
> + struct strbuf buf = STRBUF_INIT;
> + int fd, ret = -1;
> +
> + fd = open(old, O_RDONLY);
> + if (fd < 0) {
> + sd_eprintf("failed to open %s", old);
> + goto out;
> + }
> +
> + ret = strbuf_read(&buf, fd, SD_INODE_SIZE);
This assumes that SD_INODE_SIZE is the longest object size. It is
true, but might be wrong in future. I think using get_objsize(oid)
instead is safer.
Thanks,
Kazutaka
More information about the sheepdog
mailing list