# HG changeset patch # User Josef 'Jeff' Sipek # Date 1671496720 18000 # Node ID 45a236e09b4312353f03dac1f88211bdf75c4c60 # Parent 2488b36da4a8df75a539b58a7be776784c7a8a5d objstore: move objstore_{get,set}attr to obj_attr.c Signed-off-by: Josef 'Jeff' Sipek diff -r 2488b36da4a8 -r 45a236e09b43 src/objstore/obj_attr.c --- a/src/objstore/obj_attr.c Mon Dec 19 19:35:04 2022 -0500 +++ b/src/objstore/obj_attr.c Mon Dec 19 19:38:40 2022 -0500 @@ -94,3 +94,108 @@ txn_log_entry(txn, entry); } + +int objstore_getattr(struct objstore_open_obj_info *open, struct nattr *attr) +{ + struct obj *obj; + + if (!open || !attr) + return -EINVAL; + + obj = open->obj; + + MXLOCK(&obj->lock); + *attr = open->ver->attrs; + MXUNLOCK(&obj->lock); + + /* sanity check that the backend didn't try to give us an inode number */ + ASSERT0(attr->ino); + + return 0; +} + +int objstore_setattr(struct objstore_open_obj_info *open, struct nattr *attr, + const unsigned valid) +{ + struct objver *newver; + struct obj *obj; + struct txn *txn; + int ret; + + if (!open || !attr) + return -EINVAL; + + obj = open->obj; + + if (!obj->ops || !obj->ops->setattr) + return -ENOTSUP; + + if (open->qualified) + return -EROFS; + + /* clear whatever garbage the user may have supplied */ + attr->ino = 0; + + MXLOCK(&obj->lock); + + /* + * first do some checks + */ + + /* we can't truncate anything other than regular files */ + if ((valid & OBJ_ATTR_SIZE) && !NATTR_ISREG(open->ver->attrs.mode)) { + ret = -EINVAL; + goto err; + } + + if (valid & OBJ_ATTR_MODE) { + const uint16_t current_mode = open->ver->attrs.mode; + + /* if we didn't get a type, copy it from the obj */ + if (_NATTR_ISNOTYPE(attr->mode)) + attr->mode |= current_mode & NATTR_TMASK; + + /* we can't change the type of the object */ + if ((attr->mode & NATTR_TMASK) != (current_mode & NATTR_TMASK)) { + ret = -EINVAL; + goto err; + } + } + + /* + * fire off the txn + */ + + txn = txn_begin(obj->clone); + if (IS_ERR(txn)) { + ret = PTR_ERR(txn); + goto err; + } + + newver = obj_cow(txn, open); + if (IS_ERR(newver)) { + ret = PTR_ERR(newver); + goto err_txn; + } + + obj_setattr(txn, newver, attr, valid); + + ret = 0; + +err_txn: + ret = txn_commitabort(txn, ret); + newver = NULL; /* prevent accidental use */ + + /* return current attributes */ + *attr = open->ver->attrs; + +err: + MXUNLOCK(&obj->lock); + + /* sanity check that the backend didn't try to give us an inode number */ + ASSERT0(attr->ino); + + /* FIXME: safely copy attrs to open->ver.attrs */ + + return ret; +} diff -r 2488b36da4a8 -r 45a236e09b43 src/objstore/obj_ops.c --- a/src/objstore/obj_ops.c Mon Dec 19 19:35:04 2022 -0500 +++ b/src/objstore/obj_ops.c Mon Dec 19 19:38:40 2022 -0500 @@ -166,111 +166,6 @@ return ret; } -int objstore_getattr(struct objstore_open_obj_info *open, struct nattr *attr) -{ - struct obj *obj; - - if (!open || !attr) - return -EINVAL; - - obj = open->obj; - - MXLOCK(&obj->lock); - *attr = open->ver->attrs; - MXUNLOCK(&obj->lock); - - /* sanity check that the backend didn't try to give us an inode number */ - ASSERT0(attr->ino); - - return 0; -} - -int objstore_setattr(struct objstore_open_obj_info *open, struct nattr *attr, - const unsigned valid) -{ - struct objver *newver; - struct obj *obj; - struct txn *txn; - int ret; - - if (!open || !attr) - return -EINVAL; - - obj = open->obj; - - if (!obj->ops || !obj->ops->setattr) - return -ENOTSUP; - - if (open->qualified) - return -EROFS; - - /* clear whatever garbage the user may have supplied */ - attr->ino = 0; - - MXLOCK(&obj->lock); - - /* - * first do some checks - */ - - /* we can't truncate anything other than regular files */ - if ((valid & OBJ_ATTR_SIZE) && !NATTR_ISREG(open->ver->attrs.mode)) { - ret = -EINVAL; - goto err; - } - - if (valid & OBJ_ATTR_MODE) { - const uint16_t current_mode = open->ver->attrs.mode; - - /* if we didn't get a type, copy it from the obj */ - if (_NATTR_ISNOTYPE(attr->mode)) - attr->mode |= current_mode & NATTR_TMASK; - - /* we can't change the type of the object */ - if ((attr->mode & NATTR_TMASK) != (current_mode & NATTR_TMASK)) { - ret = -EINVAL; - goto err; - } - } - - /* - * fire off the txn - */ - - txn = txn_begin(obj->clone); - if (IS_ERR(txn)) { - ret = PTR_ERR(txn); - goto err; - } - - newver = obj_cow(txn, open); - if (IS_ERR(newver)) { - ret = PTR_ERR(newver); - goto err_txn; - } - - obj_setattr(txn, newver, attr, valid); - - ret = 0; - -err_txn: - ret = txn_commitabort(txn, ret); - newver = NULL; /* prevent accidental use */ - - /* return current attributes */ - *attr = open->ver->attrs; - -err: - MXUNLOCK(&obj->lock); - - /* sanity check that the backend didn't try to give us an inode number */ - ASSERT0(attr->ino); - - /* FIXME: safely copy attrs to open->ver.attrs */ - - return ret; -} - ssize_t objstore_read(struct objstore_open_obj_info *open, void *buf, size_t len, uint64_t offset) {