X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=src%2Fcommon%2Ffd-tracker%2Finode.c;h=182c84a6bb6a978ca03980e2a9c19cd9f9f40026;hb=a0377dfefe40662ba7d68617bce6ff467114136c;hp=b894f8fbf6d6d41073cd14a94ea63a5d7285e3b0;hpb=d05a3d937ddc2b666b153e6adaf9610800772b68;p=lttng-tools.git diff --git a/src/common/fd-tracker/inode.c b/src/common/fd-tracker/inode.c index b894f8fbf..182c84a6b 100644 --- a/src/common/fd-tracker/inode.c +++ b/src/common/fd-tracker/inode.c @@ -114,7 +114,7 @@ static int lttng_unlinked_file_pool_add_inode( if (pool->file_count == 0) { DBG("Creating unlinked files directory at %s", pool->unlink_directory_path); - assert(!pool->unlink_directory_handle); + LTTNG_ASSERT(!pool->unlink_directory_handle); ret = utils_mkdir(pool->unlink_directory_path, S_IRWXU | S_IRWXG, -1, -1); if (ret) { @@ -152,7 +152,7 @@ static int lttng_unlinked_file_pool_add_inode( inode->location.directory_handle = NULL; reference_acquired = lttng_directory_handle_get( pool->unlink_directory_handle); - assert(reference_acquired); + LTTNG_ASSERT(reference_acquired); inode->location.directory_handle = pool->unlink_directory_handle; free(inode->location.path); @@ -217,8 +217,8 @@ static void lttng_inode_destroy(struct lttng_inode *inode) if (inode->unlink_pending) { int ret; - assert(inode->location.directory_handle); - assert(inode->location.path); + LTTNG_ASSERT(inode->location.directory_handle); + LTTNG_ASSERT(inode->location.path); DBG("Removing %s from unlinked file pool", inode->location.path); ret = lttng_unlinked_file_pool_remove_inode(inode->unlinked_file_pool, inode); @@ -245,11 +245,15 @@ static void lttng_inode_get(struct lttng_inode *inode) urcu_ref_get(&inode->ref); } -struct lttng_unlinked_file_pool *lttng_unlinked_file_pool_create( +LTTNG_HIDDEN struct lttng_unlinked_file_pool *lttng_unlinked_file_pool_create( const char *path) { struct lttng_unlinked_file_pool *pool = zmalloc(sizeof(*pool)); + if (!pool) { + goto error; + } + if (!path || *path != '/') { ERR("Unlinked file pool must be created with an absolute path, path = \"%s\"", path ? path : "NULL"); @@ -268,37 +272,38 @@ error: return NULL; } -void lttng_unlinked_file_pool_destroy( +LTTNG_HIDDEN void lttng_unlinked_file_pool_destroy( struct lttng_unlinked_file_pool *pool) { if (!pool) { return; } - assert(pool->file_count == 0); + LTTNG_ASSERT(pool->file_count == 0); lttng_directory_handle_put(pool->unlink_directory_handle); free(pool->unlink_directory_path); free(pool); } -void lttng_inode_put(struct lttng_inode *inode) +LTTNG_HIDDEN void lttng_inode_put(struct lttng_inode *inode) { urcu_ref_put(&inode->ref, lttng_inode_release); } -struct lttng_directory_handle *lttng_inode_get_location_directory_handle( +LTTNG_HIDDEN struct lttng_directory_handle * +lttng_inode_get_location_directory_handle( struct lttng_inode *inode) { if (inode->location.directory_handle) { const bool reference_acquired = lttng_directory_handle_get( inode->location.directory_handle); - assert(reference_acquired); + LTTNG_ASSERT(reference_acquired); } return inode->location.directory_handle; } -void lttng_inode_borrow_location(struct lttng_inode *inode, +LTTNG_HIDDEN void lttng_inode_borrow_location(struct lttng_inode *inode, const struct lttng_directory_handle **out_directory_handle, const char **out_path) { @@ -310,7 +315,7 @@ void lttng_inode_borrow_location(struct lttng_inode *inode, } } -int lttng_inode_rename( +LTTNG_HIDDEN int lttng_inode_rename( struct lttng_inode *inode, struct lttng_directory_handle *old_directory_handle, const char *old_path, @@ -368,7 +373,7 @@ int lttng_inode_rename( } reference_acquired = lttng_directory_handle_get(new_directory_handle); - assert(reference_acquired); + LTTNG_ASSERT(reference_acquired); lttng_directory_handle_put(inode->location.directory_handle); free(inode->location.path); inode->location.directory_handle = new_directory_handle; @@ -380,7 +385,7 @@ end: return ret; } -int lttng_inode_unlink(struct lttng_inode *inode) +LTTNG_HIDDEN int lttng_inode_unlink(struct lttng_inode *inode) { int ret = 0; @@ -425,7 +430,7 @@ static struct lttng_inode *lttng_inode_create(const struct inode_id *id, } reference_acquired = lttng_directory_handle_get(directory_handle); - assert(reference_acquired); + LTTNG_ASSERT(reference_acquired); inode = zmalloc(sizeof(*inode)); if (!inode) { @@ -446,7 +451,7 @@ end: return inode; } -struct lttng_inode_registry *lttng_inode_registry_create(void) +LTTNG_HIDDEN struct lttng_inode_registry *lttng_inode_registry_create(void) { struct lttng_inode_registry *registry = zmalloc(sizeof(*registry)); @@ -473,7 +478,8 @@ error: return NULL; } -void lttng_inode_registry_destroy(struct lttng_inode_registry *registry) +LTTNG_HIDDEN void lttng_inode_registry_destroy( + struct lttng_inode_registry *registry) { if (!registry) { return; @@ -481,12 +487,12 @@ void lttng_inode_registry_destroy(struct lttng_inode_registry *registry) if (registry->inodes) { int ret = cds_lfht_destroy(registry->inodes, NULL); - assert(!ret); + LTTNG_ASSERT(!ret); } free(registry); } -struct lttng_inode *lttng_inode_registry_get_inode( +LTTNG_HIDDEN struct lttng_inode *lttng_inode_registry_get_inode( struct lttng_inode_registry *registry, struct lttng_directory_handle *handle, const char *path, @@ -522,10 +528,14 @@ struct lttng_inode *lttng_inode_registry_get_inode( inode = lttng_inode_create(&id, registry->inodes, unlinked_file_pool, handle, path); + if (!inode) { + goto end_unlock; + } + node = cds_lfht_add_unique(registry->inodes, lttng_inode_id_hash(&inode->id), lttng_inode_match, &inode->id, &inode->registry_node); - assert(node == &inode->registry_node); + LTTNG_ASSERT(node == &inode->registry_node); end_unlock: rcu_read_unlock(); end: