Ejemplo n.º 1
0
Archivo: attr.c Proyecto: snsl/osc-osd
/*
 * get the directory page of the object.
 *
 * returns:
 * -EINVAL: invalid arg, ignore used_len 
 * -ENOENT: error, attribute not found
 * OSD_ERROR: some other error
 * OSD_OK: success, used_outlen modified
 */
int attr_get_dir_page(struct db_context *dbc, uint64_t pid, uint64_t oid, 
		      uint32_t page, uint64_t outlen, void *outdata,
		      uint8_t listfmt, uint32_t *used_outlen)
{
	int ret = 0;
	sqlite3_stmt *stmt = NULL;

	assert(dbc && dbc->db && dbc->attr && dbc->attr->dirpage);

	if (page != USEROBJECT_DIR_PG && page != COLLECTION_DIR_PG &&
	    page != PARTITION_DIR_PG && page != ROOT_DIR_PG)
		return -EINVAL;
repeat:
	ret = 0;
	stmt = dbc->attr->dirpage;
	ret |= sqlite3_bind_blob(stmt, 1, unid_page, sizeof(unid_page), 
				 SQLITE_TRANSIENT);
	ret |= sqlite3_bind_int64(stmt, 2, pid);
	ret |= sqlite3_bind_int64(stmt, 3, oid);
	ret = exec_attr_rtrvl_stmt(dbc, stmt, ret, __func__, oid, page,
				   GATHER_DIR_PAGE, outlen, outdata, listfmt,
				   used_outlen);
	if (ret == OSD_REPEAT) {
		goto repeat;
	} else if (ret == -ENOENT) {
		osd_debug("%s: dir page not found!", __func__);
	}

	return ret;
}
Ejemplo n.º 2
0
Archivo: attr.c Proyecto: snsl/osc-osd
/*
 * get all attributes for an object in a list format
 *
 * XXX:SD If the page is defined and we don't have name for the page (attr
 * num == 0), then we don't return its name. That is a bug
 *
 * returns: 
 * -EINVAL: invalid arg, ignore used_len 
 * -ENOENT: error, attribute not found
 * OSD_ERROR: some other error
 * OSD_OK: success, used_outlen modified
 */
int attr_get_all_attrs(struct db_context *dbc, uint64_t pid, uint64_t oid,
		       uint64_t outlen, void *outdata, uint8_t listfmt, 
		       uint32_t *used_outlen)
{
	int ret = 0;
	sqlite3_stmt *stmt = NULL;

	assert(dbc && dbc->db && dbc->attr && dbc->attr->getall);

repeat:
	ret = 0;
	stmt = dbc->attr->getall;
	ret |= sqlite3_bind_int64(stmt, 1, pid);
	ret |= sqlite3_bind_int64(stmt, 2, oid);
	ret = exec_attr_rtrvl_stmt(dbc, stmt, ret, __func__, oid, 0,
				   GATHER_ATTR, outlen, outdata, listfmt,
				   used_outlen);
	if (ret == OSD_REPEAT) {
		goto repeat;
	} else if (ret == -ENOENT) {
		osd_debug("%s: attr (%llu %llu * *) not found!", __func__, 
			  llu(pid), llu(oid));
	}

	return ret;
}
Ejemplo n.º 3
0
/*
 * return the type of the object
 *
 * returns:
 * -EINVAL: invalid arg, ignore value of obj_type
 * OSD_ERROR: any other error, ignore value of obj_type
 * OSD_OK: success in determining the type, either valid or invalid. 
 * 	obj_types set to the determined type.
 */
int obj_get_type(void *ohandle, uint64_t pid, uint64_t oid, 
		 uint8_t *obj_type)
{
  struct db_context *dbc = ((struct handle*)ohandle)->dbc;
	int ret = 0;
	int bound = 0;
	*obj_type = ILLEGAL_OBJ;

	assert(dbc && dbc->db && dbc->obj && dbc->obj->gettype);

repeat:
	ret = 0;
	ret |= sqlite3_bind_int64(dbc->obj->gettype, 1, pid);
	ret |= sqlite3_bind_int64(dbc->obj->gettype, 2, oid);
	bound = (ret == SQLITE_OK);
	if (!bound) {
		error_sql(dbc->db, "%s: bind failed", __func__);
		goto out_reset;
	}

	while ((ret = sqlite3_step(dbc->obj->gettype)) == SQLITE_BUSY);
	if (ret == SQLITE_ROW) {
		*obj_type = sqlite3_column_int(dbc->obj->gettype, 0);
	} else if (ret == SQLITE_DONE) {
		osd_debug("%s: object (%llu %llu) doesn't exist", __func__, 
			  llu(pid), llu(oid));
	} 

out_reset:
	ret = db_reset_stmt(dbc, dbc->obj->gettype, bound, __func__);
	if (ret == OSD_REPEAT)
		goto repeat;
out:
	return ret;
}
Ejemplo n.º 4
0
Archivo: attr.c Proyecto: snsl/osc-osd
/*
 * get one attribute value.
 *
 * -EINVAL: invalid arg, ignore used_len 
 * -ENOENT: error, attribute not found
 * OSD_ERROR: some other error
 * OSD_OK: success, used_outlen modified
 */
int attr_get_val(struct db_context *dbc, uint64_t pid, uint64_t oid,
		 uint32_t page, uint32_t number, uint64_t outlen,
		 void *outdata, uint32_t *used_outlen)
{
	int ret = 0;
	sqlite3_stmt *stmt = NULL;

	assert(dbc && dbc->db && dbc->attr && dbc->attr->getval);

repeat:
	ret = 0;
	stmt = dbc->attr->getval;
	ret |= sqlite3_bind_int64(stmt, 1, pid);
	ret |= sqlite3_bind_int64(stmt, 2, oid);
	ret |= sqlite3_bind_int(stmt, 3, page);
	ret |= sqlite3_bind_int(stmt, 4, number);
	ret = exec_attr_rtrvl_stmt(dbc, stmt, ret, __func__, oid, 0, 
				   GATHER_VAL, outlen, outdata, 0,
				   used_outlen); 
	if (ret == OSD_REPEAT) {
		goto repeat;
	} else if (ret == -ENOENT) {
		osd_debug("%s: attr (%llu %llu %u %u) not found!", __func__, 
			  llu(pid), llu(oid), page, number);
	}

	return ret;
}
Ejemplo n.º 5
0
static int do_osd_debug(cmd_tbl_t *cmdtp, int flag, int argc,
			char *const argv[])
{
	int ret = 0;
	int level = 0;

	switch (argc) {
	case 1:
		osd_debug();
		break;
	case 2:
		level = simple_strtoul(argv[1], NULL, 10);
		osd_set_log_level(level);
		break;
	default:
		return CMD_RET_USAGE;
	}

	return ret;
}