[sheepdog] [PATCH 1/2] sheep: journaling epoch file write
Hitoshi Mitake
mitake.hitoshi at gmail.com
Thu Apr 4 09:18:06 CEST 2013
At Wed, 3 Apr 2013 15:06:16 +0800,
Liu Yuan wrote:
>
> From: Liu Yuan <tailai.ly at taobao.com>
>
> Also bundle two writes into one.
>
> Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
> ---
> sheep/store.c | 31 +++++++++++++++++++------------
> 1 file changed, 19 insertions(+), 12 deletions(-)
>
> diff --git a/sheep/store.c b/sheep/store.c
> index 5b1e457..f112751 100644
> --- a/sheep/store.c
> +++ b/sheep/store.c
> @@ -39,28 +39,35 @@ LIST_HEAD(store_drivers);
>
> int update_epoch_log(uint32_t epoch, struct sd_node *nodes, size_t nr_nodes)
> {
> - int fd, ret, len;
> + int fd, ret, len, nodes_len, flags = O_RDWR | O_CREAT | O_DSYNC;
> time_t t;
> - char path[PATH_MAX];
> + char path[PATH_MAX], *buf;
>
> sd_dprintf("update epoch: %d, %zd", epoch, nr_nodes);
>
> + /* Piggyback the epoch creation time for 'collie cluster info' */
> + time(&t);
> + nodes_len = nr_nodes * sizeof(struct sd_node);
> + len = nodes_len + sizeof(time_t);
> + buf = xmalloc(len);
> + memcpy(buf, nodes, nodes_len);
> + memcpy(buf + nodes_len, &t, sizeof(time_t));
> +
> + if (uatomic_is_true(&sys->use_journal) &&
> + journal_write_epoch(buf, len, epoch) != SD_RES_SUCCESS) {
> + sd_eprintf("turn off journaling");
> + uatomic_set_false(&sys->use_journal);
> + sync();
> + }
> +
> snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
> - fd = open(path, O_RDWR | O_CREAT | O_DSYNC, def_fmode);
> + fd = open(path, flags, def_fmode);
> if (fd < 0) {
> ret = fd;
> goto err_open;
> }
>
> - len = nr_nodes * sizeof(struct sd_node);
> - ret = xwrite(fd, (char *)nodes, len);
> - if (ret != len)
> - goto err;
> -
> - /* Piggyback the epoch creation time for 'collie cluster info' */
> - time(&t);
> - len = sizeof(t);
> - ret = xwrite(fd, (char *)&t, len);
> + ret = xwrite(fd, buf, len);
> if (ret != len)
> goto err;
>
update_epoch_log() seems to lack free(buf);
Thanks,
Hitoshi
More information about the sheepdog
mailing list