improved log write semantics on configured logs.

This commit is contained in:
nvt-se 2008-10-16 09:58:57 +00:00
parent 75f036f698
commit 77c72f4588

View file

@ -735,7 +735,7 @@ write_log_page(struct file_desc *fdp, struct log_param *lp)
lp_out.buf = copy_buf; lp_out.buf = copy_buf;
lp_out.size = log_entry_size; lp_out.size = log_entry_size;
if(lp->offset > 0 && if((lp->offset > 0 || log_entry_size == COFFEE_PAGE_SIZE) &&
read_log_page(&hdr, fdp->next_log_entry > 0 ? fdp->next_log_entry - 1 : -1, &lp_out) < 0) { read_log_page(&hdr, fdp->next_log_entry > 0 ? fdp->next_log_entry - 1 : -1, &lp_out) < 0) {
COFFEE_READ(copy_buf, sizeof(copy_buf), COFFEE_READ(copy_buf, sizeof(copy_buf),
ABS_OFFSET(fdp->file_page, page * log_entry_size)); ABS_OFFSET(fdp->file_page, page * log_entry_size));
@ -936,6 +936,7 @@ cfs_write(int fd, const void *buf, unsigned size)
struct file_desc *fdp; struct file_desc *fdp;
int i; int i;
struct log_param lp; struct log_param lp;
coffee_offset_t remains;
if(!(FD_VALID(fd) && FD_WRITABLE(fd))) { if(!(FD_VALID(fd) && FD_WRITABLE(fd))) {
return -1; return -1;
@ -950,23 +951,29 @@ cfs_write(int fd, const void *buf, unsigned size)
} }
if(fdp->offset < fdp->end) { if(fdp->offset < fdp->end) {
remains = size;
while(remains) {
lp.offset = fdp->offset; lp.offset = fdp->offset;
lp.buf = buf; lp.buf = buf;
lp.size = size; lp.size = remains;
size = write_log_page(fdp, &lp); i = write_log_page(fdp, &lp);
if(size == 0) { if(i == 0) {
/* The log got flushed. Try again. */ /* The log got flushed. Try again. */
size = write_log_page(fdp, &lp); i = write_log_page(fdp, &lp);
} }
if(size < 0) { if(i < 0) {
return -1; return size - remains > 0 ? size - remains : -1;
}
remains -= i;
fdp->offset += i;
} }
} else { } else {
COFFEE_WRITE(buf, size, COFFEE_WRITE(buf, size,
ABS_OFFSET(fdp->file_page, fdp->offset)); ABS_OFFSET(fdp->file_page, fdp->offset));
}
fdp->offset += size; fdp->offset += size;
}
if(fdp->offset > fdp->end) { if(fdp->offset > fdp->end) {
/* /*
* The file has been extended and the file descriptors * The file has been extended and the file descriptors