Mercurial > nomad
changeset 749:ba7c47730f68
objstore: write obj op returns the number of bytes written on success
The writing of the data to the actual storage must complete fully. A
partial write is the same as an error since we were "promissed" the write
was going to happen when the transaction commit op succeeded.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sun, 29 Mar 2020 19:20:13 -0400 |
parents | f6f0d45d5db6 |
children | faa9c2c03b5a |
files | src/objstore/obj_ops.c src/objstore/txn.c |
diffstat | 2 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/objstore/obj_ops.c Sun Mar 29 19:19:44 2020 -0400 +++ b/src/objstore/obj_ops.c Sun Mar 29 19:20:13 2020 -0400 @@ -364,7 +364,13 @@ err: MXUNLOCK(&obj->lock); - /* we have to return the number of bytes written */ + /* + * We have to return the number of bytes written. + * + * Because of the transaction being atomic, we never do a partial + * write. Therefore, we either return an error or the requested + * length. + */ return ret ? ret : len; }
--- a/src/objstore/txn.c Sun Mar 29 19:19:44 2020 -0400 +++ b/src/objstore/txn.c Sun Mar 29 19:20:13 2020 -0400 @@ -213,6 +213,19 @@ buffer_data(buf), buffer_size(buf), entry->write.offset); + /* + * This is the write to the actual storage. + * At this point, we logged the write and + * the transaction committed. Therefore, we + * must write out the whole buffer. In + * other words, if we ended up with a + * parital write, we must error out - which + * will trigger a panic later in this code. + */ + if (ret == buffer_size(buf)) + ret = 0; + if (ret > 0) + ret = -EPIPE; buffer_free(buf); break;