Example #1
0
int solaris_unlink (const char *path)
{
        char *mapped_path = NULL;
        struct stat     stbuf = {0, };
        int ret = -1;

        ret = solaris_xattr_resolve_path (path, &mapped_path);


        if (!ret && mapped_path) {
                if (lstat(path, &stbuf)) {
                        gf_msg (THIS->name, GF_LOG_WARNING, errno,
                                LG_MSG_FILE_OP_FAILED, "Stat failed on "
                                "mapped file %s", mapped_path);
                        goto out;
                }
                if (stbuf.st_nlink == 1) {
                        if(remove (mapped_path))
                                gf_msg (THIS->name, GF_LOG_WARNING, errno,
                                        LG_MSG_FILE_OP_FAILED, "Failed to "
                                        "remove mapped file %s", mapped_path);
                }

        }

out:
        GF_FREE (mapped_path);

        return  unlink (path);
}
Example #2
0
/**
 * _export_file_init -- Initialize an exports file structure.
 *
 * @return  : success: Pointer to an allocated exports file struct
 *            failure: NULL
 *
 * Not for external use.
 */
struct exports_file *
_exports_file_init()
{
    struct exports_file *file = NULL;

    file = GF_CALLOC(1, sizeof(*file), gf_common_mt_nfs_exports);
    if (!file) {
        gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
               "Failed to allocate file struct!");
        goto out;
    }

    file->exports_dict = dict_new();
    file->exports_map = dict_new();
    if (!file->exports_dict || !file->exports_map) {
        gf_msg(GF_EXP, GF_LOG_CRITICAL, ENOMEM, NFS_MSG_NO_MEMORY,
               "Failed to allocate dict!");
        goto free_and_out;
    }

    goto out;

free_and_out:
    if (file->exports_dict)
        dict_unref(file->exports_dict);

    GF_FREE(file);
    file = NULL;
out:
    return file;
}
Example #3
0
static int
xlator_option_validate_path (xlator_t *xl, const char *key, const char *value,
                             volume_option_t *opt, char **op_errstr)
{
        int   ret = -1;
        char  errstr[256];

        if (strstr (value, "../")) {
                snprintf (errstr, 256,
                          "invalid path given '%s'",
                          value);
                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s",
                        errstr);
                goto out;
        }

                /* Make sure the given path is valid */
        if (value[0] != '/') {
                snprintf (errstr, 256,
                          "option %s %s: '%s' is not an "
                          "absolute path name",
                          key, value, value);
                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s",
                        errstr);
                goto out;
        }

        ret = 0;
out:
        if (ret && op_errstr)
                *op_errstr = gf_strdup (errstr);
        return ret;
}
Example #4
0
/*Internal function: Used initialize/map db operation of
 * specified type of db plugin*/
static int
init_db_operations (gfdb_db_type_t       gfdb_db_type,
                    gfdb_db_operations_t *gfdb_db_operations)
{

        int ret = -1;

        GF_ASSERT (gfdb_db_operations);

        /*Clear the gfdb_db_operations*/
        gfdb_db_operations = memset(gfdb_db_operations, 0,
                                        sizeof(*gfdb_db_operations));
        switch (gfdb_db_type) {
        case GFDB_SQLITE3:
                gf_sqlite3_fill_db_operations (gfdb_db_operations);
                ret = 0;
                break;
        case GFDB_HYPERDEX:
        case GFDB_HASH_FILE_STORE:
        case GFDB_ROCKS_DB:
                gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                        LG_MSG_UNSUPPORTED_PLUGIN, "Plugin not supported");
                break;
        case GFDB_INVALID_DB:
        case GFDB_DB_END:
                gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                        LG_MSG_INVALID_DB_TYPE, "Invalid DB Type");
                break;
        }
        return ret;
}
Example #5
0
static int
xlator_option_validate_percent (xlator_t *xl, const char *key, const char *value,
                                volume_option_t *opt, char **op_errstr)
{
        double    percent = 0;
        int       ret = -1;
        char      errstr[256];

        /* Check if the value is valid percentage */
        if (gf_string2percent (value, &percent) != 0) {
                snprintf (errstr, 256,
                          "invalid percent format \"%s\" in \"option %s\"",
                          value, key);
                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s",
                        errstr);
                goto out;
        }

        if ((percent < 0.0) || (percent > 100.0)) {
                snprintf (errstr, 256,
                          "'%lf' in 'option %s %s' is out of range [0 - 100]",
                          percent, key, value);
                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_OUT_OF_RANGE, "%s",
                        errstr);
                goto out;
        }

        ret = 0;
