int fs_create(lsm_plugin_ptr c, lsm_pool *pool, const char *name, uint64_t size_bytes, lsm_fs **fs, char **job, lsm_flag flags) { int rc = LSM_ERR_OK; sqlite3 *db = NULL; char err_msg[_LSM_ERR_MSG_LEN]; _lsm_err_msg_clear(err_msg); _good(_check_null_ptr(err_msg, 4 /* argument count */, pool, name, fs, job), rc, out); _good(_get_db_from_plugin_ptr(err_msg, c, &db), rc, out); _good(_db_sql_trans_begin(err_msg, db), rc, out); _good(_fs_create_internal(err_msg, db, name, size_bytes, _db_lsm_id_to_sim_id(lsm_pool_id_get(pool))), rc, out); _good(_job_create(err_msg, db, LSM_DATA_TYPE_FS, _db_last_rowid(db), job), rc, out); _good(_db_sql_trans_commit(err_msg, db), rc, out); out: if (fs != NULL) *fs = NULL; if (rc != LSM_ERR_OK) { _db_sql_trans_rollback(db); if (job != NULL) *job = NULL; lsm_log_error_basic(c, rc, err_msg); } if (rc == LSM_ERR_OK) rc = LSM_ERR_JOB_STARTED; return rc; }
int fs_child_dependency_rm(lsm_plugin_ptr c, lsm_fs *fs, lsm_string_list *files, char **job, lsm_flag flags) { int rc = LSM_ERR_OK; uint8_t yes = 0; char err_msg[_LSM_ERR_MSG_LEN]; uint64_t sim_fs_id = 0; char condition[_BUFF_SIZE]; sqlite3 *db = NULL; _lsm_err_msg_clear(err_msg); _good(_check_null_ptr(err_msg, 2 /* argument count */, fs, job), rc, out); _good(fs_child_dependency(c, fs, files, &yes), rc, out); if (yes == 0) { rc = LSM_ERR_NO_STATE_CHANGE; _lsm_err_msg_set(err_msg, "Specified file system does not have child " "dependency"); goto out; } _good(_get_db_from_plugin_ptr(err_msg, c, &db), rc, out); _good(_db_sql_trans_begin(err_msg, db), rc, out); /* * Assuming API definition is break all clone relationship and remove * all snapshot of this source file system. */ /* Previous fs_child_dependency() call already checked the fs existence */ sim_fs_id = _db_lsm_id_to_sim_id(lsm_fs_id_get(fs)); _snprintf_buff(err_msg, rc, out, condition, "src_fs_id = %" PRIu64, sim_fs_id); _good(_db_data_delete_condition(err_msg, db, _DB_TABLE_FS_CLONES, condition), rc, out); _snprintf_buff(err_msg, rc, out, condition, "fs_id = %" PRIu64, sim_fs_id); _good(_db_data_delete_condition(err_msg, db, _DB_TABLE_FS_SNAPS, condition), rc, out); _good(_job_create(err_msg, db, LSM_DATA_TYPE_NONE, _DB_SIM_ID_NONE, job), rc, out); _good(_db_sql_trans_commit(err_msg, db), rc, out); out: _db_sql_trans_rollback(db); if (rc != LSM_ERR_OK) { lsm_log_error_basic(c, rc, err_msg); } else { rc = LSM_ERR_JOB_STARTED; } return rc; }
int proctrack_p_create (stepd_step_rec_t *job) { if (!libjob_handle) init(); if ((job->cont_id = _job_create (0, job->uid, 0)) == (jid_t) -1) { error ("Failed to create job container: %m"); return SLURM_ERROR; } debug ("created jid 0x%08lx", job->cont_id); return SLURM_SUCCESS; }
int fs_file_clone(lsm_plugin_ptr c, lsm_fs *fs, const char *src_file_name, const char *dest_file_name, lsm_fs_ss *snapshot, char **job, lsm_flag flags) { int rc = LSM_ERR_OK; sqlite3 *db = NULL; char err_msg[_LSM_ERR_MSG_LEN]; lsm_hash *sim_fs = NULL; lsm_hash *sim_fs_snap = NULL; _lsm_err_msg_clear(err_msg); _good(_check_null_ptr(err_msg, 4 /* argument count */, fs, src_file_name, dest_file_name, job), rc, out); _good(_get_db_from_plugin_ptr(err_msg, c, &db), rc, out); _good(_db_sql_trans_begin(err_msg, db), rc, out); /* Check fs existence */ _good(_db_sim_fs_of_sim_id(err_msg, db, _db_lsm_id_to_sim_id(lsm_fs_id_get(fs)), &sim_fs), rc, out); if (snapshot != NULL) _good(_db_sim_fs_snap_of_sim_id(err_msg, db, _db_lsm_id_to_sim_id (lsm_fs_ss_id_get(snapshot)), &sim_fs_snap), rc, out); /* We don't have API to query file level clone. So do nothing here */ _good(_job_create(err_msg, db, LSM_DATA_TYPE_NONE, _DB_SIM_ID_NONE, job), rc, out); _good(_db_sql_trans_commit(err_msg, db), rc, out); out: if (sim_fs != NULL) lsm_hash_free(sim_fs); if (sim_fs_snap != NULL) lsm_hash_free(sim_fs_snap); if (rc != LSM_ERR_OK) { _db_sql_trans_rollback(db); if (job != NULL) *job = NULL; lsm_log_error_basic(c, rc, err_msg); } else { rc = LSM_ERR_JOB_STARTED; } return rc; }
int fs_snapshot_delete(lsm_plugin_ptr c, lsm_fs *fs, lsm_fs_ss *ss, char **job, lsm_flag flags) { int rc = LSM_ERR_OK; sqlite3 *db = NULL; char err_msg[_LSM_ERR_MSG_LEN]; lsm_hash *sim_fs_snap = NULL; uint64_t sim_fs_snap_id = 0; _lsm_err_msg_clear(err_msg); _good(_check_null_ptr(err_msg, 3 /* argument count */, fs, ss, job), rc, out); _good(_get_db_from_plugin_ptr(err_msg, c, &db), rc, out); _good(_db_sql_trans_begin(err_msg, db), rc, out); sim_fs_snap_id = _db_lsm_id_to_sim_id(lsm_fs_ss_id_get(ss)); /* The existence of fs snapshot indicate the fs is exist due to the sqlite * REFERENCES and PRAGMA foreign_keys = ON */ _good(_db_sim_fs_snap_of_sim_id(err_msg, db, sim_fs_snap_id, &sim_fs_snap), rc, out); _good(_db_data_delete(err_msg, db, _DB_TABLE_FS_SNAPS, sim_fs_snap_id), rc, out); _good(_job_create(err_msg, db, LSM_DATA_TYPE_NONE, _DB_SIM_ID_NONE, job), rc, out); _good(_db_sql_trans_commit(err_msg, db), rc, out); out: if (sim_fs_snap != NULL) lsm_hash_free(sim_fs_snap); if (rc != LSM_ERR_OK) { _db_sql_trans_rollback(db); lsm_log_error_basic(c, rc, err_msg); if (job != NULL) *job = NULL; } else { rc = LSM_ERR_JOB_STARTED; } return rc; }
int fs_snapshot_create(lsm_plugin_ptr c, lsm_fs *fs, const char *name, lsm_fs_ss **snapshot, char **job, lsm_flag flags) { int rc = LSM_ERR_OK; struct _vector *vec = NULL; sqlite3 *db = NULL; char err_msg[_LSM_ERR_MSG_LEN]; lsm_hash *sim_fs = NULL; uint64_t sim_fs_id = 0; char ts_str[_BUFF_SIZE]; struct timespec ts; _lsm_err_msg_clear(err_msg); _good(_check_null_ptr(err_msg, 4 /* argument count */, fs, name, snapshot, job), rc, out); _good(_get_db_from_plugin_ptr(err_msg, c, &db), rc, out); _good(_db_sql_trans_begin(err_msg, db), rc, out); /* Check fs existence */ sim_fs_id = _db_lsm_id_to_sim_id(lsm_fs_id_get(fs)); _good(_db_sim_fs_of_sim_id(err_msg, db, sim_fs_id, &sim_fs), rc, out); if (clock_gettime(CLOCK_REALTIME, &ts) != 0) { rc = LSM_ERR_PLUGIN_BUG; _lsm_err_msg_set(err_msg, "BUG: clock_gettime(CLOCK_REALTIME, &ts) " "failed"); goto out; } _snprintf_buff(err_msg, rc, out, ts_str, "%" PRIu64, (uint64_t) difftime(ts.tv_sec, 0)); rc = _db_data_add(err_msg, db, _DB_TABLE_FS_SNAPS, "name", name, "fs_id", _db_lsm_id_to_sim_id_str(lsm_fs_id_get(fs)), "timestamp", ts_str, NULL); if (rc != LSM_ERR_OK) { if (sqlite3_errcode(db) == SQLITE_CONSTRAINT) { rc = LSM_ERR_NAME_CONFLICT; _lsm_err_msg_set(err_msg, "FS snapshot name '%s' in use", name); } goto out; } _good(_job_create(err_msg, db, LSM_DATA_TYPE_SS, _db_last_rowid(db), job), rc, out); _good(_db_sql_trans_commit(err_msg, db), rc, out); out: _db_sql_exec_vec_free(vec); if (snapshot != NULL) *snapshot = NULL; if (sim_fs != NULL) lsm_hash_free(sim_fs); if (rc != LSM_ERR_OK) { lsm_log_error_basic(c, rc, err_msg); } else { rc = LSM_ERR_JOB_STARTED; } return rc; }
int fs_resize(lsm_plugin_ptr c, lsm_fs *fs, uint64_t new_size, lsm_fs ** rfs, char **job, lsm_flag flags) { int rc = LSM_ERR_OK; char err_msg[_LSM_ERR_MSG_LEN]; uint64_t sim_fs_id = 0; lsm_hash *sim_fs = NULL; uint64_t increment_size = 0; uint64_t cur_size = 0; uint64_t sim_pool_id = 0; char new_size_str[_BUFF_SIZE]; sqlite3 *db = NULL; _lsm_err_msg_clear(err_msg); _good(_check_null_ptr(err_msg, 3 /* argument count */, fs, rfs, job), rc, out); _good(_get_db_from_plugin_ptr(err_msg, c, &db), rc, out); _good(_db_sql_trans_begin(err_msg, db), rc, out); sim_fs_id = _db_lsm_id_to_sim_id(lsm_fs_id_get(fs)); _good(_db_sim_fs_of_sim_id(err_msg, db, sim_fs_id, &sim_fs), rc, out); _good(_str_to_uint64(err_msg, lsm_hash_string_get(sim_fs, "total_space"), &cur_size), rc, out); new_size = _db_blk_size_rounding(new_size); if (cur_size == new_size) { rc = LSM_ERR_NO_STATE_CHANGE; _lsm_err_msg_set(err_msg, "Specified new size is identical to " "current fs size"); goto out; } if (new_size > cur_size) { increment_size = new_size - cur_size; sim_pool_id = _db_lsm_id_to_sim_id(lsm_fs_pool_id_get(fs)); if (_pool_has_enough_free_size(db, sim_pool_id, increment_size) == false) { rc = LSM_ERR_NOT_ENOUGH_SPACE; _lsm_err_msg_set(err_msg, "Insufficient space in pool"); goto out; } } _snprintf_buff(err_msg, rc, out, new_size_str, "%" PRIu64, new_size); _good(_db_data_update(err_msg, db, _DB_TABLE_FSS, sim_fs_id, "total_space", new_size_str), rc, out); _good(_db_data_update(err_msg, db, _DB_TABLE_FSS, sim_fs_id, "consumed_size", new_size_str), rc, out); _good(_db_data_update(err_msg, db, _DB_TABLE_FSS, sim_fs_id, "free_space", new_size_str), rc, out); _good(_job_create(err_msg, db, LSM_DATA_TYPE_FS, sim_fs_id, job), rc, out); _good(_db_sql_trans_commit(err_msg, db), rc, out); out: if (rfs != NULL) *rfs = NULL; if (sim_fs != NULL) lsm_hash_free(sim_fs); if (rc != LSM_ERR_OK) { _db_sql_trans_rollback(db); if (job != NULL) *job = NULL; lsm_log_error_basic(c, rc, err_msg); } else { rc = LSM_ERR_JOB_STARTED; } return rc; }
int fs_clone(lsm_plugin_ptr c, lsm_fs *src_fs, const char *dest_fs_name, lsm_fs **cloned_fs, lsm_fs_ss *optional_snapshot, char **job, lsm_flag flags) { int rc = LSM_ERR_OK; sqlite3 *db = NULL; char err_msg[_LSM_ERR_MSG_LEN]; lsm_hash *sim_fs = NULL; lsm_hash *sim_fs_snap = NULL; uint64_t sim_fs_id = 0; uint64_t dst_sim_fs_id = 0; char dst_sim_fs_id_str[_BUFF_SIZE]; uint64_t sim_fs_snap_id = 0; _lsm_err_msg_clear(err_msg); _good(_check_null_ptr(err_msg, 4 /* argument count */, src_fs, dest_fs_name, cloned_fs, job), rc, out); _good(_get_db_from_plugin_ptr(err_msg, c, &db), rc, out); _good(_db_sql_trans_begin(err_msg, db), rc, out); sim_fs_id = _db_lsm_id_to_sim_id(lsm_fs_id_get(src_fs)); /* Check fs existence */ _good(_db_sim_fs_of_sim_id(err_msg, db, sim_fs_id, &sim_fs), rc, out); if (optional_snapshot != NULL) { sim_fs_snap_id = _db_lsm_id_to_sim_id (lsm_fs_ss_id_get(optional_snapshot)); /* No need to trace state of snap id here due to lack of query method. * We just check snapshot existence */ _good(_db_sim_fs_snap_of_sim_id(err_msg, db, sim_fs_snap_id, &sim_fs_snap), rc, out); lsm_hash_free(sim_fs_snap); } _good(_fs_create_internal(err_msg, db, dest_fs_name, lsm_fs_total_space_get(src_fs), _db_lsm_id_to_sim_id(lsm_fs_pool_id_get(src_fs))), rc, out); dst_sim_fs_id = _db_last_rowid(db); _snprintf_buff(err_msg, rc, out, dst_sim_fs_id_str, "%" PRIu64, dst_sim_fs_id); _good(_db_data_add(err_msg, db, _DB_TABLE_FS_CLONES, "src_fs_id", _db_lsm_id_to_sim_id_str(lsm_fs_id_get(src_fs)), "dst_fs_id", dst_sim_fs_id_str, NULL), rc, out); _good(_job_create(err_msg, db, LSM_DATA_TYPE_FS, dst_sim_fs_id, job), rc, out); _good(_db_sql_trans_commit(err_msg, db), rc, out); out: if (sim_fs != NULL) lsm_hash_free(sim_fs); if (cloned_fs != NULL) *cloned_fs = NULL; if (rc != LSM_ERR_OK) { _db_sql_trans_rollback(db); if (job != NULL) *job = NULL; lsm_log_error_basic(c, rc, err_msg); } else { rc = LSM_ERR_JOB_STARTED; } return rc; }
int fs_delete(lsm_plugin_ptr c, lsm_fs *fs, char **job, lsm_flag flags) { int rc = LSM_ERR_OK; sqlite3 *db = NULL; char err_msg[_LSM_ERR_MSG_LEN]; lsm_hash *sim_fs = NULL; uint64_t sim_fs_id = 0; char sql_cmd[_BUFF_SIZE]; struct _vector *vec = NULL; _lsm_err_msg_clear(err_msg); _good(_check_null_ptr(err_msg, 2 /* argument count */, fs, job), rc, out); _good(_get_db_from_plugin_ptr(err_msg, c, &db), rc, out); _good(_db_sql_trans_begin(err_msg, db), rc, out); sim_fs_id = _db_lsm_id_to_sim_id(lsm_fs_id_get(fs)); /* Check fs existence */ _good(_db_sim_fs_of_sim_id(err_msg, db, sim_fs_id, &sim_fs), rc, out); /* Check fs snapshot status */ _snprintf_buff(err_msg, rc, out, sql_cmd, "SELECT * FROM " _DB_TABLE_FS_SNAPS_VIEW " WHERE fs_id=%" PRIu64 ";", sim_fs_id); _good(_db_sql_exec(err_msg, db, sql_cmd, &vec), rc, out); if (_vector_size(vec) != 0) { rc = LSM_ERR_PLUGIN_BUG; /* TODO(Gris Ge): API does not have dedicate error for this scenario.*/ _lsm_err_msg_set(err_msg, "Specified filesystem has snapshot"); goto out; } _db_sql_exec_vec_free(vec); vec = NULL; /* Check fs clone(clone here means read and writeable snapshot) */ _snprintf_buff(err_msg, rc, out, sql_cmd, "SELECT * FROM " _DB_TABLE_FS_CLONES " WHERE src_fs_id = %" PRIu64 ";", sim_fs_id); _good(_db_sql_exec(err_msg, db, sql_cmd, &vec), rc, out); if (_vector_size(vec) != 0) { rc = LSM_ERR_PLUGIN_BUG; /* We don't have error number for this yet */ _lsm_err_msg_set(err_msg, "Specified fs is a clone source"); goto out; } _good(_db_data_delete(err_msg, db, _DB_TABLE_FSS, sim_fs_id), rc, out); _good(_job_create(err_msg, db, LSM_DATA_TYPE_NONE, _DB_SIM_ID_NONE, job), rc, out); _good(_db_sql_trans_commit(err_msg, db), rc, out); out: _db_sql_exec_vec_free(vec); if (sim_fs != NULL) lsm_hash_free(sim_fs); if (rc != LSM_ERR_OK) { _db_sql_trans_rollback(db); lsm_log_error_basic(c, rc, err_msg); if (job != NULL) *job = NULL; } else { rc = LSM_ERR_JOB_STARTED; } return rc; }