Beispiel #1
0
Bitcask* bc_open(const char* path, int depth, int pos, time_t before)
{
    if (path == NULL || depth > 4) return NULL;
    if (0 != access(path, F_OK) && 0 != mkdir(path, 0750)){
        fprintf(stderr, "mkdir %s failed\n", path);
        return NULL;
    }
    const char* t[] = {path};
    Mgr *mgr = mgr_create(t, 1);
    Bitcask* bc = bc_open2(mgr, depth, pos, before);
    bc_scan(bc);
    return bc;
}
Beispiel #2
0
/*
 *  ======== dev_start_device ========
 *  Purpose:
 *      Initializes the new device with the BRIDGE environment.
 */
int dev_start_device(struct cfg_devnode *dev_node_obj)
{
	struct dev_object *hdev_obj = NULL;	/* handle to 'Bridge Device */
	/* Bridge driver filename */
	char bridge_file_name[CFG_MAXSEARCHPATHLEN] = "UMA";
	int status;
	struct mgr_object *hmgr_obj = NULL;
	struct drv_data *drv_datap = dev_get_drvdata(bridge);

	DBC_REQUIRE(refs > 0);

	/* Given all resources, create a device object. */
	status = dev_create_device(&hdev_obj, bridge_file_name,
				   dev_node_obj);
	if (!status) {
		/* Store away the hdev_obj with the DEVNODE */
		if (!drv_datap || !dev_node_obj) {
			status = -EFAULT;
			pr_err("%s: Failed, status 0x%x\n", __func__, status);
		} else if (!(strcmp((char *)dev_node_obj, "TIOMAP1510"))) {
			drv_datap->dev_object = (void *) hdev_obj;
		}
		if (!status) {
			/* Create the Manager Object */
			status = mgr_create(&hmgr_obj, dev_node_obj);
			if (status && !(strcmp((char *)dev_node_obj,
							"TIOMAP1510"))) {
				/* Ensure the device extension is NULL */
				drv_datap->dev_object = NULL;
			}
		}
		if (status) {
			/* Clean up */
			dev_destroy_device(hdev_obj);
			hdev_obj = NULL;
		}
	}

	return status;
}
Beispiel #3
0
/*
 *  ======== dev_start_device ========
 *  Purpose:
 *      Initializes the new device with the BRIDGE environment.
 */
int dev_start_device(struct cfg_devnode *dev_node_obj)
{
	struct dev_object *hdev_obj = NULL;	/* handle to 'Bridge Device */
	/* wmd filename */
	char sz_wmd_file_name[CFG_MAXSEARCHPATHLEN] = "UMA";
	int status;
	struct mgr_object *hmgr_obj = NULL;

	DBC_REQUIRE(refs > 0);

		/* Given all resources, create a device object. */
		status =
	    dev_create_device(&hdev_obj, sz_wmd_file_name,
				      dev_node_obj);
		if (DSP_SUCCEEDED(status)) {
			/* Store away the hdev_obj with the DEVNODE */
			status =
			    cfg_set_dev_object(dev_node_obj, (u32) hdev_obj);
			if (DSP_FAILED(status)) {
				/* Clean up */
				dev_destroy_device(hdev_obj);
				hdev_obj = NULL;
			}
		}
	if (DSP_SUCCEEDED(status)) {
		/* Create the Manager Object */
		status = mgr_create(&hmgr_obj, dev_node_obj);
	}
	if (DSP_FAILED(status)) {
		if (hdev_obj)
			dev_destroy_device(hdev_obj);

		/* Ensure the device extension is NULL */
		cfg_set_dev_object(dev_node_obj, 0L);
	}

	return status;
}
Beispiel #4
0
HStore* hs_open(char *path, int height, time_t before, int scan_threads)
{
    if (NULL == path) return NULL;
    if (height < 0 || height > 3) {
        fprintf(stderr, "invalid db height: %d\n", height);
        return NULL; 
    }
    if (before != 0){
        if (before<0) {
            fprintf(stderr, "invalid time:%ld\n", before);
            return NULL;
        }else{
            fprintf(stderr, "serve data modified before %s\n", ctime(&before));
        }
    }
    
    char *paths[20], *rpath = path;
    int npath = 0;
    while ((paths[npath] = strsep(&rpath, ",:;")) != NULL) {
        if (npath >= MAX_PATHS) return NULL; 
        path = paths[npath];
        if (0 != access(path, F_OK) && 0 != mkdir(path, 0755)){
            fprintf(stderr, "mkdir %s failed\n", path);
            return NULL;
        }
        if (height > 1){
            // try to mkdir
            HStore *s = hs_open(path, height - 1, 0, 0);
            if (s == NULL){
                return NULL;
            }
            hs_close(s);
        }
        
        npath ++;
    }

    int i, j, count = 1 << (height * 4);
    HStore *store = (HStore*) malloc(sizeof(HStore) + sizeof(Bitcask*) * count);
    if (!store) return NULL;
    memset(store, 0, sizeof(HStore) + sizeof(Bitcask*) * count);
    store->height = height;
    store->count = count;
    store->before = before;
    store->scan_threads = scan_threads;
    store->op_start = 0;
    store->op_end = 0;
    store->op_limit = 0;
    store->mgr = mgr_create((const char**)paths, npath);
    if (store->mgr == NULL) {
        free(store);
        return NULL;
    }
    for (i=0; i<NUM_OF_MUTEX; i++) {
        pthread_mutex_init(&store->locks[i], NULL);
    }

    char *buf[20] = {0};
    for (i=0;i<npath;i++) {
        buf[i] = malloc(255);
    }
    for (i=0; i<count; i++){
        for (j=0; j<npath; j++) {
            path = paths[j];
            switch(height){
                case 0: sprintf(buf[j], "%s", path); break;
                case 1: sprintf(buf[j], "%s/%x", path, i); break;
                case 2: sprintf(buf[j], "%s/%x/%x", path, i>>4, i & 0xf); break;
                case 3: sprintf(buf[j], "%s/%x/%x/%x", path, i>>8, (i>>4)&0xf, i&0xf); break;
            }
        }
        Mgr *mgr = mgr_create((const char**)buf, npath);
        if (mgr == NULL) return NULL;
        store->bitcasks[i] = bc_open2(mgr, height, i, before);
    }
    for (i=0;i<npath;i++) {
        free(buf[i]);
    }
   
    if (store->scan_threads > 1 && count > 1) {
        parallelize(store, bc_scan);
    }else{
        for (i=0; i<count; i++) {
            bc_scan(store->bitcasks[i]);
        }
    }

    return store;
}