out:
        if (ret && op_errstr)
                *op_errstr = gf_strdup (errstr);
        return ret;
}
Example #6
0
int gf_sqlite3_insert(void *db_conn, gfdb_db_record_t *gfdb_db_record)
{
        int ret                         =       -1;
        gf_sql_connection_t *sql_conn   =       db_conn;

        CHECK_SQL_CONN(sql_conn, out);
        GF_VALIDATE_OR_GOTO(GFDB_STR_SQLITE3, gfdb_db_record, out);


        switch (gfdb_db_record->gfdb_fop_path) {
        case GFDB_FOP_WIND:
                ret = gf_sql_insert_wind (sql_conn, gfdb_db_record);
                if (ret) {
                        gf_msg (GFDB_STR_SQLITE3, _gfdb_log_level (GF_LOG_ERROR,
                                gfdb_db_record->ignore_errors), 0,
                                LG_MSG_INSERT_FAILED, "Failed wind insert");
                        goto out;
                }
                break;
        case GFDB_FOP_UNWIND:
                ret = gf_sql_insert_unwind (sql_conn, gfdb_db_record);
                if (ret) {
                        gf_msg (GFDB_STR_SQLITE3, _gfdb_log_level (GF_LOG_ERROR,
                                gfdb_db_record->ignore_errors), 0,
                                LG_MSG_INSERT_FAILED, "Failed unwind insert");
                        goto out;
                }
                break;

        case GFDB_FOP_WDEL:
                ret = gf_sql_update_delete_wind (sql_conn, gfdb_db_record);
                if (ret) {
                        gf_msg (GFDB_STR_SQLITE3, _gfdb_log_level (GF_LOG_ERROR,
                                gfdb_db_record->ignore_errors), 0,
                                LG_MSG_UPDATE_FAILED, "Failed updating delete "
                                "during wind");
                        goto out;
                }
                break;
        case GFDB_FOP_UNDEL:
        case GFDB_FOP_UNDEL_ALL:
                ret = gf_sql_delete_unwind (sql_conn, gfdb_db_record);
                if (ret) {
                        gf_msg (GFDB_STR_SQLITE3, _gfdb_log_level (GF_LOG_ERROR,
                                gfdb_db_record->ignore_errors), 0,
                                LG_MSG_DELETE_FAILED, "Failed deleting");
                        goto out;
                }
                break;
        case GFDB_FOP_INVALID:
        default:
                gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_INVALID_FOP,
                        "Cannot record to DB: Invalid FOP");
                goto out;
        }

        ret = 0;
out:
        return ret;
}
Example #7
0
/*Libgfdb API Function: Used to terminate/de-initialize db connection
 *                      (Destructor function for db connection object)
 * Arguments:
 *      _conn_node  :  GFDB Connection node
 * Returns : if successful return 0 or
 *          -ve value in case of failure*/
int
fini_db (gfdb_conn_node_t *_conn_node)
{
        int ret                                 = -1;
        gfdb_db_operations_t *db_operations_t   = NULL;

        CHECK_CONN_NODE_GOTO (_conn_node, empty);

        db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;

        GF_ASSERT (db_operations_t->fini_db_op);

        ret = db_operations_t->fini_db_op(&_conn_node->gfdb_connection.
                                          gf_db_connection);
        if (ret) {
                gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                        LG_MSG_CLOSE_CONNECTION_FAILED, "Failed close the db "
                        "connection");
                goto out;
        }

        ret = delete_conn_node (_conn_node);
        if (ret) {
                gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                        LG_MSG_DELETE_FROM_LIST_FAILED, "Failed deleting "
                        "connection node from list");
        }
empty:
        ret = 0;
out:
        return ret;
}
Example #8
0
/* Function to set PRAGMA to sqlite db
 * Input:
 * void *db_conn        : Sqlite connection
 * char *pragma_key     : PRAGMA to be set
 * char *pragma_value   : the value of the PRAGMA
 * Return:
 *      On success return 0
 *      On failure return -1
 * */
int
gf_sqlite3_set_pragma (void *db_conn, char *pragma_key, char *pragma_value)
{
        int ret = -1;
        gf_sql_connection_t *sql_conn = db_conn;
        char sqlstring[GF_NAME_MAX] = "";
        char *db_pragma_value = NULL;

        CHECK_SQL_CONN (sql_conn, out);
        GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pragma_key, out);
        GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pragma_value, out);

        GF_SQLITE3_SET_PRAGMA(sqlstring, pragma_key, "%s",
                              pragma_value, ret, out);

        ret = gf_sqlite3_pragma (db_conn, pragma_key, &db_pragma_value);
        if (ret < 0) {
                gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED,
                        "Failed to get %s pragma", pragma_key);
        } else {
                gf_msg (GFDB_STR_SQLITE3, GF_LOG_INFO, 0, 0,
                        "Value set on DB %s : %s", pragma_key, db_pragma_value);
        }
        GF_FREE (db_pragma_value);

        ret = 0;

out:

        return ret;
}
Example #9
0
static void
__slot_update_events (struct event_slot_epoll *slot, int poll_in, int poll_out)
{
	switch (poll_in) {
	case 1:
		slot->events |= EPOLLIN;
		break;
	case 0:
		slot->events &= ~EPOLLIN;
		break;
	case -1:
		/* do nothing */
		break;
	default:
		gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_INVALID_POLL_IN,
			"invalid poll_in value %d", poll_in);
		break;
	}

	switch (poll_out) {
	case 1:
		slot->events |= EPOLLOUT;
		break;
	case 0:
		slot->events &= ~EPOLLOUT;
		break;
	case -1:
		/* do nothing */
		break;
	default:
		gf_msg ("epoll", GF_LOG_ERROR, 0, LG_MSG_INVALID_POLL_OUT,
			"invalid poll_out value %d", poll_out);
		break;
	}
}
Example #10
0
int
gf_umount_lazy (char *xlname, char *path, int rmdir_flag)
{
        int                   ret               = -1;
        runner_t              runner            = {0,};

        runinit (&runner);
#ifdef GF_LINUX_HOST_OS
        runner_add_args (&runner, _PATH_UMOUNT, "-l", path, NULL);
#else
        if (rmdir_flag)
                runner_add_args (&runner, SBIN_DIR "/umountd",
                                 "-r", path, NULL);
        else
                runner_add_args (&runner, SBIN_DIR "/umountd",
                                 path, NULL);
#endif
        ret = runner_run (&runner);
        if (ret) {
                gf_msg (xlname, GF_LOG_ERROR, errno, LG_MSG_UNMOUNT_FAILED,
                        "Lazy unmount of %s", path);
        }

#ifdef GF_LINUX_HOST_OS
        if (!ret && rmdir_flag) {
                ret = rmdir (path);
                if (ret)
                        gf_msg (xlname, GF_LOG_WARNING, errno,
                                LG_MSG_DIR_OP_FAILED, "rmdir %s", path);
        }
#endif

        return ret;
}
Example #11
0
/*  Parses the string to be of the form <key1>:<value1>,<key2>:<value2>...  *
 *  takes two optional validaters key_validator and value_validator         */
static int
validate_list_elements (const char *string, volume_option_t *opt,
                        int (key_validator)( const char *),
                        int (value_validator)( const char *, volume_option_t *))
{

        char                    *dup_string = NULL;
        char                    *str_sav = NULL;
        char                    *substr_sav = NULL;
        char                    *str_ptr = NULL;
        char                    *key = NULL;
        char                    *value = NULL;
        int                     ret = 0;

        GF_ASSERT (string);

        dup_string = gf_strdup (string);
        if (NULL == dup_string)
                goto out;

        str_ptr = strtok_r (dup_string, ",", &str_sav);
        if (str_ptr == NULL) {
                ret = -1;
                goto out;
        }
        while (str_ptr) {

                key = strtok_r (str_ptr, ":", &substr_sav);
                if (!key ||
                    (key_validator && key_validator(key))) {
                        ret = -1;
                        gf_msg (THIS->name, GF_LOG_WARNING, 0,
                                LG_MSG_INVALID_ENTRY, "invalid list '%s', key "
                                "'%s' not valid.", string, key);
                        goto out;
                }

                value = strtok_r (NULL, ":", &substr_sav);
                if (!value ||
                    (value_validator && value_validator(value, opt))) {
                        ret = -1;
                        gf_msg (THIS->name, GF_LOG_WARNING, 0,
                                LG_MSG_INVALID_ENTRY, "invalid list '%s', "
                                "value '%s' not valid.", string, key);
                        goto out;
                }

                str_ptr = strtok_r (NULL, ",", &str_sav);
                substr_sav = NULL;
        }

 out:
        GF_FREE (dup_string);
        gf_msg_debug (THIS->name, 0, "Returning %d", ret);
        return ret;
}
int
glusterd_proc_stop (glusterd_proc_t *proc, int sig, int flags)
{

        /* NB: Copy-paste code from glusterd_service_stop, the source may be
         * removed once all daemon management use proc */

        int32_t  ret    = -1;
        pid_t    pid    = -1;
        xlator_t *this  = NULL;

        this = THIS;
        GF_ASSERT (this);

        if (!gf_is_service_running (proc->pidfile, &pid)) {
                ret = 0;
                gf_log (this->name, GF_LOG_INFO, "%s already stopped",
                        proc->name);
                goto out;
        }
        gf_log (this->name, GF_LOG_DEBUG, "Stopping %s daemon running in pid: "
                "%d", proc->name, pid);

        ret = kill (pid, sig);
        if (ret) {
                switch (errno) {
                case ESRCH:
                        gf_log (this->name, GF_LOG_DEBUG, "%s is already "
                                "stopped", proc->name);
                        ret = 0;
                        goto out;
                default:
                        gf_msg (this->name, GF_LOG_ERROR, errno,
                                GD_MSG_SVC_KILL_FAIL, "Unable to kill %s "
                                "service, reason:%s", proc->name,
                                strerror (errno));
                }
        }
        if (flags != PROC_STOP_FORCE)
                goto out;

        sleep (1);
        if (gf_is_service_running (proc->pidfile, NULL)) {
                ret = kill (pid, SIGKILL);
                if (ret) {
                        gf_msg (this->name, GF_LOG_ERROR, errno,
                                GD_MSG_PID_KILL_FAIL, "Unable to kill pid:%d, "
                                "reason:%s", pid, strerror(errno));
                        goto out;
                }
        }

        ret = 0;
out:
        return ret;
}
Example #13
0
/* Function to extract PRAGMA from sqlite db
 * Input:
 * void *db_conn        : Sqlite connection
 * char *pragma_key     : PRAGMA or setting to be extracted
 * char **pragma_value  : the value of the PRAGMA or setting that is
 *                        extracted. This function will allocate memory
 *                        to pragma_value. The caller should free the memory
 * Return:
 *      On success return the lenght of the pragma/setting value that is
 *      extracted.
 *      On failure return -1
 * */
int
gf_sqlite3_pragma (void *db_conn, char *pragma_key, char **pragma_value)
{
        int ret = -1;
        gf_sql_connection_t *sql_conn = db_conn;
        sqlite3_stmt *pre_stmt = NULL;
        char *sqlstring = NULL;

        CHECK_SQL_CONN (sql_conn, out);
        GF_VALIDATE_OR_GOTO (GFDB_STR_SQLITE3, pragma_key, out);

        ret = gf_asprintf (&sqlstring, "PRAGMA %s;", pragma_key);
        if (ret <= 0) {
                gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0,
                        LG_MSG_PREPARE_FAILED, "Failed allocating memory");
                goto out;
        }

        ret = sqlite3_prepare_v2 (sql_conn->sqlite3_db_conn,
                                  sqlstring, -1, &pre_stmt, 0);
        if (ret != SQLITE_OK) {
                gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0,
                        LG_MSG_PREPARE_FAILED, "Failed init prepare stmt %s",
                        sqlite3_errmsg (db_conn));
                ret = -1;
                goto out;
        }

        ret = sqlite3_step (pre_stmt);
        if (ret != SQLITE_ROW) {
                gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0,
                        LG_MSG_GET_RECORD_FAILED, "Failed to get records "
                        "from db : %s", sqlite3_errmsg (db_conn));
                ret = -1;
                goto out;
        }

        ret = gf_asprintf (pragma_value, "%s", sqlite3_column_text (pre_stmt, 0));
        if (ret <= 0) {
                gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_QUERY_FAILED,
                        "Failed to get %s from db", pragma_key);
        }

        ret = 0;
out:
        GF_FREE (sqlstring);

        sqlite3_finalize (pre_stmt);

        return ret;
}
Example #14
0
int
xlator_volopt_dynload (char *xlator_type, void **dl_handle,
                       volume_opt_list_t *opt_list)
{
        int                     ret = -1;
        char                    *name = NULL;
        void                    *handle = NULL;

        GF_VALIDATE_OR_GOTO ("xlator", xlator_type, out);

        /* socket.so doesn't fall under the default xlator directory, hence we
         * need this check */
        if (!strstr(xlator_type, "rpc-transport"))
                ret = gf_asprintf (&name, "%s/%s.so", XLATORDIR, xlator_type);
        else
                ret = gf_asprintf (&name, "%s/%s.so", XLATORPARENTDIR, xlator_type);
        if (-1 == ret) {
                goto out;
        }

        ret = -1;

        gf_msg_trace ("xlator", 0, "attempt to load file %s", name);

        handle = dlopen (name, RTLD_NOW|RTLD_GLOBAL);
        if (!handle) {
                gf_msg ("xlator", GF_LOG_WARNING, 0, LG_MSG_DLOPEN_FAILED,
                        "%s", dlerror ());
                goto out;
        }

        if (!(opt_list->given_opt = dlsym (handle, "options"))) {
                dlerror ();
                gf_msg ("xlator", GF_LOG_ERROR, 0, LG_MSG_LOAD_FAILED,
                        "Failed to load xlator opt table");
                goto out;
        }

        *dl_handle = handle;
        handle = NULL;

        ret = 0;
 out:
        GF_FREE (name);
        if (handle)
                dlclose (handle);

        gf_msg_debug ("xlator", 0, "Returning %d", ret);
        return ret;

}
Example #15
0
int
nfs_gfid_loc_fill (inode_table_t *itable, uuid_t gfid, loc_t *loc, int how)
{
        int             ret = -EFAULT;
        inode_t         *inode = NULL;

        if (!loc)
                return ret;

        inode = inode_find (itable, gfid);
        if (!inode) {
		gf_msg_trace (GF_NFS, 0, "Inode not found in itable, will "
                              "try to create one.");
                if (how == NFS_RESOLVE_CREATE) {
			gf_msg_trace (GF_NFS, 0, "Inode needs to be created.");
                        inode = inode_new (itable);
                        if (!inode) {
                                gf_msg (GF_NFS, GF_LOG_ERROR, ENOMEM,
                                        NFS_MSG_NO_MEMORY, "Failed to "
                                        "allocate memory");
                                ret = -ENOMEM;
                                goto err;
                        }

                } else {
			gf_msg (GF_NFS, GF_LOG_ERROR, ENOENT,
                                NFS_MSG_INODE_NOT_FOUND, "Inode not found in "
                                "itable and no creation was requested.");
                        ret = -ENOENT;
                        goto err;
                }
        } else {
		gf_msg_trace (GF_NFS, 0, "Inode was found in the itable.");
	}

        gf_uuid_copy (loc->gfid, gfid);

        ret = nfs_inode_loc_fill (inode, loc, how);
	if (ret < 0) {
		gf_msg (GF_NFS, GF_LOG_ERROR, -ret,
                        NFS_MSG_INODE_LOC_FILL_ERROR,
                        "Inode loc filling failed.: %s", strerror (-ret));
		goto err;
	}

err:
        if (inode)
                inode_unref (inode);
        return ret;
}
Example #16
0
int
nfs_inode_loc_fill (inode_t *inode, loc_t *loc, int how)
{
        char            *resolvedpath = NULL;
        inode_t         *parent = NULL;
        int             ret = -EFAULT;

        if ((!inode) || (!loc))
                return ret;

        /* If gfid is not null, then the inode is already linked to
         * the inode table, and not a newly created one. For newly
         * created inode, inode_path returns null gfid as the path.
         */
        if (!gf_uuid_is_null (inode->gfid)) {
                ret = inode_path (inode, NULL, &resolvedpath);
                if (ret < 0) {
                        gf_msg (GF_NFS, GF_LOG_ERROR, 0,
                                NFS_MSG_PATH_RESOLVE_FAIL, "path resolution "
                                "failed %s", resolvedpath);
                        goto err;
                }
        }

        if (resolvedpath == NULL) {
                char tmp_path[GFID_STR_PFX_LEN + 1] = {0,};
                snprintf (tmp_path, sizeof (tmp_path), "<gfid:%s>",
                          uuid_utoa (loc->gfid));
                resolvedpath = gf_strdup (tmp_path);
        } else {
                parent = inode_parent (inode, loc->pargfid, NULL);
        }

        ret = nfs_loc_fill (loc, inode, parent, resolvedpath);
        if (ret < 0) {
                gf_msg (GF_NFS, GF_LOG_ERROR, -ret,
                        NFS_MSG_LOC_FILL_RESOLVE_FAIL,
                        "loc fill resolution failed %s", resolvedpath);
                goto err;
        }

        ret = 0;
err:
        if (parent)
                inode_unref (parent);

        GF_FREE (resolvedpath);

        return ret;
}
Example #17
0
static int
xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value,
                              volume_option_t *opt, char **op_errstr)
{
        size_t  size = 0;
        int       ret = 0;
        char      errstr[256];

        /* Check the range */
        if (gf_string2bytesize_size (value, &size) != 0) {
                snprintf (errstr, 256,
                          "invalid number format \"%s\" in option \"%s\"",
                          value, key);
                gf_msg (xl->name, GF_LOG_ERROR, 0, LG_MSG_INVALID_ENTRY, "%s",
                        errstr);
                ret = -1;
                goto out;
        }

        if ((opt->min == 0) && (opt->max == 0)) {
                gf_msg_trace (xl->name, 0, "no range check required for "
                              "'option %s %s'", key, value);
                goto out;
        }

        if ((size < opt->min) || (size > opt->max)) {
                if ((strncmp (key, "cache-size", 10) == 0) &&
                    (size > opt->max)) {
                       snprintf (errstr, 256, "Cache size %" GF_PRI_SIZET " is out of "
                                 "range [%.0f - %.0f]",
                                 size, opt->min, opt->max);
                       gf_msg (xl->name, GF_LOG_WARNING, 0,
                               LG_MSG_OUT_OF_RANGE, "%s", errstr);
                } else {
                        snprintf (errstr, 256,
                                  "'%" GF_PRI_SIZET "' in 'option %s %s' "
                                  "is out of range [%.0f - %.0f]",
                                  size, key, value, opt->min, opt->max);
                        gf_msg (xl->name, GF_LOG_ERROR, 0,
                                LG_MSG_OUT_OF_RANGE, "%s", errstr);
                        ret = -1;
                }
        }

out:
        if (ret && op_errstr)
                *op_errstr = gf_strdup (errstr);
        return ret;
}
Example #18
0
/*Libgfdb API Function: Query records/files that have changed/accessed from a
 *                      time in past to current time
 * Arguments:
 *      _conn_node              : GFDB Connection node
 *      query_callback          : Call back function that will be called
 *                                for every record found
 *      _query_cbk_args         : Custom argument passed for the call back
 *                                function query_callback
 *      for_time                : Time from where the file/s are
 *                                changed/accessed
 * Returns : if successful return 0 or
 *          -ve value in case of failure*/
