[sheepdog] [PATCH 5/7 v4 UPDATE] sheep: rename journal_file.c as journal.c

Hitoshi Mitake mitake.hitoshi at gmail.com
Fri Apr 5 10:51:45 CEST 2013


> -static int jrnl_write_header(struct jrnl_descriptor *jd)
> +static int do_recover(int fd)
>  {
> -	ssize_t ret;
> -	struct jrnl_head *head = (struct jrnl_head *) &jd->head;
> +	struct journal_descriptor *jd;
> +	void *map;
> +	char *p, *end;
> +	struct stat st;
>  
> -	ret = xpwrite(jd->fd, head, sizeof(*head), 0);
> +	if (fstat(fd, &st) < 0) {
> +		sd_eprintf("fstat %m");
> +		return -1;
> +	}

do_recover should return here if a condition st.st_size == 0 is true.
If st.st_size == 0, the below mmap() fails with Invalid argument.

>  
> -	if (ret != sizeof(*head)) {
> -		if (errno == ENOSPC)
> -			ret = SD_RES_NO_SPACE;
> -		else
> -			ret = SD_RES_EIO;
> -	} else
> -		ret = SD_RES_SUCCESS;
> +	map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
> +	close(fd);
> +	if (map == MAP_FAILED) {
> +		sd_eprintf("%m");
> +		return -1;
> +	}

Thanks,
Hitoshi



More information about the sheepdog mailing list