Mercurial > nomad > experimental
changeset 1263:8d3171c87786
objstore/posix: remove hack to fill newly created dirs
In the past we needed to automatically fill the contents of a newly created
directory with entries referring to '.' and '..'. This is now handled
automatically later in the same transaction.
Unfortunately, a simplified version of the code still exists for root-object
creation.
Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author | Josef 'Jeff' Sipek <jeffpc@josefsipek.net> |
---|---|
date | Sat, 17 Dec 2022 15:40:26 -0500 |
parents | 79102a88827c |
children | 9f4bd7cfa177 |
files | src/objstore/posix/obj_create.c src/objstore/posix/posix.h src/objstore/posix/vol.c |
diffstat | 3 files changed, 34 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/objstore/posix/obj_create.c Sat Dec 17 16:08:01 2022 -0500 +++ b/src/objstore/posix/obj_create.c Sat Dec 17 15:40:26 2022 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * Copyright (c) 2018-2020,2022 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -91,10 +91,9 @@ } int create_obj(int rootfd, uint64_t this_host, uint64_t this_uniq, - uint64_t parent_host, uint64_t parent_uniq, - const struct nvclock *clock, const struct nattr *_attrs) + const struct nvclock *clock, const struct nattr *_attrs, + struct buffer *contents) { - struct buffer contents; struct nattr attrs; char objname[34]; int ret; @@ -102,60 +101,36 @@ attrs = *_attrs; - /* create empty directory contents for new directories */ - if (NATTR_ISDIR(attrs.mode)) { - ret = buffer_init_heap(&contents, BLOCK_SIZE); /* size guess */ - if (ret) - return ret; - - ret = obj_make_dir_buffer(this_host, this_uniq, parent_host, - parent_uniq, &contents); - if (ret) - goto err; - - /* overwrite the requested size */ - attrs.size = buffer_size(&contents); - } else { - /* initialize the buffer to make buffer_free work */ - buffer_init_sink(&contents); - } - snprintf(objname, sizeof(objname), "%016"PRIx64"-%016"PRIx64, this_host, this_uniq); /* create the object directory */ ret = xmkdirat(rootfd, objname, 0700); if (ret) - goto err; + return ret; /* open the object directory */ fd = xopenat(rootfd, objname, O_RDONLY, 0); if (fd < 0) { ret = fd; - goto err_unlink; + goto err; } /* create the object version file */ - ret = create_objver(fd, clock, &attrs, - NATTR_ISDIR(attrs.mode) ? &contents : NULL); + ret = create_objver(fd, clock, &attrs, contents); if (ret) goto err_close; xclose(fd); - buffer_free(&contents); - return ret; err_close: xclose(fd); -err_unlink: +err: xunlinkat(rootfd, objname, 0); -err: - buffer_free(&contents); - return ret; } @@ -166,7 +141,7 @@ struct nattr attrs = { .mode = NATTR_DIR | 0700, .nlink = 1, /* even new dirs have a link count of 1 */ - .size = 0, /* overwritten in create_obj */ + .size = 0, /* overwritten below */ .atime = now, .btime = now, .ctime = now, @@ -175,9 +150,30 @@ .group = 0, }; struct nvclock clock; + struct buffer contents; + int ret; nvclock_reset(&clock); VERIFY0(nvclock_inc(&clock)); - return create_obj(rootfd, host, uniq, host, uniq, &clock, &attrs); + /* + * construct an empty directory + */ + ret = buffer_init_heap(&contents, BLOCK_SIZE); /* size guess */ + if (ret) + return ret; + + ret = obj_make_dir_buffer(host, uniq, host, uniq, &contents); + if (ret) + goto err; + + /* overwrite the requested size */ + attrs.size = buffer_size(&contents); + + ret = create_obj(rootfd, host, uniq, &clock, &attrs, &contents); + +err: + buffer_free(&contents); + + return ret; }
--- a/src/objstore/posix/posix.h Sat Dec 17 16:08:01 2022 -0500 +++ b/src/objstore/posix/posix.h Sat Dec 17 15:40:26 2022 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> + * Copyright (c) 2018-2020,2022 Josef 'Jeff' Sipek <jeffpc@josefsipek.net> * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -161,8 +161,8 @@ extern const struct clone_ops posix_clone_ops; extern int create_obj(int rootfd, uint64_t host, uint64_t uniq, - uint64_t parent_host, uint64_t parent_uniq, - const struct nvclock *clock, const struct nattr *attrs); + const struct nvclock *clock, const struct nattr *attrs, + struct buffer *contents); extern int create_rootdir(int rootfd, uint64_t host, uint64_t uniq); extern int write_ver_header(struct objver *ver, int fd,
--- a/src/objstore/posix/vol.c Sat Dec 17 16:08:01 2022 -0500 +++ b/src/objstore/posix/vol.c Sat Dec 17 15:40:26 2022 -0500 @@ -110,8 +110,7 @@ return create_obj(pvol->rootfd, noid_get_allocator(oid), noid_get_uniq(oid), - noid_get_allocator(parent), noid_get_uniq(parent), - clock, attrs); + clock, attrs, NULL); } const struct clone_ops posix_clone_ops = {