int
find_recently_changed_files(gfdb_conn_node_t    *_conn_node,
                            gf_query_callback_t query_callback,
                            void                *_query_cbk_args,
                            gfdb_time_t         *from_time)
{

        int ret                                 = 0;
        gfdb_db_operations_t *db_operations_t   = NULL;
        void *gf_db_connection                  = NULL;

        CHECK_CONN_NODE(_conn_node);

        db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
        gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;

        if (db_operations_t->find_recently_changed_files_op) {

                ret =  db_operations_t->find_recently_changed_files_op (
                                gf_db_connection, query_callback,
                                _query_cbk_args, from_time);
                if (ret) {
                        gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                                LG_MSG_FIND_OP_FAILED,
                                "Find changed operation failed");
                }

        }

        return ret;

}
Example #19
0
/*Libgfdb API Function: Query all the records from the database
 * Arguments:
 *      _conn_node      : GFDB Connection node
 *      query_callback  : Call back function that will be called
 *                        for every record found
 *      _query_cbk_args : Custom argument passed for the call back
 *                        function query_callback
 * Returns : if successful return 0 or
 *          -ve value in case of failure*/
int
find_all (gfdb_conn_node_t      *_conn_node,
          gf_query_callback_t   query_callback,
          void                  *_query_cbk_args)
{
        int ret                                 = 0;
        gfdb_db_operations_t *db_operations_t   = NULL;
        void *gf_db_connection                  = NULL;

        CHECK_CONN_NODE(_conn_node);

        db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
        gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;

        if (db_operations_t->find_all_op) {
                ret = db_operations_t->find_all_op (gf_db_connection,
                                                    query_callback,
                                                    _query_cbk_args);
                if (ret) {
                        gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                                LG_MSG_FIND_OP_FAILED, "Find all operation "
                                "failed");
                }

        }

        return ret;
}
Example #20
0
/*Libgfdb API Function: Used to delete record from the database
 *                      NOTE: In the current gfdb_sqlite3 plugin
 *                      implementation this function is dummy.
 *                      Use the insert_record function.
 *                      Refer CTR Xlator features/changetimerecorder for usage
 * Arguments:
 *      _conn_node     :  GFDB Connection node
 *      gfdb_db_record :  Record to be deleted
 * Returns : if successful return 0 or
 *          -ve value in case of failure*/
int
delete_record (gfdb_conn_node_t *_conn_node,
               gfdb_db_record_t *gfdb_db_record)
{
        int ret                                 = 0;
        gfdb_db_operations_t *db_operations_t   = NULL;
        void *gf_db_connection                  = NULL;

        CHECK_CONN_NODE(_conn_node);

        db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
        gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;

        if (db_operations_t->delete_record_op) {

                ret = db_operations_t->delete_record_op (gf_db_connection,
                                                         gfdb_db_record);
                if (ret) {
                        gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                                LG_MSG_DELETE_FAILED, "Delete operation "
                                "failed");
                }

        }

        return ret;
}
Example #21
0
/*Libgfdb API Function: Used to insert/update records in the database
 *                      NOTE: In current gfdb_sqlite plugin we use that
 *                      same function to delete the record. Set the
 *                      gfdb_fop_path to GFDB_FOP_UNDEL to delete the
 *                      link of inode from GF_FLINK_TB and
 *                      GFDB_FOP_UNDEL_ALL to delete all the records from
 *                      GF_FLINK_TB and GF_FILE_TB.
 *                      TODO: Should seperate this function into the
 *                      delete_record function
 *                      Refer CTR Xlator features/changetimerecorder for usage
 * Arguments:
 *      _conn_node     :  GFDB Connection node
 *      gfdb_db_record :  Record to be inserted/updated
 * Returns : if successful return 0 or
 *          -ve value in case of failure*/
