/*
- * Copyright (C) 2020 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright (C) 2020 Jérémie Galarneau <jeremie.galarneau@efficios.com>
*
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License, version 2 only, as
- * published by the Free Software Foundation.
+ * SPDX-License-Identifier: GPL-2.0-only
*
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc., 51
- * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <common/defaults.h>
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) {
}
pool->unlink_directory_handle = lttng_directory_handle_create(
pool->unlink_directory_path);
+ if (!pool->unlink_directory_handle) {
+ ERR("Failed to create directory handle to unlinked file pool at %s",
+ pool->unlink_directory_path);
+ ret = -1;
+ goto end;
+ }
}
ret = lttng_directory_handle_rename(inode->location.directory_handle,
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);
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);
{
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");
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);
urcu_ref_put(&inode->ref, lttng_inode_release);
}
-void lttng_inode_get_location(struct lttng_inode *inode,
+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);
+
+ LTTNG_ASSERT(reference_acquired);
+ }
+ return inode->location.directory_handle;
+}
+
+void lttng_inode_borrow_location(struct lttng_inode *inode,
const struct lttng_directory_handle **out_directory_handle,
const char **out_path)
{
}
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;
}
reference_acquired = lttng_directory_handle_get(directory_handle);
- assert(reference_acquired);
+ LTTNG_ASSERT(reference_acquired);
inode = zmalloc(sizeof(*inode));
if (!inode) {
return NULL;
}
-void lttng_inode_registry_destroy(struct lttng_inode_registry *registry)
+void lttng_inode_registry_destroy(
+ struct lttng_inode_registry *registry)
{
if (!registry) {
return;
if (registry->inodes) {
int ret = cds_lfht_destroy(registry->inodes, NULL);
- assert(!ret);
+ LTTNG_ASSERT(!ret);
}
free(registry);
}
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: