コード例 #1
0
int init_mc(struct ctx *p_ctx, res_hndl_t *res_hndl)
{
    int rc;
    __u64 chunks=16;
    __u64 actual_size=0;

    rc = mc_init();
    CHECK_RC(rc, "mc_init failed");
    debug("mc_init success :%d\n",rc);

    rc = ctx_init(p_ctx);
    CHECK_RC(rc, "Context init failed");

    rc = create_res(p_ctx);
    CHECK_RC(rc, "opening res_hndl");

    rc = mc_size1(p_ctx,chunks, &actual_size);
    CHECK_RC(rc, "mc_size");

    *res_hndl = p_ctx->res_hndl;

    rc = create_res(p_ctx);
    CHECK_RC(rc, "opening res_hndl");

    rc = mc_size1(p_ctx, chunks, &actual_size);
    CHECK_RC(rc, "mc_size");
    return 0;
}
コード例 #2
0
int test_scsi_cmds()
{
    int rc;
    struct ctx myctx;
    struct ctx *p_ctx = &myctx;
    __u64 chunk = 16;
    pthread_t thread;
    __u64 stride = 0x10;
    __u64 nlba;
    uint8_t opcode[]={ 0x00,0xA0,0x09E,0x12,0x03,0x1B,0x5A,0x55 };
    int index;
    pid = getpid();
    rc = ctx_init(p_ctx);
    int i;
    CHECK_RC(rc, "Context init failed");

    pthread_create(&thread,NULL,ctx_rrq_rx, p_ctx);

    p_ctx->flags = DK_UVF_ALL_PATHS;
    p_ctx->lun_size = chunk * p_ctx->chunk_size;
    rc = create_res(p_ctx);
    CHECK_RC(rc, "create_res failed");

    nlba = p_ctx->last_lba+1;
    for (index=0;index <sizeof(opcode);index++)
    {
        debug("%d:sending scsi cmd=0X%"PRIX8" ........\n",pid,opcode[index]);
        fill_send_write(p_ctx, nlba, pid, stride);
        for (i =0;i<NUM_CMDS;i++)
        {
            p_ctx->cmd[i].rcb.req_flags = SISL_REQ_FLAGS_RES_HNDL;
            p_ctx->cmd[i].rcb.req_flags |= SISL_REQ_FLAGS_HOST_READ;
            p_ctx->cmd[i].rcb.cdb[0] = opcode[index];
        }
        send_cmd(p_ctx);
        rc = wait_resp(p_ctx);
#ifndef _AIX
        if (rc != 0x21)
        {
            fprintf(stderr,"%d:failed rc =%d for scsi cmd=0X%"PRIX8",exptd rc=0x21\n",
                    pid,rc,opcode[index]);
            break;
        }
#endif
        debug("%d:rc =%d for scsi cmd=0X%"PRIX8" ........\n",pid,rc,opcode[index]);
        usleep(1000);
    }
    pthread_cancel(thread);
    ctx_close(p_ctx);
    return rc;
}
コード例 #3
0
ファイル: enc_query.c プロジェクト: ShawnOfMisfit/ambarella
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <mqueue.h>
#include <semaphore.h>

#include "ClearSilver.h"
#include "mxml.h"
#include "utils.h"

#define NAME_LEN 32
#define STREAM_NUM 8
#define create_fr(rotate,vflip,hflip) ((rotate << 2)|(vflip << 1)|(hflip))

typedef enum {
    HIGHRES_2592x1944 = create_res(2592,1944), //2592 x 1944 (5.0M)
    HIGHRES_2560x1440 = create_res(2560,1440), //2560 x 1440 (3.7M)
    HIGHRES_2304x1296 = create_res(2304,1296), //2304 x 1296 (3.0M)
    HIGHRES_2048x1536 = create_res(2048,1536)  //2048 x 1536 (3.0M)
}HIGHRES_INDEX;