int
insert_record (gfdb_conn_node_t *_conn_node,
               gfdb_db_record_t *gfdb_db_record)
{
        int ret                                 = 0;
        gfdb_db_operations_t *db_operations_t   = NULL;
        void *gf_db_connection                  = NULL;

        CHECK_CONN_NODE(_conn_node);

        db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
        gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;

        if (db_operations_t->insert_record_op) {

                ret = db_operations_t->insert_record_op (gf_db_connection,
                                                         gfdb_db_record);
                if (ret) {
                        gf_msg (GFDB_DATA_STORE, _gfdb_log_level (GF_LOG_ERROR,
                                gfdb_db_record->ignore_errors), 0,
                                LG_MSG_INSERT_OR_UPDATE_FAILED, "Insert/Update"
                                " operation failed");
                }
        }

        return ret;
}
Example #22
0
int
solaris_setxattr(const char *path, const char* key, const char *value,
                 size_t size, int flags)
{
        int attrfd = -1;
        int ret = 0;
        char *mapped_path = NULL;

        ret = solaris_xattr_resolve_path (path, &mapped_path);
        if (!ret) {
                attrfd = attropen (mapped_path,  key, flags|O_CREAT|O_WRONLY,
                                   0777);
        } else {
                attrfd = attropen (path, key, flags|O_CREAT|O_WRONLY, 0777);
        }
        if (attrfd >= 0) {
                ftruncate (attrfd, 0);
                ret = write (attrfd, value, size);
                close (attrfd);
                ret = 0;
        } else {
                if (errno != ENOENT)
                        gf_msg ("libglusterfs", GF_LOG_ERROR, errno,
                                LG_MSG_SET_ATTRIBUTE_FAILED, "Couldn't set "
                                "extended attribute for %s", path);
                ret = -1;
        }
        GF_FREE (mapped_path);
        return ret;
}
Example #23
0
int
gf_sql_clear_counters (gf_sql_connection_t *sql_conn)
{
        int ret                 = -1;
        char *sql_strerror      = NULL;
        char *query_str         = NULL;

        CHECK_SQL_CONN (sql_conn, out);

        query_str = "BEGIN;UPDATE "
                    GF_FILE_TABLE
                    " SET " GF_COL_READ_FREQ_CNTR " = 0 , "
                    GF_COL_WRITE_FREQ_CNTR " = 0 ;COMMIT;";

        ret = sqlite3_exec (sql_conn->sqlite3_db_conn, query_str, NULL, NULL,
                                &sql_strerror);
        if (ret != SQLITE_OK) {
                gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_EXEC_FAILED,
                        "Failed executing: %s : %s",
                        query_str, sql_strerror);
                sqlite3_free (sql_strerror);
                        ret = -1;
                        goto out;
        }

        ret = 0;
out:
        return ret;
}
Example #24
0
int
solaris_fgetxattr(int fd, const char* key, char *value, size_t size)
{
        int attrfd = -1;
        int ret = 0;

        attrfd = openat (fd, key, O_RDONLY|O_XATTR);
        if (attrfd >= 0) {
                if (size == 0) {
                        struct stat buf;
                        fstat (attrfd, &buf);
                        ret = buf.st_size;
                } else {
                        ret = read (attrfd, value, size);
                }
                close (attrfd);
        } else {
                if (errno != ENOENT)
                        gf_msg ("libglusterfs", GF_LOG_INFO, errno,
                                LG_MSG_READ_ATTRIBUTE_FAILED, "Couldn't read "
                                "extended attribute for the file %d", fd);
                if (errno == ENOENT)
                        errno = ENODATA;
                return -1;
        }

        return ret;
}
Example #25
0
/*Libgfdb API Function: Query records/files that have not changed/accessed
 *                      from a time in past to current time, with
 *                      a desired frequency
 * Arguments:
 *      _conn_node              : GFDB Connection node
 *      query_callback          : Call back function that will be called
 *                                for every record found
 *      _query_cbk_args         : Custom argument passed for the call back
 *                                function query_callback
 *      for_time                : Time from where the file/s are not
 *                                changed/accessed
 *      write_freq_thresold     : Desired Write Frequency lower limit
 *      read_freq_thresold      : Desired Read Frequency lower limit
 *      _clear_counters         : If true, Clears all the frequency counters of
 *                                all files.
 * Returns : if successful return 0 or
 *          -ve value in case of failure*/
