Mercurial > nomad
changeset 760:2d794f76bd06
objstore: move write transaction op setup into a separate function
This reduces code duplication.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Mon, 30 Mar 2020 09:58:22 -0400 |
parents | 007f0df5d814 |
children | 44f88c8abb28 |
files | src/objstore/obj_dir_create.c src/objstore/obj_ops.c src/objstore/obj_txn.c src/objstore/objstore_impl.h |
diffstat | 4 files changed, 19 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/src/objstore/obj_dir_create.c Mon Mar 30 09:52:46 2020 -0400 +++ b/src/objstore/obj_dir_create.c Mon Mar 30 09:58:22 2020 -0400 @@ -61,7 +61,6 @@ const struct noid *parent, const struct noid *child) { - struct txn_entry *entry; struct buffer buf; int ret; @@ -79,12 +78,8 @@ return ret; } - entry = txn_alloc_entry(txn); - entry->op = OP_WRITE; FIXME("child dir write op has NULL objver"); - entry->write.ver = NULL; /* FIXME */ - entry->write.buf = buf; - entry->write.offset = 0; + obj_write(txn, NULL /* FIXME */, &buf, 0); return 0; } @@ -96,7 +91,6 @@ struct nattr attrs = { .size = dirver->attrs.size + DIR_BLOCK_SIZE, }; - struct txn_entry *entry; struct ndirent_tgt tgt; struct dirblock block; struct buffer buf; @@ -127,11 +121,7 @@ obj_setattr(txn, dirver, &attrs, OBJ_ATTR_SIZE); /* fill in the fresh block */ - entry = txn_alloc_entry(txn); - entry->op = OP_WRITE; - entry->write.ver = dirver; - entry->write.buf = buf; - entry->write.offset = dirver->attrs.size; + obj_write(txn, dirver, &buf, dirver->attrs.size); return 0;
--- a/src/objstore/obj_ops.c Mon Mar 30 09:52:46 2020 -0400 +++ b/src/objstore/obj_ops.c Mon Mar 30 09:58:22 2020 -0400 @@ -292,7 +292,7 @@ ssize_t objstore_write(struct objstore_open_obj_info *open, const void *buf, size_t len, uint64_t offset) { - struct txn_entry *entry; + struct buffer buffer; struct txn txn; struct obj *obj; ssize_t ret; @@ -343,11 +343,8 @@ obj_setattr(&txn, open->ver, &attrs, OBJ_ATTR_SIZE); } - entry = txn_alloc_entry(&txn); - entry->op = OP_WRITE; - entry->write.ver = open->ver; - buffer_init_static(&entry->write.buf, buf, len, false); - entry->write.offset = offset; + buffer_init_static(&buffer, buf, len, false); + obj_write(&txn, open->ver, &buffer, offset); err_txn: ret = txn_commitabort(&txn, ret);
--- a/src/objstore/obj_txn.c Mon Mar 30 09:52:46 2020 -0400 +++ b/src/objstore/obj_txn.c Mon Mar 30 09:58:22 2020 -0400 @@ -35,3 +35,15 @@ entry->setattr.attrs = *attrs; entry->setattr.valid = valid; } + +void obj_write(struct txn *txn, struct objver *ver, struct buffer *buf, + uint64_t offset) +{ + struct txn_entry *entry; + + entry = txn_alloc_entry(txn); + entry->op = OP_WRITE; + entry->write.ver = ver; + entry->write.buf = *buf; /* this is a hack */ + entry->write.offset = offset; +}
--- a/src/objstore/objstore_impl.h Mon Mar 30 09:52:46 2020 -0400 +++ b/src/objstore/objstore_impl.h Mon Mar 30 09:58:22 2020 -0400 @@ -67,6 +67,8 @@ extern int obj_cow(struct objstore_open_obj_info *open, struct txn *txn); extern void obj_setattr(struct txn *txn, struct objver *ver, const struct nattr *attrs, unsigned valid); +extern void obj_write(struct txn *txn, struct objver *ver, struct buffer *buf, + uint64_t offset); extern int dir_lookup_one(struct objver *dirver, const char *name, const struct noid *desired, struct noid *child,