typedef enum {
    FR_NORMAL = create_fr(0,0,0),
    FR_HFLIP = create_fr(0,0,1),
    FR_VFLIP = create_fr(0,1,0),
    FR_ROTATE_90 = create_fr(1,0,0),
    FR_ROTATE_180 = create_fr(0,1,1),
    FR_ROTATE_270 = create_fr(1,1,1)
}FR_INDEX;

CGI *cgi;
コード例 #4
0
int test_mc_invalid_opcode()
{
    int rc;
    struct ctx myctx;
    struct ctx *p_ctx = &myctx;
    __u64 chunks=10;
    __u64 actual_size=0;
    __u64 vlba =0;
    __u64 *p_u64;
    __u32 *p_u32;
    mc_stat_t l_mc_stat;
    pthread_t thread;

    if (mc_init() !=0 )
    {
        fprintf(stderr, "mc_init failed.\n");
        return -1;
    }
    debug("mc_init success.\n");

    rc = ctx_init(p_ctx);
    if (rc != 0)
    {
        fprintf(stderr, "Context init failed, errno %d\n", errno);
        return -1;
    }
    pthread_create(&thread,NULL,ctx_rrq_rx, p_ctx);
    /*rc = mc_register(master_dev_path, p_ctx->ctx_hndl,
       (volatile __u64 *)p_ctx->p_host_map,&p_ctx->mc_hndl);
       if(rc != 0)
       {
           fprintf(stderr, "ctx _reg failed, ctx_hndl %d,rc %d\n",p_ctx->ctx_hndl, rc );
           return -1;
       }*/

    rc = create_res(p_ctx);
    if (rc != 0)
    {
        fprintf(stderr, "error opening res_hndl rc %d\n", rc);
        return -1;
    }

    rc = mc_size1(p_ctx,chunks, &actual_size);
    CHECK_RC(rc, "mc_size");

    rc = mc_stat1(p_ctx, &l_mc_stat);
    CHECK_RC(rc, "mc_stat");

    pid = getpid();
    vlba = (actual_size * (1 << l_mc_stat.nmask))-1;
    fill_buf((__u64*)&p_ctx->wbuf[0][0],
             sizeof(p_ctx->wbuf[0])/sizeof(__u64),pid);

    memset((void *)&p_ctx->cmd[0].rcb.cdb[0], 0, sizeof(p_ctx->cmd[0].rcb.cdb));
    p_u64 = (__u64*)&p_ctx->cmd[0].rcb.cdb[2];

    p_ctx->cmd[0].rcb.res_hndl = p_ctx->res_hndl;
    p_ctx->cmd[0].rcb.req_flags = SISL_REQ_FLAGS_RES_HNDL;
    p_ctx->cmd[0].rcb.req_flags |= SISL_REQ_FLAGS_HOST_WRITE;
    write_lba(p_u64, vlba);

    p_ctx->cmd[0].rcb.data_ea = (__u64) &p_ctx->wbuf[0][0];

    p_ctx->cmd[0].rcb.data_len = sizeof(p_ctx->wbuf[0]);
    p_ctx->cmd[0].rcb.cdb[0] = 0xFA; // invalid opcode

    p_u32 = (__u32*)&p_ctx->cmd[0].rcb.cdb[10];
    write_32(p_u32, 8); // 8 LBAs for 4K

    p_ctx->cmd[0].sa.host_use[0] = 0; // 0 means active
    p_ctx->cmd[0].sa.ioasc = 0;
    send_single_cmd(p_ctx);
    rc = wait_single_resp(p_ctx);
    return rc;
}
コード例 #5
0
int mc_invalid_ioarcb(int cmd)
{
    int rc;
    struct ctx myctx;
    struct ctx *p_ctx = &myctx;
    __u64 chunks=32;
    __u64 actual_size=0;
    __u64 vlba =0;
    __u32 *p_u32;
    __u64 stride;
    __u64 *p_u64;
    pthread_t thread;
    mc_stat_t l_mc_stat;
    int i;

    pid = getpid();

    signal(SIGABRT, sig_handle);
    signal(SIGSEGV, sig_handle);
    rc = mc_init();
    CHECK_RC(rc, "mc_init failed");
    debug("mc_init success :%d\n",rc);

    rc = ctx_init(p_ctx);
    CHECK_RC(rc, "Context init failed");

    pthread_create(&thread,NULL,ctx_rrq_rx, p_ctx);

    if (15 == cmd)
    {
        //PLBA out of range
        rc = create_resource(p_ctx, 0, DK_UDF_ASSIGN_PATH, LUN_DIRECT);
        CHECK_RC(rc, "opening res_hndl");
        actual_size = (p_ctx->last_lba+1)/p_ctx->chunk_size;
    }
    else
    {
        p_ctx->flags = DK_UVF_ALL_PATHS;
        rc = create_res(p_ctx);
        CHECK_RC(rc, "opening res_hndl");
        rc = mc_size1(p_ctx,chunks, &actual_size);
        CHECK_RC(rc, "mc_size");
    }

    rc = mc_stat1(p_ctx, &l_mc_stat);
    CHECK_RC(rc, "mc_stat");
    stride  = 1 << l_mc_stat.nmask;

    vlba = (actual_size * (1 << l_mc_stat.nmask))-1;
    fill_send_write(p_ctx, vlba, pid, stride);
    for (i = 0; i < NUM_CMDS; i++)
    {
        if (1 == cmd)
        {
            //invalid upcode
            debug("invalid upcode(0xFA) action = %d\n",cmd);
            p_ctx->cmd[i].rcb.cdb[0] = 0xFA;
        }
        else if (2 == cmd)
        {
            //EA = NULL
            debug("EA = NULL action = %d\n",cmd);
            p_ctx->cmd[i].rcb.data_ea = (__u64)NULL;
#ifdef _AIX
            bad_address = true;
#endif
        }
        else if (3 == cmd)
        {
            //invalid flgas
            p_ctx->cmd[i].rcb.req_flags = SISL_REQ_FLAGS_RES_HNDL;
            p_ctx->cmd[i].rcb.req_flags |= SISL_REQ_FLAGS_HOST_READ;
            debug("invalid flag = 0X%X\n",p_ctx->cmd[i].rcb.req_flags);
        }
        else if (5 == cmd)
        {
            //SISL_AFU_RC_RHT_INVALID
            p_ctx->cmd[i].rcb.res_hndl   = p_ctx->res_hndl + 2;
        }
        else if ( 6 == cmd)
        {
            //SISL_AFU_RC_RHT_OUT_OF_BOUNDS
            p_ctx->cmd[i].rcb.res_hndl   = MAX_RES_HANDLE;
        }
        else if (7 == cmd)
        {
            //invalid address for page fault
            debug("setting EA = 0x1234 to generate error page fault\n");
            p_ctx->cmd[i].rcb.data_ea = (__u64)0x1234;
#ifdef _AIX
            bad_address = true;
#endif
        }
        else if (8 == cmd)
        {
            //invalid ctx_id
            debug("%d:  sending invalid ctx id\n", pid);
            p_ctx->cmd[i].rcb.ctx_id = p_ctx->ctx_hndl +10;
        }
        else if (9 == cmd)
        {
            //test flag underrun
            p_ctx->cmd[i].rcb.data_len = sizeof(p_ctx->wbuf[0])/2;
        }
        else if (10 == cmd)
        {
            // test flag overrun
            p_ctx->cmd[i].rcb.data_len = sizeof(p_ctx->wbuf[0]);
            p_u32 = (__u32*)&p_ctx->cmd[i].rcb.cdb[10];
            write_32(p_u32, 2);
        }
        else if (11 == cmd)
        {
            //rc scsi_rc_check
            p_u32 = (__u32*)&p_ctx->cmd[i].rcb.cdb[10];
            write_32(p_u32, p_ctx->blk_len +1);
        }
        else if (12 == cmd)
        {
            //data len 0 in ioarcb
            p_ctx->cmd[i].rcb.data_len = 0;
        }
        else if (13 == cmd)
        {
            //NUM  BLK to write 0
            p_u32 = (__u32*)&p_ctx->cmd[i].rcb.cdb[10];
            write_32(p_u32, 0);
        }
        else if ((14 == cmd) || (15 == cmd))
        {
            //test out of range LBAs
            p_u64 = (__u64*)&p_ctx->cmd[i].rcb.cdb[2];
            vlba += i+1;
            write_lba(p_u64, vlba);
        }
    }

    //test BAD IOARCB, IOASA & CMD room violation
    if (cmd >= 100)
    {
        if (100 == cmd)
        {
            //bad RCB
            place_bad_addresses(p_ctx, 1);
            usleep(1000);
            if (err_afu_intrpt) //cool expected res
                rc = 100;
            else rc = -1;
            goto END;
        }
        else if (101 == cmd)
        {
            //bad IOASA
            handle_bad_ioasa(p_ctx, pid);
            usleep(1000); //sleep sometime to process rcb cmd by AFU
            //And let handle rrq event
            //how to handle error, rrq thread should throw some error
            return -1;
        }
        else if (102 == cmd)
        {
            //cmd_room violation
            place_bad_addresses(p_ctx, 3);
            usleep(1000);
#ifdef _AIX
            if (err_afu_intrpt) //cool expected res
                rc = 102;
            else rc = -1;
            goto END;
#endif
        }
        else if (103 == cmd)
        {
            //bad HRRQ
            place_bad_addresses(p_ctx, 2);
            usleep(1000);
            if (err_afu_intrpt) //cool expected res
                rc = 103;
            else rc = -1;
            goto END;
        }
    }
    else
    {
        send_cmd(p_ctx);
    }
    rc = wait_resp(p_ctx);
    if ( cmd >= 9 && cmd <= 13)
    {
        if (!rc_flags)
        {
            if (!dont_displa_err_msg)
                fprintf(stderr, "%d: Expecting rc flags non zero\n", pid);
            rc = -1;
        }
    }
    if (4 == cmd)
    {
        //invalid fc port & lun id
        debug("invalid fc port(0xFF)&lun id(0X1200), action=%d",cmd);
        fill_send_write(p_ctx, vlba, pid, stride);
        for (i = 0; i < NUM_CMDS; i++)
        {
            p_ctx->cmd[i].rcb.lun_id = 0x12000;
            p_ctx->cmd[i].rcb.port_sel = 0xff;
        }
        //send_single_cmd(p_ctx);
        send_cmd(p_ctx);
        rc = wait_resp(p_ctx);
    }
#ifdef _AIX
    if ((7 == cmd || 2 == cmd)&& (err_afu_intrpt))
        rc = 7;
#endif
END:
    pthread_cancel(thread);
    close_res(p_ctx);
    //mc_unregister(p_ctx->mc_hndl);
    //xerror:
    ctx_close(p_ctx);
    mc_term();
    return rc;
}
コード例 #6
0
ファイル: enc_page.c プロジェクト: ShawnOfMisfit/ambarella
static int _add_encode_format (Page* currentPage, char* text, int streamId, char* enabled, int encMode)
{
	sprintf(text, "<fieldset><legend>Stream %d</legend><br>\n", streamId);
	char name[NAME_LEN] = {0};
	int index =0;
	int value = 0;
	char action[MAXSTRLEN] = {0};
	//type
	memset(options,0,MAX_OPTION_LEN*sizeof(Label_Option));

	options[OFF].value = OFF;
	strcat(options[OFF].option, "OFF");

	options[H_264].value = H_264;
	strcat(options[H_264].option, "H.264");

	options[MJPEG].value = MJPEG;
	strcat(options[MJPEG].option, "MJPEG");

	_get_name(name,streamId, "type");
	index = _get_enc_params_index(streamId, "type");
	select_Label select_label;
	memset(&select_label, 0, sizeof(select_Label));
	select_label.label = "Type :";
	select_label.name = name;
	select_label.options = options;
	select_label.option_len = TYPE_LEN;
	select_label.value = enc_params[index].value;
	select_label.action = enabled;
	(&virtual_PageOps)->create_select_label(currentPage, text, &select_label);
	strcat(text, "&nbsp; &nbsp; ");

	//enc_fps
	memset(options, 0, MAX_OPTION_LEN*sizeof(Label_Option));
	strcat(options[ENC_FPS_60].option, "60");
	options[ENC_FPS_60].value = FPS_60;

	strcat(options[ENC_FPS_30].option, "30");
	options[ENC_FPS_30].value = FPS_30;

	strcat(options[ENC_FPS_25].option, "25");
	options[ENC_FPS_25].value = FPS_25;

	strcat(options[ENC_FPS_20].option, "20");
	options[ENC_FPS_20].value = FPS_20;

	strcat(options[ENC_FPS_15].option, "15");
	options[ENC_FPS_15].value = FPS_15;

	strcat(options[ENC_FPS_10].option, "10");
	options[ENC_FPS_10].value = FPS_10;

	strcat(options[ENC_FPS_6].option, "6");
	options[ENC_FPS_6].value = FPS_6;

	strcat(options[ENC_FPS_5].option, "5");
	options[ENC_FPS_5].value = FPS_5;

	strcat(options[ENC_FPS_4].option, "4");
	options[ENC_FPS_4].value = FPS_4;

	strcat(options[ENC_FPS_3].option, "3");
	options[ENC_FPS_3].value = FPS_3;

	strcat(options[ENC_FPS_2].option, "2");
	options[ENC_FPS_2].value = FPS_2;

	strcat(options[ENC_FPS_1].option, "1");
	options[ENC_FPS_1].value = FPS_1;

	memset(name, 0, NAME_LEN);
	_get_name(name,streamId,"enc_fps");
	index = _get_enc_params_index(streamId, "enc_fps");
	memset(&select_label, 0, sizeof(select_Label));
	select_label.label = "Encode FPS :";
	select_label.name = name;
	select_label.options = options;
	select_label.option_len = ENC_FPS_LIST_LEN;
	select_label.value = enc_params[index].value;
	select_label.action = enabled;
	(&virtual_PageOps)->create_select_label(currentPage, text, &select_label);
	strcat(text, "&nbsp; &nbsp; ");


	//dptz
	memset(options,0,MAX_OPTION_LEN*sizeof(Label_Option));
	strcat(options[DPTZ_DISABLE].option, "Disable");
	options[DPTZ_DISABLE].value = DPTZ_DISABLE;
	strcat(options[DPTZ_ENABLE].option, "Enable");
	options[DPTZ_ENABLE].value = DPTZ_ENABLE;

	if (((enc_params[_get_enc_params_index(streamId, "width")].value) == 0 )||\
		((enc_params[_get_enc_params_index(streamId, "height")].value) == 0)) {
		value = create_res(1280,720);
	}
	else {
		value = create_res(enc_params[_get_enc_params_index(streamId,"width")].value,\
			enc_params[_get_enc_params_index(streamId,"height")].value);
	}


	if (encMode == ENC_LOW_DELAY) {
		strcat(action, "disabled");
	}
	else {
		if (strcmp(enabled,"disabled") == 0) {
			strcat(action,"disabled");
		}
		else {
			strcat(action,"");
		}
	}

	memset(name, 0, NAME_LEN);
	_get_name(name, streamId, "dptz");
	index = _get_enc_params_index(streamId, "dptz");
	memset(&select_label, 0, sizeof(select_Label));
	select_label.label = "DPTZ Type :";
	select_label.name = name;
	select_label.options = options;
	select_label.option_len = DPTZ_LEN;
	select_label.value = enc_params[index].value;
	select_label.action = action;
	(&virtual_PageOps)->create_select_label(currentPage, text, &select_label);
	strcat(text, "<br><br>\n");

	//resolution
	memset(options, 0, MAX_OPTION_LEN*sizeof(Label_Option));
	memset(action, 0, MAXSTRLEN);
	sprintf(action, "onchange=\"setDPTZMode(this.options[this.selectedIndex].value, %d)\" %s",\
		streamId, enabled);
	memset(name, 0, NAME_LEN);
	_get_name(name, streamId, "resolution");
	if ((encMode != ENC_HIGH_MP) || (streamId != 0)) {
		strcat(options[RES_OPS_1920x1080].option, "1920 x 1080");
		options[RES_OPS_1920x1080].value = RES_1920x1080;

		strcat(options[RES_OPS_1440x1080].option, "1440 x 1080");
		options[RES_OPS_1440x1080].value = RES_1440x1080;

		strcat(options[RES_OPS_1280x1024].option, "1280 x 1024");
		options[RES_OPS_1280x1024].value = RES_1280x1024;

		strcat(options[RES_OPS_1280x960].option, "1280 x 960");
		options[RES_OPS_1280x960].value = RES_1280x960;

		strcat(options[RES_OPS_1280x720].option, "1280 x 720");
		options[RES_OPS_1280x720].value = RES_1280x720;

		strcat(options[RES_OPS_800x600].option, "800 x 600");
		options[RES_OPS_800x600].value = RES_800x600;

		strcat(options[RES_OPS_720x576].option, "720 x 576");
		options[RES_OPS_720x576].value = RES_720x576;

		strcat(options[RES_OPS_720x480].option, "720 x 480");
		options[RES_OPS_720x480].value = RES_720x480;

		strcat(options[RES_OPS_640x480].option, "640 x 480");
		options[RES_OPS_640x480].value = RES_640x480;

		strcat(options[RES_OPS_352x288].option, "352 x 288");
		options[RES_OPS_352x288].value = RES_352x288;

		strcat(options[RES_OPS_352x240].option, "352 x 240");
		options[RES_OPS_352x240].value = RES_352x240;

		strcat(options[RES_OPS_320x240].option, "320 x 240");
		options[RES_OPS_320x240].value = RES_320x240;

		strcat(options[RES_OPS_176x144].option, "176 x 144");
		options[RES_OPS_176x144].value = RES_176x144;

		strcat(options[RES_OPS_176x120].option, "176 x 120");
		options[RES_OPS_176x120].value = RES_176x120;

		strcat(options[RES_OPS_160x120].option, "160 x 120");
		options[RES_OPS_160x120].value = RES_160x120;

		memset(&select_label, 0, sizeof(select_Label));
		select_label.label = "Resolution :";
		select_label.name = name;
		select_label.options = options;
		select_label.option_len = RES_OPTIONS_LEN;
		select_label.value = value;
		select_label.action = action;
		(&virtual_PageOps)->create_select_label(currentPage, text, &select_label);
	}else {
		strcat(options[HIGHRES_OPS_2592x1944].option, "2592x1944 (5.0M)");
		options[HIGHRES_OPS_2592x1944].value = HIGHRES_2592x1944;

		strcat(options[HIGHRES_OPS_2560x1440].option, "2560x1440 (3.7M)");
		options[HIGHRES_OPS_2560x1440].value = HIGHRES_2560x1440;

		strcat(options[HIGHRES_OPS_2304x1296].option, "2304x1296 (3.0M)");
		options[HIGHRES_OPS_2304x1296].value = HIGHRES_2304x1296;

		strcat(options[HIGHRES_OPS_2048x1536].option, "2048x1536 (3.0M)");
		options[HIGHRES_OPS_2048x1536].value = HIGHRES_2048x1536;

		memset(&select_label, 0, sizeof(select_Label));
		select_label.label = "Resolution :";
		select_label.name = name;
		select_label.options = options;
		select_label.option_len = HIGHRES_OPTIONS_LEN;
		select_label.value = value;
		select_label.action = action;
		(&virtual_PageOps)->create_select_label(currentPage, text, &select_label);
	}
	strcat(text,"&nbsp; &nbsp; ");

	/*
		Flip & Rotate
	*/
	memset(options, 0, MAX_OPTION_LEN*sizeof(Label_Option));
	strcat(options[FR_OPS_NORMAL].option, "Normal");
	options[FR_OPS_NORMAL].value = FR_NORMAL;

	strcat(options[FR_OPS_HFLIP].option, "Horizontal Flip");
	options[FR_OPS_HFLIP].value = FR_HFLIP;

	strcat(options[FR_OPS_VFLIP].option, "Vertical Flip");
	options[FR_OPS_VFLIP].value = FR_VFLIP;

	strcat(options[FR_OPS_ROTATE_90].option, "Rotate Clockwise 90");
	options[FR_OPS_ROTATE_90].value = FR_ROTATE_90;

	strcat(options[FR_OPS_ROTATE_180].option, "Rotate 180");
	options[FR_OPS_ROTATE_180].value = FR_ROTATE_180;

	strcat(options[FR_OPS_ROTATE_270].option, "Rotate Clockwise 270");
	options[FR_OPS_ROTATE_270].value = FR_ROTATE_270;

	memset(name, 0, NAME_LEN);
	_get_name(name,streamId,"flip_rotate");
	index = _get_enc_params_index(streamId, "flip_rotate");
	memset(&select_label, 0, sizeof(select_Label));
	select_label.label = "Flip & Rotate :";
	select_label.name = name;
	select_label.options = options;
	select_label.option_len = FR_OPTIONS_LEN;
	select_label.value = enc_params[index].value;
	select_label.action = enabled;
	(&virtual_PageOps)->create_select_label(currentPage, text, &select_label);

	_add_expand_format(currentPage, text, streamId, enabled);

	char* fieldset_end = "</fieldset><br>";
	strncat(text, fieldset_end, strlen(fieldset_end));

	return 0;
}
コード例 #7
0
int test_clone_ioctl(int cmd)
{
    struct ctx myctx;
    int i;
    pid_t cpid;
    struct ctx *p_ctx=&myctx;
    uint64_t nlba;
    uint64_t st_lba;
    uint64_t stride=0x1000;
    int rc=0;
    uint64_t src_ctx_id;
    uint64_t src_adap_fd;
    pthread_t thread;
    uint64_t resource[MAX_RES_HANDLE];
    uint64_t RES_CLOSED=-1;
    int cl_index[5]={ 1,7,10,12,15 };
    pid = getpid();
    rc =ctx_init(p_ctx);
    CHECK_RC(rc, "Context init failed");
    pthread_create(&thread, NULL, ctx_rrq_rx, p_ctx);
    p_ctx->flags = DK_UVF_ALL_PATHS;
    for (i=0;i<MAX_RES_HANDLE;i++)
    {
        p_ctx->lun_size = (i+1)*p_ctx->chunk_size;
        rc = create_res(p_ctx);
        CHECK_RC(rc, "create res failed");
        resource[i]=p_ctx->rsrc_handle;
    }
    for (i=0;i<5;i++)
    {
        p_ctx->rsrc_handle= resource[cl_index[i]];
        close_res(p_ctx);
        resource[cl_index[i]]= RES_CLOSED;
    }
    for (i=0; i<MAX_RES_HANDLE;i++)
    {
        if (RES_CLOSED == resource[i])
            continue;
        nlba = (i+1)*p_ctx->chunk_size;
        p_ctx->rsrc_handle = resource[i];
        p_ctx->res_hndl = p_ctx->rsrc_handle & RES_HNDLR_MASK;
        for (st_lba=0;st_lba<nlba;st_lba += (NUM_CMDS*stride))
        {
            rc = send_write(p_ctx,st_lba,stride,pid);
            CHECK_RC(rc, "send write failed\n");
        }
    }
    //write done cancel thread now
    pthread_cancel(thread);
    cpid = fork();
    if (cpid == 0)
    {
        //child process
        pid = getpid();
        ppid = getppid();
        //take backup parent ctx_id
        src_ctx_id= p_ctx->context_id;
        src_adap_fd = p_ctx->adap_fd;
        //do unmap parent mmio 1st
        rc =munmap((void *)p_ctx->p_host_map, p_ctx->mmio_size);
        CHECK_RC_EXIT(rc, "munmap failed\n");
        //do fresh attach for child
        rc = ctx_init_internal(p_ctx,DK_AF_ASSIGN_AFU,p_ctx->devno);
        CHECK_RC_EXIT(rc, "ctx_init_internal failed");
        pthread_create(&thread, NULL,ctx_rrq_rx,p_ctx);
        //do clone
        rc = ioctl_dk_capi_clone(p_ctx, src_ctx_id,src_adap_fd);
        CHECK_RC_EXIT(rc, "clone ioctl failed");
        //do read data
        for (i=0; i< MAX_RES_HANDLE;i++)
        {
            if (RES_CLOSED == resource[i])
                continue;
            p_ctx->rsrc_handle = resource[i];
            p_ctx->res_hndl = p_ctx->rsrc_handle & RES_HNDLR_MASK;
            nlba = (i+1)*p_ctx->chunk_size;
            for (st_lba=0;st_lba<nlba; st_lba+=(NUM_CMDS*stride))
            {
                rc = send_read(p_ctx,st_lba,stride);
                CHECK_RC_EXIT(rc,"send_read failed\n");
                rc = rw_cmp_buf_cloned(p_ctx, st_lba);
                CHECK_RC_EXIT(rc,"rw_cmp_buf_cloned failed\n");
            }
        }
        sleep(1);
        //now create closed resources
        p_ctx->flags = DK_UVF_ALL_PATHS;
        for (i=0; i < 5;i++)
        {
            p_ctx->lun_size = (cl_index[i]+1)*p_ctx->chunk_size;
            rc = create_res(p_ctx);
            CHECK_RC_EXIT(rc,"res_create failed\n");
            resource[cl_index[i]] = p_ctx->rsrc_handle;
        }
        //do io on new resources
        p_ctx->st_lba = 0;
        for (i=0;i<5;i++)
        {
            p_ctx->last_lba = ((cl_index[i]+1)*p_ctx->chunk_size) -1;
            p_ctx->res_hndl = resource[cl_index[i]] & RES_HNDLR_MASK;
            rc = do_io(p_ctx, stride);
            CHECK_RC_EXIT(rc, "do_io failed\n");
        }
        pthread_cancel(thread);
        ctx_close(p_ctx);
        exit(0);
    } //child process end
    else
    {
        //create pthread
        sleep(1); //let child process do clone & read written data
        pthread_create(&thread, NULL, ctx_rrq_rx, p_ctx);
        //do open closed res
        //now create closed resources
        p_ctx->flags = DK_UVF_ALL_PATHS;
        for (i=0; i < 5;i++)
        {
            p_ctx->lun_size = (cl_index[i]+1)*p_ctx->chunk_size;
            rc = create_res(p_ctx);
            CHECK_RC_EXIT(rc,"res_create failed\n");
            resource[cl_index[i]] = p_ctx->rsrc_handle;
        }
        //do resize all resources & IO
        for (i=0;i<MAX_RES_HANDLE;i++)
        {
            p_ctx->req_size = (rand()%MAX_RES_HANDLE +1) * p_ctx->chunk_size;
            p_ctx->rsrc_handle = resource[i];
            p_ctx->res_hndl = p_ctx->rsrc_handle & RES_HNDLR_MASK;
            rc = ioctl_dk_capi_vlun_resize(p_ctx);
            CHECK_RC(rc, "dk_capi_resize_ioctl failed\n");
            rc = do_io(p_ctx, stride);
            CHECK_RC(rc, "do_io failed\n");
        }
        //close res
        for (i=0;i<MAX_RES_HANDLE;i++)
        {
            p_ctx->rsrc_handle = resource[i];
            rc = close_res(p_ctx);
            CHECK_RC(rc, "cose_res failed\n");
        }

        pthread_cancel(thread);
        ctx_close(p_ctx);
        rc = wait4all();
    }
    return rc;
}