int
find_unchanged_for_time_freq(gfdb_conn_node_t *_conn_node,
                                        gf_query_callback_t query_callback,
                                        void *_query_cbk_args,
                                        gfdb_time_t *for_time,
                                        int write_freq_thresold,
                                        int read_freq_thresold,
                                        gf_boolean_t _clear_counters)
{
        int ret                                 = 0;
        gfdb_db_operations_t *db_operations_t   = NULL;
        void *gf_db_connection                  = NULL;

        CHECK_CONN_NODE(_conn_node);

        db_operations_t = &_conn_node->gfdb_connection.gfdb_db_operations;
        gf_db_connection = _conn_node->gfdb_connection.gf_db_connection;

        if (db_operations_t->find_unchanged_for_time_freq_op) {

                ret = db_operations_t->find_unchanged_for_time_freq_op(
                                gf_db_connection, query_callback,
                                _query_cbk_args, for_time,
                                write_freq_thresold, read_freq_thresold,
                                _clear_counters);
                if (ret) {
                        gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                                LG_MSG_FIND_OP_FAILED,
                                "Find unchanged with freq operation failed");
                }

        }

        return ret;
}
Example #26
0
int
set_db_params (gfdb_conn_node_t *conn_node, char *param_key,
                char *param_value)
{
        int ret                                 = -1;
        gfdb_db_operations_t *db_operations     = NULL;
        void *gf_db_connection                  = NULL;

        CHECK_CONN_NODE(conn_node);

        db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
        gf_db_connection = conn_node->gfdb_connection.gf_db_connection;

        if (db_operations->set_db_params) {
                ret =  db_operations->set_db_params (gf_db_connection,
                                                     param_key,
                                                     param_value);
                if (ret < 0) {
                        gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                                LG_MSG_INSERT_OR_UPDATE_FAILED,
                                "Failed to set database setting");
                }
        }

        return ret;
}
Example #27
0
int
get_db_params (gfdb_conn_node_t *conn_node, char *param_key,
                char **param_value)
{
        int ret                                 = -1;
        gfdb_db_operations_t *db_operations     = NULL;
        void *gf_db_connection                  = NULL;

        CHECK_CONN_NODE(conn_node);

        db_operations = &conn_node->gfdb_connection.gfdb_db_operations;
        gf_db_connection = conn_node->gfdb_connection.gf_db_connection;

        if (db_operations->get_db_params) {
                ret =  db_operations->get_db_params (gf_db_connection,
                                                     param_key,
                                                     param_value);
                if (ret < 0) {
                        gf_msg (GFDB_DATA_STORE, GF_LOG_ERROR, 0,
                                LG_MSG_FIND_OP_FAILED,
                                "Get setting failed");
                }
        }

        return ret;
}
Example #28
0
clienttable_t *
gf_clienttable_alloc (void)
{
        clienttable_t *clienttable = NULL;
        int            result = 0;

        clienttable =
                GF_CALLOC (1, sizeof (clienttable_t), gf_common_mt_clienttable_t);
        if (!clienttable)
                return NULL;

        LOCK_INIT (&clienttable->lock);

        result = gf_client_clienttable_expand (clienttable,
                                               GF_CLIENTTABLE_INITIAL_SIZE);
        if (result != 0) {
                gf_msg ("client_t", GF_LOG_ERROR, 0,
                        LG_MSG_EXPAND_CLIENT_TABLE_FAILED,
                        "gf_client_clienttable_expand failed");
                GF_FREE (clienttable);
                return NULL;
        }

        return clienttable;
}
Example #29
0
static int
create_filetable (sqlite3 *sqlite3_db_conn)
{
        int ret                         =       -1;
        char *sql_stmt                  =       NULL;
        char *sql_strerror              =       NULL;

        GF_ASSERT(sqlite3_db_conn);

        sql_stmt = sql_stmt_init();
        if (!sql_stmt) {
                ret = ENOMEM;
                goto out;
        }

        GF_CREATE_STMT(sql_stmt);

        ret = sqlite3_exec (sqlite3_db_conn, sql_stmt, NULL, NULL,
                                &sql_strerror);
        if (ret != SQLITE_OK) {
                gf_msg (GFDB_STR_SQLITE3, GF_LOG_ERROR, 0, LG_MSG_EXEC_FAILED,
                        "Failed executing: %s : %s", sql_stmt, sql_strerror);
                sqlite3_free (sql_strerror);
                        ret = -1;
                        goto out;
        }


        ret = 0;
out:
        sql_stmt_fini (&sql_stmt);
        return ret;
}
Example #30
0
static int
event_unregister_poll (struct event_pool *event_pool, int fd, int idx_hint)
{
        int idx = -1;

        GF_VALIDATE_OR_GOTO ("event", event_pool, out);

        pthread_mutex_lock (&event_pool->mutex);
        {
                idx = __event_getindex (event_pool, fd, idx_hint);

                if (idx == -1) {
                        gf_msg ("poll", GF_LOG_ERROR, 0, LG_MSG_INDEX_NOT_FOUND,
                                "index not found for fd=%d (idx_hint=%d)",
                                fd, idx_hint);
                        errno = ENOENT;
                        goto unlock;
                }

                event_pool->reg[idx] =  event_pool->reg[--event_pool->used];
                event_pool->changed = 1;
        }
unlock:
        pthread_mutex_unlock (&event_pool->mutex);

out:
        return idx;
}