コード例 #1
0
static void
verify_persistent_reserve_access(struct scsi_device *sd1, struct scsi_device *sd2,
    const enum scsi_persistent_out_type pr_type,
    int reg_i2_can_read,
    int reg_i2_can_write,
    int unreg_i2_can_read,
    int unreg_i2_can_write)
{
        int ret;
        const unsigned long long key = rand_key();
        const unsigned long long key2 = rand_key();


        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE,
            "Verify access for reservation type: %s",
            scsi_pr_type_str(pr_type));

        /* send TURs to clear possible check conditions */
        (void) testunitready_clear_ua(sd1);
        (void) testunitready_clear_ua(sd2);

        /* register our reservation key with the target */
        ret = prout_register_and_ignore(sd1, key);
        if (ret == -2) {
                CU_PASS("PERSISTENT RESERVE OUT is not implemented.");
                return;
        }        
        CU_ASSERT_EQUAL(0, ret);
        ret = prout_register_and_ignore(sd2, key2);
        CU_ASSERT_EQUAL(0, ret);

        /* reserve the target through initiator 1 */
        ret = prout_reserve(sd1, key, pr_type);
        CU_ASSERT_EQUAL(0, ret);

        /* verify target reservation */
        ret = prin_verify_reserved_as(sd1,
            pr_type_is_all_registrants(pr_type) ? 0 : key,
            pr_type);
        CU_ASSERT_EQUAL(0, ret);

        CU_ASSERT_PTR_NOT_NULL_FATAL(scratch);

        /* make sure init1 can read */
        ret = verify_read_works(sd1, scratch);
        CU_ASSERT_EQUAL(0, ret);

        /* make sure init1 can write */
        ret = verify_write_works(sd1, scratch);
        CU_ASSERT_EQUAL(0, ret);

        /* verify registered init2 read access */
        if (reg_i2_can_read)
                ret = verify_read_works(sd2, scratch);
        else
                ret = verify_read_fails(sd2, scratch);
        CU_ASSERT_EQUAL(0, ret);

        /* verify registered init2 write access */
        if (reg_i2_can_write)
                ret = verify_write_works(sd2, scratch);
        else
                ret = verify_write_fails(sd2, scratch);
        CU_ASSERT_EQUAL(0, ret);

        /* unregister init2 */
        ret = prout_register_key(sd2, 0, key2);
        CU_ASSERT_EQUAL(0, ret);

        /* verify unregistered init2 read access */
        if (unreg_i2_can_read)
                ret = verify_read_works(sd2, scratch);
        else
                ret = verify_read_fails(sd2, scratch);
        CU_ASSERT_EQUAL(0, ret);

        /* verify unregistered init2 write access */
        if (unreg_i2_can_write)
                ret = verify_write_works(sd2, scratch);
        else
                ret = verify_write_fails(sd2, scratch);
        CU_ASSERT_EQUAL(0, ret);

        /* release our reservation */
        ret = prout_release(sd1, key, pr_type);
        CU_ASSERT_EQUAL(0, ret);

        /* remove our key from the target */
        ret = prout_register_key(sd1, 0, key);
        CU_ASSERT_EQUAL(0, ret);
}
コード例 #2
0
void
test_verify16_beyond_eol(void)
{ 
	int i, ret;
	unsigned char *buf = alloca(256 * block_size);


	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test VERIFY16 1-256 blocks one block beyond the end");
	for (i = 1; i <= 256; i++) {
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}

		ret = verify16_lbaoutofrange(iscsic, tgt_lun, num_blocks + 1 - i,
					   i * block_size, block_size,
					   0, 0, 1, buf);
		if (ret == -2) {
			logging(LOG_NORMAL, "[SKIPPED] VERIFY16 is not implemented.");
			CU_PASS("[SKIPPED] Target does not support VERIFY16. Skipping test");
			return;
		}
		CU_ASSERT_EQUAL(ret, 0);
	}


	logging(LOG_VERBOSE, "Test VERIFY16 1-256 blocks at LBA==2^63");
	for (i = 1; i <= 256; i++) {
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}

		ret = verify16_lbaoutofrange(iscsic, tgt_lun, 0x8000000000000000,
					   i * block_size, block_size,
					   0, 0, 1, buf);
		CU_ASSERT_EQUAL(ret, 0);
	}


	logging(LOG_VERBOSE, "Test VERIFY16 1-256 blocks at LBA==-1");
	for (i = 1; i <= 256; i++) {
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}

		ret = verify16_lbaoutofrange(iscsic, tgt_lun, -1, i * block_size,
					   block_size, 0, 0, 1, buf);
		CU_ASSERT_EQUAL(ret, 0);
	}


	logging(LOG_VERBOSE, "Test VERIFY16 2-256 blocks all but one block beyond the end");
	for (i = 2; i <= 256; i++) {
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}

		ret = verify16_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1,
					   i * block_size, block_size,
					   0, 0, 1, buf);
		CU_ASSERT_EQUAL(ret, 0);
	}
}
コード例 #3
0
void *sock_port_mapper(void *arg){

    struct sockaddr_in server_sockaddr, client_sockaddr;
    int sin_size, recvbytes, sendbytes;
    int sockfd, client_fd, desc_ready;
    char logmsg[128];

    sin_size=sizeof(client_sockaddr);

    /* Data structure to handle timeout */
    struct timeval before, timer, *tvptr;
    struct timezone tzp;
    
    /* Data structure for the select I/O */
    fd_set ready_set, test_set;
    int maxfd, nready, client[FD_SETSIZE];

    /* create socket */
    sockfd = Socket(AF_INET,SOCK_STREAM,0);

    /* set parameters for sockaddr_in */
    server_sockaddr.sin_family = AF_INET;
    server_sockaddr.sin_port = htons(PORT); //0, assign port automatically in 1024 ~ 65535
    server_sockaddr.sin_addr.s_addr = htonl(INADDR_ANY); //0, got local IP automatically
    bzero(&(server_sockaddr.sin_zero), 8);
   
    int i = 1;//enable reuse the combination of local address and socket
    setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, &i, sizeof(i));
    Bind(sockfd, server_sockaddr);

    getaddr(hostname, addrstr); //get hostname and ip, getaddrinfo.h
    port = Getsockname(sockfd, server_sockaddr, sin_size);  /* Get the port number assigned*/
    writePortMapper(port, addrstr, PORT_MAPPER_FILE);
    
    snprintf(logmsg, sizeof(logmsg), "sockserver: Server %s (%s) is setup on port: %d\n", addrstr, hostname, port);
    logging(LOGFILE, logmsg);
    Listen(sockfd, MAX_QUE_CONN_NM);
   
    /* Thread attribute */
    pthread_attr_t attr;
    pthread_attr_init(&attr); // Creating thread attributes
    pthread_attr_setschedpolicy(&attr, SCHED_RR); // Round Robin scheduling for threads 
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); // Don't want threads (particualrly main)
    int iThread = 0; // Thread iterator

    /* Set up the I/O for the socket, nonblocking */
    maxfd = sockfd;
    int k;
    for(k=0;k<FD_SETSIZE;k++){
        client[k] = -1;
    }
    FD_ZERO(&ready_set);
    FD_ZERO(&test_set);
    FD_SET(sockfd, &test_set);
  
    /* Initialize the timeval struct to TIMER seconds */
    timer.tv_sec = TIMER;
    timer.tv_usec = 0;
    tvptr = &timer;

    /* Set up the time out by getting the time of the day from the system */
    gettimeofday(&before, &tzp);

    int status;
    status=CONTINUE;
    while (status==CONTINUE){
        if (iThread == NTHREADS){
            iThread = 0;
        }

        memcpy(&ready_set, &test_set, sizeof(test_set));
        nready = select(maxfd+1, &ready_set, NULL, NULL, tvptr);

        switch(nready){
            case -1:
                printf("sockserver: errno: %d.\n", errno);
                perror("\nSELECT: unexpected error occured.\n");
                logging(LOGFILE, "\nSELECT: unexpected error occured.\n");

                /* remove bad fd */
                for(k=0;k<FD_SETSIZE;k++){
                    if(client[k] > 0){
                        struct stat tStat;
                        if (-1 == fstat(client[k], &tStat)){
                            printf("fstat %d error:%s", sockfd, strerror(errno));
                            FD_CLR(client[k], &ready_set);
                        }
                    }
                }
                status=-1;
                break;
            case 0:
                /* timeout occuired */
                printf("sockserver: TIMEOUT... %d.\n", errno);
                status=-1;
                break;
            default:
                if (FD_ISSET(sockfd, &ready_set)){
                    //snprintf(logmsg, sizeof(logmsg), "sockserver(0x%x): Listening socket is readable\n", pthread_self());
                    //logging(LOGFILE, logmsg);
                    /* wait for connection */
                    client_fd = Accept(sockfd, client_sockaddr, sin_size);
                    for(k=0;k<FD_SETSIZE;k++){
                        if(client[k] < 0){
                            client[k] = client_fd;
                        }
                    }

                    FD_SET(client_fd, &test_set);
                    if (client_fd > maxfd) maxfd = client_fd;
                    snprintf(logmsg, sizeof(logmsg), "sockserver(0x%x): Descriptor %d is readable\n",  pthread_self(), client_fd);
                    logging(LOGFILE, logmsg);
                    pthread_create(&threadid[iThread], &attr, &port_mapper_thread, (void *)client_fd);
                    pthread_join(threadid[iThread], NULL);
                    iThread++;
                }// end if (FD_ISSET(i, &ready_set))
        }// end switch
        usleep(100);
    } // end while (status==CONTINUE)
    close(sockfd);
    unlinkPortFile(addrstr);

    return 0;
}
コード例 #4
0
core::memory_allocator::RuleMirroredAppDirectNotSupported::~RuleMirroredAppDirectNotSupported()
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
}
コード例 #5
0
void
test_writeatomic16_vpd(void)
{
	int ret;
	struct scsi_inquiry_block_limits *bl;
	struct scsi_task *bl_task = NULL;
	int gran;
	unsigned char *buf;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test WRITEATOMIC16 VPD data");

	CHECK_FOR_SBC;
	CHECK_FOR_DATALOSS;


	logging(LOG_VERBOSE, "Block device. Verify that we can read Block "
		"Limits VPD");
	ret = inquiry(sd, &bl_task,
		      1, SCSI_INQUIRY_PAGECODE_BLOCK_LIMITS, 255,
		      EXPECT_STATUS_GOOD);
	CU_ASSERT_EQUAL(ret, 0);
	if (ret != 0) {
		logging(LOG_NORMAL, "[FAILURE] failed to read Block Limits VDP");
		CU_FAIL("[FAILURE] failed to read Block Limits VDP");
		goto finished;
	}
	bl = scsi_datain_unmarshall(bl_task);
	if (bl == NULL) {
		logging(LOG_NORMAL, "[FAILURE] failed to unmarshall Block Limits VDP");
		CU_FAIL("[FAILURE] failed to unmarshall Block Limits VDP");
		goto finished;
	}


	logging(LOG_VERBOSE, "Check if WRITEATOMIC16 is supported");
	gran = inq_bl->atomic_gran ? inq_bl->atomic_gran : 1;
	buf = alloca(block_size * gran);
	memset(buf, 0x00, block_size * gran);
	ret = writeatomic16(sd, 0, block_size * gran,
			    block_size, 0, 0, 0, 0, buf,
			    EXPECT_STATUS_GOOD);
	if (ret == -2) {
		logging(LOG_VERBOSE, "WRITEATOMIC16 is NOT supported by the target.");

		logging(LOG_VERBOSE, "Verify that MAXIMUM_ATOMIC_TRANSFER_LENGTH is zero");
		if (bl->max_atomic_xfer_len) {
			logging(LOG_VERBOSE, "MAXIMUM_ATOMIC_TRANSFER_LENGTH is non-zero but target does not support ATOMICWRITE16");
			CU_FAIL("MAXIMUM_ATOMIC_TRANSFER_LENGTH is non-zero but target does not support ATOMICWRITE16");
		}

		logging(LOG_VERBOSE, "Verify that ATOMIC_ALIGNMENT is zero");
		if (bl->atomic_align) {
			logging(LOG_VERBOSE, "ATOMIC_ALIGNMENT is non-zero but target does not support ATOMICWRITE16");
			CU_FAIL("ATOMIC_ALIGNMENT is non-zero but target does not support ATOMICWRITE16");
		}

		logging(LOG_VERBOSE, "Verify that ATOMIC_GRANULARITY is zero");
		if (bl->atomic_gran) {
			logging(LOG_VERBOSE, "ATOMIC_GRANULARITY is non-zero but target does not support ATOMICWRITE16");
			CU_FAIL("ATOMIC_GRANULARITY is non-zero but target does not support ATOMICWRITE16");
		}
		goto finished;
	}

	logging(LOG_VERBOSE, "WRITEATOMIC16 IS supported by the target.");
	logging(LOG_VERBOSE, "Verify that MAXIMUM_ATOMIC_TRANSFER_LENGTH is non-zero");
	if (!bl->max_atomic_xfer_len) {
		logging(LOG_VERBOSE, "[WARNING] MAXIMUM_ATOMIC_TRANSFER_LENGTH is zero but target supports ATOMICWRITE16");
		CU_FAIL("[WARNING] MAXIMUM_ATOMIC_TRANSFER_LENGTH is zero but target supports ATOMICWRITE16");
	}

	logging(LOG_VERBOSE, "Verify that MAXIMUM_ATOMIC_TRANSFER_LENGTH is less than or equal to MAXIMUM_TRANSFER_LENGTH");
	if (bl->max_atomic_xfer_len > bl->max_xfer_len) {
		logging(LOG_VERBOSE, "[FAILED] MAXIMUM_ATOMIC_TRANSFER_LENGTH is greater than MAXIMUM_TRANSFER_LENGTH");
		CU_FAIL("[FAILED] MAXIMUM_ATOMIC_TRANSFER_LENGTH is greater than MAXIMUM_TRANSFER_LENGTH");
	}

	logging(LOG_VERBOSE, "Check handling on misaligned writes");
	if (bl->atomic_align < 2) {
		logging(LOG_VERBOSE, "[SKIPPED] No alignment restrictions on this LUN");
	} else {
		logging(LOG_VERBOSE, "Atomic Write at LBA 1 should fail due to misalignment");
		ret = writeatomic16(sd, 1, block_size * gran,
				    block_size, 0, 0, 0, 0, buf,
				    EXPECT_INVALID_FIELD_IN_CDB);
		if (ret) {
			logging(LOG_VERBOSE, "[FAILED] Misaligned write did NOT fail with INVALID_FIELD_IN_CDB");
		CU_FAIL("[FAILED] Misaligned write did NOT fail with INVALID_FIELD_IN_CDB");
		}
	}

	logging(LOG_VERBOSE, "Check handling on invalid granularity");
	if (bl->atomic_gran < 2) {
		logging(LOG_VERBOSE, "[SKIPPED] No granularity restrictions on this LUN");
	} else {
		logging(LOG_VERBOSE, "Atomic Write of 1 block should fail due to invalid granularity");
		ret = writeatomic16(sd, 0, block_size,
				    block_size, 0, 0, 0, 0, buf,
				    EXPECT_INVALID_FIELD_IN_CDB);
		if (ret) {
			logging(LOG_VERBOSE, "[FAILED] Misgranularity write did NOT fail with INVALID_FIELD_IN_CDB");
		CU_FAIL("[FAILED] Misgranularity write did NOT fail with INVALID_FIELD_IN_CDB");
		}
	}


finished:
	scsi_free_scsi_task(bl_task);
}
int env_set(HASHTBL * task_tbl, oph_operator_struct * handle)
{
	if (!handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_NULL_OPERATOR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
	}

	if (!task_tbl) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null operator string\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_NULL_TASK_TABLE);
		return OPH_ANALYTICS_OPERATOR_BAD_PARAMETER;
	}

	if (handle->operator_handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator handle already initialized\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_HANDLE_ALREADY_INITIALIZED);
		return OPH_ANALYTICS_OPERATOR_NOT_NULL_OPERATOR_HANDLE;
	}

	if (!(handle->operator_handle = (OPH_PRIMITIVES_LIST_operator_handle *) calloc(1, sizeof(OPH_PRIMITIVES_LIST_operator_handle)))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MEMORY_ERROR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}
	//1 - Set up struct to empty values
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level = 0;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_ret = NULL;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_type = NULL;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->name_filter = NULL;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->limit = 0;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms = 0;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server = NULL;
	ophidiadb *oDB = &((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys = NULL;
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys_num = -1;

	//Only master process has to continue
	if (handle->proc_rank != 0)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	oph_odb_init_ophidiadb(oDB);

	//3 - Fill struct with the correct data
	char *value;

	// retrieve objkeys
	value = hashtbl_get(task_tbl, OPH_IN_PARAM_OBJKEY_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_OBJKEY_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_OBJKEY_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (oph_tp_parse_multiple_value_param
	    (value, &((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys, &((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys_num)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Operator string not valid\n");
		oph_tp_free_multiple_value_param_list(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys,
						      ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys_num);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_PRIMITIVE_NAME_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_PRIMITIVE_NAME_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_PRIMITIVE_NAME_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (!(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->name_filter = (char *) strndup(value, OPH_TP_TASKLEN))) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MEMORY_ERROR_INPUT, "name_filter");
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_LIMIT_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_LIMIT_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_LIMIT_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->limit = (int) strtol(value, NULL, 10);
	if (((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->limit < 0) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Limit must be positive\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LIMIT, OPH_IN_PARAM_LIMIT_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_VISUALIZZATION_LEVEL);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_VISUALIZZATION_LEVEL);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_VISUALIZZATION_LEVEL);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level = (int) strtol(value, NULL, 10);
	if (((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level < 1 || ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level > 5) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Level unrecognized\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LEVEL);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_DBMS_ID_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_DBMS_ID_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_DBMS_ID_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (strcmp(value, OPH_COMMON_DEFAULT_EMPTY_VALUE) == 0) {
		((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms = 0;
	} else {
		((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms = (int) strtol(value, NULL, 10);
		if (((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms < 1) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "id of dbms must be positive\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LIMIT, OPH_IN_PARAM_DBMS_ID_FILTER);
			return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
		}
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_PRIMITIVE_RETURN_TYPE_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_PRIMITIVE_RETURN_TYPE_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_PRIMITIVE_RETURN_TYPE_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (strcmp(value, OPH_COMMON_ALL_FILTER) != 0) {
		if (!(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_ret = (char *) strndup(value, OPH_TP_TASKLEN))) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MEMORY_ERROR_INPUT, "func_ret");
			return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
		}
	}

	value = hashtbl_get(task_tbl, OPH_IN_PARAM_PRIMITIVE_TYPE_FILTER);
	if (!value) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_PRIMITIVE_TYPE_FILTER);
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MISSING_INPUT_PARAMETER, "NO-CONTAINER", OPH_IN_PARAM_PRIMITIVE_TYPE_FILTER);
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	if (strcmp(value, OPH_COMMON_ALL_FILTER) != 0) {
		if (!(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_type = (char *) strndup(value, OPH_TP_TASKLEN))) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_MEMORY_ERROR_INPUT, "func_type");
			return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
		}
	}

	return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
コード例 #7
0
ファイル: Condition.cpp プロジェクト: sleimanf/aibot
void Condition::addCharacters(const StringPimpl &characters) 
	throw(InternalProgrammerErrorException &)
{
	logging("<Input> characters:" + String(characters.c_str()));
	add(shared_ptr<PlainWord>(new PlainWord(characters)));
}
コード例 #8
0
void SystemMemoryResources::copy(const SystemMemoryResources &other)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
	this->m_capacities = other.m_capacities;
}
コード例 #9
0
SystemMemoryResources::~SystemMemoryResources()
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
}
コード例 #10
0
SystemMemoryResources::SystemMemoryResources(struct device_capacities device_capacities) :
		m_capacities(device_capacities)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
}
コード例 #11
0
SystemMemoryResources::SystemMemoryResources(const SystemMemoryResources &other) :
		m_capacities(other.m_capacities)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
	copy(other);
}
コード例 #12
0
NVM_UINT64 core::system::SystemMemoryResources::getTotalInaccessibleCapacity()
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
	return m_capacities.inaccessible_capacity;
}
コード例 #13
0
void
test_preventallow_warm_reset(void)
{
	int ret;

	CHECK_FOR_SBC;
	CHECK_FOR_REMOVABLE;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test that Target Warm Reset clears PREVENT MEDIUM REMOVAL");

	logging(LOG_VERBOSE, "Set the PREVENT flag");
	ret = preventallow(iscsic, tgt_lun, 1);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Try to eject the medium");
	ret = startstopunit_preventremoval(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Verify we can still access the media.");
	ret = testunitready(iscsic, tgt_lun);
	CU_ASSERT_EQUAL(ret, 0);

	
	logging(LOG_VERBOSE, "Perform warm reset on target");
	ret = iscsi_task_mgmt_target_warm_reset_sync(iscsic);
	CU_ASSERT_EQUAL(ret, 0);
	logging(LOG_VERBOSE, "Wait until all unit attentions clear");
	while (testunitready(iscsic, tgt_lun) != 0);


	logging(LOG_VERBOSE, "Try to eject the medium");
	ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Verify we can not access the media.");
	ret = testunitready_nomedium(iscsic, tgt_lun);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Load the medium");
	ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 0);
	CU_ASSERT_EQUAL(ret, 0);


	logging(LOG_VERBOSE, "Clear PREVENT and load medium in case target failed");
	logging(LOG_VERBOSE, "Test we can clear PREVENT flag");
	ret = preventallow(iscsic, tgt_lun, 0);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Load the medium");
	ret = startstopunit(iscsic, tgt_lun, 0, 0, 0, 0, 1, 1);
	CU_ASSERT_EQUAL(ret, 0);

}
コード例 #14
0
void
test_inquiry_standard(void)
{
        int ret, i;
        struct scsi_inquiry_standard *std_inq;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test of the standard INQUIRY page");

        logging(LOG_VERBOSE, "Verify we can read standard INQUIRY page");
        /* 260 bytes is the maximum possible size of the standard vpd */
        ret = inquiry(sd, &task, 0, 0, 260,
                      EXPECT_STATUS_GOOD);
        CU_ASSERT_EQUAL(ret, 0);

        logging(LOG_VERBOSE, "Verify we got at least 36 bytes of data");
        CU_ASSERT(task->datain.size >= 36);

        logging(LOG_VERBOSE, "Verify we can unmarshall the DATA-IN buffer");
        std_inq = scsi_datain_unmarshall(task);
        CU_ASSERT_NOT_EQUAL(std_inq, NULL);
        if (std_inq == NULL) {
                logging(LOG_NORMAL, "[FAILED] Failed to unmarshall DATA-IN "
                        "buffer");
                return;
        }

        logging(LOG_VERBOSE, "Verify peripheral-qualifier is 0");
        CU_ASSERT_EQUAL(std_inq->qualifier, 0);

        logging(LOG_VERBOSE, "Verify version field is either 0x4, 0x5 or 0x6");
        switch (std_inq->version) {
        case 0x0:
                logging(LOG_NORMAL, "[WARNING] Standard INQUIRY data claims "
                        "conformance to no standard. Version==0. "
                        "Bad sport.");

                break;
        case 0x4:
        case 0x5:
        case 0x6:
                break;
        default:
                logging(LOG_NORMAL, "[FAILED] Invalid version in standard "
                        "INQUIRY data. Version %d found but only versions "
                        "0x4,0x4,0x6 are valid.", std_inq->version);
                CU_FAIL("Invalid version in INQUIRY data");
        }

        logging(LOG_VERBOSE, "Verify response-data-format is 2 "
                "(SPC-2 or later)");
        if (std_inq->response_data_format != 2) {
                logging(LOG_NORMAL, "[FAILED] Response data format is "
                        "invalid. Must be 2 but device returned %d",
                        std_inq->response_data_format);
        }
        CU_ASSERT_EQUAL(std_inq->response_data_format, 2);

        logging(LOG_VERBOSE, "Verify additional-length is correct");
        if (std_inq->additional_length > task->datain.size - 5) {
                logging(LOG_NORMAL, "[FAILED] Bad additional length "
                        "returned. Should be %d but device returned %d.",
                        task->datain.size - 5,
                        std_inq->additional_length);
                logging(LOG_NORMAL, "[FAILED] Additional length points "
                        "beyond end of data");
                CU_FAIL("Additional length points beyond end of data");
        }
        if (std_inq->additional_length < task->datain.size - 5) {
                logging(LOG_NORMAL, "[WARNING] Bad additional length "
                        "returned. Should be %d but device returned %d. ",
                        task->datain.size - 5,
                        std_inq->additional_length);
                logging(LOG_VERBOSE, "Verify that all padding data is 0");
                for (i = std_inq->additional_length + 6; i < task->datain.size; i++) {
                        if (!task->datain.data[i])
                                continue;
                        logging(LOG_NORMAL, "[FAILED] Padding data is not zero."
                                           " Are we leaking data?");
                        CU_FAIL("Padding data is not zero. Leaking data?");
                }
        }

        logging(LOG_VERBOSE, "Verify VENDOR_IDENTIFICATION is in ASCII");
        for (i = 8; i < 16; i++) {
                /* SPC-4 4.4.1 only characters 0x00 and 0x20-0x7E allowed */
                if (task->datain.data[i] == 0) {
                        continue;
                }
                if (task->datain.data[i] >= 0x20 && task->datain.data[i] <= 0x7e) {
                        continue;
                }

                logging(LOG_NORMAL, "[FAILED] VENDOR_IDENTIFICATION contains "
                        "non-ASCII characters");
                CU_FAIL("Invalid characters in VENDOR_IDENTIFICATION");
                break;
        }

        logging(LOG_VERBOSE, "Verify PRODUCT_IDENTIFICATION is in ASCII");
        for (i = 16; i < 32; i++) {
                /* SPC-4 4.4.1 only characters 0x00 and 0x20-0x7E allowed */
                if (task->datain.data[i] == 0) {
                        continue;
                }
                if (task->datain.data[i] >= 0x20 && task->datain.data[i] <= 0x7e) {
                        continue;
                }

                logging(LOG_NORMAL, "[FAILED] PRODUCT_IDENTIFICATION contains "
                        "non-ASCII characters");
                CU_FAIL("Invalid characters in PRODUCT_IDENTIFICATION");
                break;
        }

        logging(LOG_VERBOSE, "Verify PRODUCT_REVISION_LEVEL is in ASCII");
        for (i = 32; i < 36; i++) {
                /* SPC-4 4.4.1 only characters 0x00 and 0x20-0x7E allowed */
                if (task->datain.data[i] == 0) {
                        continue;
                }
                if (task->datain.data[i] >= 0x20 && task->datain.data[i] <= 0x7e) {
                        continue;
                }

                logging(LOG_NORMAL, "[FAILED] PRODUCT_REVISON_LEVEL contains "
                        "non-ASCII characters");
                CU_FAIL("Invalid characters in PRODUCT_REVISON_LEVEL");
                break;
        }

        logging(LOG_VERBOSE, "Verify AERC is clear in SPC-3 and later");
        if (task->datain.data[3] & 0x80 && std_inq->version >= 5) {
                logging(LOG_NORMAL, "[FAILED] AERC is set but this device "
                        "reports SPC-3 or later.");
                CU_FAIL("AERC is set but SPC-3+ is claimed");
        }

        logging(LOG_VERBOSE, "Verify TRMTSK is clear in SPC-2 and later");
        if (task->datain.data[3] & 0x40 && std_inq->version >= 4) {
                logging(LOG_NORMAL, "[FAILED] TRMTSK is set but this device "
                        "reports SPC-2 or later.");
                CU_FAIL("TRMTSK is set but SPC-2+ is claimed");
        }

        if (task != NULL) {
                scsi_free_scsi_task(task);
                task = NULL;
        }
}
コード例 #15
0
void
test_reserve6_logout(void)
{
	int ret;


	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test that RESERVE6 is released on logout");


	logging(LOG_NORMAL, "Take out a RESERVE6 from the first initiator");
	ret = reserve6(iscsic, tgt_lun);
	if (ret == -2) {
		logging(LOG_VERBOSE, "[SKIPPED] Target does not support RESERVE6. Skipping test");
		CU_PASS("[SKIPPED] Target does not support RESERVE6. Skipping test");
		return;
	}
	CU_ASSERT_EQUAL(ret, 0);


	logging(LOG_VERBOSE, "Create a second connection to the target");
	iscsic2 = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
	if (iscsic2 == NULL) {
		logging(LOG_VERBOSE, "Failed to login to target");
		return;
	}

	logging(LOG_NORMAL, "Try to take out a RESERVE6 from the second initiator");
	ret = reserve6_conflict(iscsic2, tgt_lun);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Logout from target");
	iscsi_logout_sync(iscsic);

	logging(LOG_VERBOSE, "Relogin to target");
	iscsic = iscsi_context_login(initiatorname1, tgt_url, &tgt_lun);
	if (iscsic == NULL) {
		logging(LOG_VERBOSE, "Failed to login to target");
		return;
	}

	logging(LOG_NORMAL, "RESERVE6 from the second initiator should work now");
	ret = reserve6(iscsic2, tgt_lun);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_NORMAL, "RELEASE6 from the second initiator");
	ret = release6(iscsic2, tgt_lun);
	CU_ASSERT_EQUAL(ret, 0);
}
コード例 #16
0
SystemMemoryResources *SystemMemoryResources::clone()
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
	return new SystemMemoryResources(*this);
}
int task_execute(oph_operator_struct * handle)
{
	if (!handle || !handle->operator_handle) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_NULL_OPERATOR_HANDLE);
		return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
	}
	//Only master process has to continue
	if (handle->proc_rank != 0)
		return OPH_ANALYTICS_OPERATOR_SUCCESS;

	logging(LOG_INFO, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_INFO_START);

	int level = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->level;
	char *func_ret = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_ret;
	char *func_type = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->func_type;
	char *name_filter = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->name_filter;
	int limit = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->limit;
	int id_dbms = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->id_dbms;
	ophidiadb *oDB = &((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB;
	char **objkeys = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys;
	int objkeys_num = ((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->objkeys_num;

	if (oph_odb_read_ophidiadb_config_file(oDB)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to read OphidiaDB configuration\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_OPHIDIADB_CONFIGURATION_FILE_NO_CONTAINER);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}

	if (oph_odb_connect_to_ophidiadb(oDB)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to OphidiaDB. Check access parameters.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_OPHIDIADB_CONNECTION_ERROR_NO_CONTAINER);
		oph_odb_disconnect_from_ophidiadb(&((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

	oph_odb_dbms_instance dbms;
	if (id_dbms == 0) {
		if (oph_odb_stge_retrieve_first_dbmsinstance(oDB, &dbms)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve DBMS info\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_RETRIEVE_DBMS_ERROR, id_dbms);
			oph_odb_disconnect_from_ophidiadb(&((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB);
			return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
		}
	} else {
		if (oph_odb_stge_retrieve_dbmsinstance(oDB, id_dbms, &dbms)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve DBMS info\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_RETRIEVE_DBMS_ERROR, id_dbms);
			oph_odb_disconnect_from_ophidiadb(&((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB);
			return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
		}
	}
	oph_odb_disconnect_from_ophidiadb(&((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->oDB);

	int num_fields;
	switch (level) {
		case 5:
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+---------+\n");
			printf("| %-35s | %-12s | %-45s | %-15s | %-7s |\n", "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY", "PRIMITIVE TYPE", "DBMS ID");
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+---------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 5;
				char *keys[5] = { "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY", "PRIMITIVE TYPE", "DBMS ID" };
				char *fieldtypes[5] = { "string", "string", "string", "string", "int" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		case 4:
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+\n");
			printf("| %-35s | %-12s | %-45s | %-15s |\n", "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY", "PRIMITIVE TYPE");
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 4;
				char *keys[4] = { "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY", "PRIMITIVE TYPE" };
				char *fieldtypes[4] = { "string", "string", "string", "string" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		case 3:
			printf("+-------------------------------------+--------------+-----------------------------------------------+\n");
			printf("| %-35s | %-12s | %-45s |\n", "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY");
			printf("+-------------------------------------+--------------+-----------------------------------------------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 3;
				char *keys[3] = { "PRIMITIVE NAME", "RETURN TYPE", "DYNAMIC LIBRARY" };
				char *fieldtypes[3] = { "string", "string", "string" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		case 2:
			printf("+-------------------------------------+--------------+\n");
			printf("| %-35s | %-12s |\n", "PRIMITIVE NAME", "RETURN TYPE");
			printf("+-------------------------------------+--------------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 2;
				char *keys[2] = { "PRIMITIVE NAME", "RETURN TYPE" };
				char *fieldtypes[2] = { "string", "string" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		case 1:
			printf("+-------------------------------------+\n");
			printf("| %-35s |\n", "PRIMITIVE NAME");
			printf("+-------------------------------------+\n");
			if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
				num_fields = 1;
				char *keys[1] = { "PRIMITIVE NAME" };
				char *fieldtypes[1] = { "string" };
				if (oph_json_add_grid(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, "Primitives List", NULL, keys, num_fields, fieldtypes, num_fields)) {
					pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID error\n");
					logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID error\n");
					return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
				}
			}
			break;
		default:
			pmesg(LOG_ERROR, __FILE__, __LINE__, "List level unrecognized\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LEVEL);
			return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	if (oph_dc_setup_dbms(&(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server), dbms.io_server_type)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to initialize IO server.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_IOPLUGIN_SETUP_ERROR, dbms.io_server_type);
		return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
	}

	if (oph_dc_connect_to_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms, 0)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to DBMS. Check access parameters.\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_CONNECT_DBMS_ERROR, dbms.id_dbms);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	}

	oph_ioserver_result *primitives_list = NULL;

	//retrieve primitives list
	if (oph_dc_get_primitives(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms, name_filter, &primitives_list)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to retrieve primitives list\n");
		logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_RETRIEVE_LIST_ERROR, dbms.id_dbms);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}

	int num_rows = 0;

	//Empty set
	if (!(num_rows = primitives_list->num_rows)) {
		pmesg(LOG_WARNING, __FILE__, __LINE__, "No rows found by query\n");
		logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_NO_ROWS_FOUND);
		oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_ANALYTICS_OPERATOR_SUCCESS;
	}

	if (primitives_list->num_fields != 4) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Not enough fields found by query\n");
		logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_NO_ROWS_FOUND);
		oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_ANALYTICS_OPERATOR_SUCCESS;
	}

	oph_ioserver_row *curr_row = NULL;

	if (oph_ioserver_fetch_row(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list, &curr_row)) {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to fetch row\n");
		logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_ROW_ERROR);
		oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
		oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
		oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
		return OPH_DC_SERVER_ERROR;
	}
	//For each ROW
	char tmp_ret[OPH_COMMON_BUFFER_LEN] = { '\0' }, tmp_type[OPH_COMMON_BUFFER_LEN] = {
	'\0'};
	int n;
	int count_limit = 0;
	while (curr_row->row) {
		if (limit > 0 && count_limit >= limit)
			break;
		switch (level) {
			case 5:
				if (func_ret || func_type) {
					if (func_ret) {
						n = snprintf(tmp_ret, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[1][0] == '0') ? "array" : "number");
						if (n <= 0)
							break;
						if (strncmp(tmp_ret, func_ret, OPH_COMMON_BUFFER_LEN) != 0)
							break;
					}
					if (func_type) {
						n = snprintf(tmp_type, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[3][0] == 'f') ? "simple" : "aggregate");
						if (n <= 0)
							break;
						if (strncmp(tmp_type, func_type, OPH_COMMON_BUFFER_LEN) != 0)
							break;
					}
					printf("| %-35s | %-12s | %-45s | %-15s | %7d |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2],
					       (curr_row->row[3][0] == 'f') ? "simple" : "aggregate", dbms.id_dbms);
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char tmpbuf[20];
						snprintf(tmpbuf, 20, "%d", dbms.id_dbms);
						char *my_row[5] =
						    { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2], (curr_row->row[3][0] == 'f') ? "simple" : "aggregate",
							tmpbuf
						};
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				} else {
					printf("| %-35s | %-12s | %-45s | %-15s | %7d |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2],
					       (curr_row->row[3][0] == 'f') ? "simple" : "aggregate", dbms.id_dbms);
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char tmpbuf[20];
						snprintf(tmpbuf, 20, "%d", dbms.id_dbms);
						char *my_row[5] =
						    { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2], (curr_row->row[3][0] == 'f') ? "simple" : "aggregate",
							tmpbuf
						};
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				}
				count_limit++;
				break;
			case 4:
				if (func_ret || func_type) {
					if (func_ret) {
						n = snprintf(tmp_ret, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[1][0] == '0') ? "array" : "number");
						if (n <= 0)
							break;
						if (strncmp(tmp_ret, func_ret, OPH_COMMON_BUFFER_LEN) != 0)
							break;
					}
					if (func_type) {
						n = snprintf(tmp_type, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[3][0] == 'f') ? "simple" : "aggregate");
						if (n <= 0)
							break;
						if (strncmp(tmp_type, func_type, OPH_COMMON_BUFFER_LEN) != 0)
							break;
					}
					printf("| %-35s | %-12s | %-45s | %-15s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2],
					       (curr_row->row[3][0] == 'f') ? "simple" : "aggregate");
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[4] =
						    { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2], (curr_row->row[3][0] == 'f') ? "simple" : "aggregate" };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				} else {
					printf("| %-35s | %-12s | %-45s | %-15s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2],
					       (curr_row->row[3][0] == 'f') ? "simple" : "aggregate");
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[4] =
						    { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2], (curr_row->row[3][0] == 'f') ? "simple" : "aggregate" };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				}
				count_limit++;
				break;
			case 3:
				if (func_ret) {
					n = snprintf(tmp_ret, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[1][0] == '0') ? "array" : "number");
					if (n <= 0)
						break;
					if (strncmp(tmp_ret, func_ret, OPH_COMMON_BUFFER_LEN) != 0)
						break;
					printf("| %-35s | %-12s | %-45s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2]);
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[3] = { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2] };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				} else {
					printf("| %-35s | %-12s | %-45s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2]);
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[3] = { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number", curr_row->row[2] };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				}
				count_limit++;
				break;
			case 2:
				if (func_ret) {
					n = snprintf(tmp_ret, OPH_COMMON_BUFFER_LEN, "%s", (curr_row->row[1][0] == '0') ? "array" : "number");
					if (n <= 0)
						break;
					if (strncmp(tmp_ret, func_ret, OPH_COMMON_BUFFER_LEN) != 0)
						break;
					printf("| %-35s | %-12s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number");
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[2] = { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number" };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				} else {
					printf("| %-35s | %-12s |\n", curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number");
					if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
						char *my_row[2] = { curr_row->row[0], (curr_row->row[1][0] == '0') ? "array" : "number" };
						if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
							pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
							logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
							oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
							oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
							oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
							return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
						}
					}
				}
				count_limit++;
				break;
			case 1:
				printf("| %-35s |\n", curr_row->row[0]);
				if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST)) {
					char *my_row[1] = { curr_row->row[0] };
					if (oph_json_add_grid_row(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_LIST, my_row)) {
						pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD GRID ROW error\n");
						logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD GRID ROW error\n");
						oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
						oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
						oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
						return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
					}
				}
				count_limit++;
				break;
			default:
				pmesg(LOG_ERROR, __FILE__, __LINE__, "List level unrecognized\n");
				logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LEVEL);
				oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
				oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
				oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
				return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
		}

		if (oph_ioserver_fetch_row(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list, &curr_row)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to fetch row\n");
			logging(LOG_WARNING, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_ROW_ERROR);
			oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
			oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
			oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);
			return OPH_DC_SERVER_ERROR;
		}

	}

	oph_ioserver_free_result(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, primitives_list);
	oph_dc_disconnect_from_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server, &dbms);
	oph_dc_cleanup_dbms(((OPH_PRIMITIVES_LIST_operator_handle *) handle->operator_handle)->server);

	switch (level) {
		case 5:
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+---------+\n");
			break;
		case 4:
			printf("+-------------------------------------+--------------+-----------------------------------------------+-----------------+\n");
			break;
		case 3:
			printf("+-------------------------------------+--------------+-----------------------------------------------+\n");
			break;
		case 2:
			printf("+-------------------------------------+--------------+\n");
			break;
		case 1:
			printf("+-------------------------------------+\n");
			break;
		default:
			pmesg(LOG_ERROR, __FILE__, __LINE__, "List level unrecognized\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_BAD_LEVEL);
			return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}

	printf(OPH_PRIMITIVES_LIST_HELP_MESSAGE);
	if (oph_json_is_objkey_printable(objkeys, objkeys_num, OPH_JSON_OBJKEY_PRIMITIVES_LIST_TIP)) {
		if (oph_json_add_text(handle->operator_json, OPH_JSON_OBJKEY_PRIMITIVES_LIST_TIP, "Useful Tip", OPH_PRIMITIVES_LIST_HELP_MESSAGE)) {
			pmesg(LOG_ERROR, __FILE__, __LINE__, "ADD TEXT error\n");
			logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "ADD TEXT error\n");
			return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
		}
	}

	logging(LOG_INFO, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_PRIMITIVES_LIST_INFO_END);
	return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
コード例 #18
0
NVM_UINT64 SystemMemoryResources::getTotalMemoryCapacity()
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
	return m_capacities.memory_capacity;
}
コード例 #19
0
void
test_writesame16_unmap(void)
{
	int ret;
	unsigned int i;
	unsigned char *buf;

	CHECK_FOR_DATALOSS;
	CHECK_FOR_THIN_PROVISIONING;
	CHECK_FOR_LBPWS;
	CHECK_FOR_SBC;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the start of the LUN");
	buf = calloc(65536, block_size);
	for (i = 1; i <= 256; i++) {
		logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
		memset(buf, 0xff, i * block_size);
		ret = write16(sd, 0,
			      i * block_size, block_size, 0, 0, 0, 0, 0, buf,
			      EXPECT_STATUS_GOOD);
		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		memset(buf, 0, block_size);
		ret = writesame16(sd, 0,
				  block_size, i, 0, 1, 0, 0, buf,
				  EXPECT_STATUS_GOOD);
		if (ret == -2) {
			logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented.");
			CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test");
			goto finished;
		}
		CU_ASSERT_EQUAL(ret, 0);

		if (rc16->lbprz) {
			logging(LOG_VERBOSE, "LBPRZ is set. Read the unmapped "
				"blocks back and verify they are all zero");
			logging(LOG_VERBOSE, "Read %d blocks and verify they "
				"are now zero", i);
			ret = read16(sd, NULL, 0,
				     i * block_size, block_size,
				     0, 0, 0, 0, 0, buf,
				     EXPECT_STATUS_GOOD);
			CU_ASSERT(all_zeroes(buf, i * block_size));
		} else {
			logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
				"and verify zero test");
		}
	}


	logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the end of the LUN");
	for (i = 1; i <= 256; i++) {
		logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
		memset(buf, 0xff, i * block_size);
		ret = write16(sd, num_blocks - i,
			      i * block_size, block_size, 0, 0, 0, 0, 0, buf,
			      EXPECT_STATUS_GOOD);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		memset(buf, 0, block_size);
		ret = writesame16(sd, num_blocks - i,
				  block_size, i, 0, 1, 0, 0, buf,
				  EXPECT_STATUS_GOOD);
		CU_ASSERT_EQUAL(ret, 0);

		if (rc16->lbprz) {
			logging(LOG_VERBOSE, "LBPRZ is set. Read the unmapped "
				"blocks back and verify they are all zero");
			logging(LOG_VERBOSE, "Read %d blocks and verify they "
				"are now zero", i);
			ret = read16(sd, NULL, num_blocks - i,
				     i * block_size, block_size,
				     0, 0, 0, 0, 0, buf,
				     EXPECT_STATUS_GOOD);
			CU_ASSERT(all_zeroes(buf, i * block_size));
		} else {
			logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
				"and verify zero test");
		}
	}

	logging(LOG_VERBOSE, "Verify that WRITESAME16 ANCHOR==1 + UNMAP==0 is invalid");
	ret = writesame16(sd, 0,
			  block_size, 1, 1, 0, 0, 0, buf,
			  EXPECT_INVALID_FIELD_IN_CDB);
	CU_ASSERT_EQUAL(ret, 0);



	if (inq_lbp->anc_sup) {
		logging(LOG_VERBOSE, "Test WRITESAME16 ANCHOR==1 + UNMAP==0");
		memset(buf, 0, block_size);
		ret = writesame16(sd, 0,
				  block_size, 1, 1, 1, 0, 0, buf,
				  EXPECT_STATUS_GOOD);
	} else {
		logging(LOG_VERBOSE, "Test WRITESAME16 ANCHOR==1 + UNMAP==0 no ANC_SUP so expecting to fail");
		ret = writesame16(sd, 0,
				  block_size, 1, 1, 1, 0, 0, buf,
				  EXPECT_INVALID_FIELD_IN_CDB);
	}

	CU_ASSERT_EQUAL(ret, 0);


	if (inq_bl == NULL) {
		logging(LOG_VERBOSE, "[FAILED] WRITESAME16 works but "
			"BlockLimits VPD is missing.");
		CU_FAIL("[FAILED] WRITESAME16 works but "
			"BlockLimits VPD is missing.");
		goto finished;
	}

	i = 256;
	if (i <= num_blocks
	    && (inq_bl->max_ws_len == 0 || inq_bl->max_ws_len >= i)) {
		logging(LOG_VERBOSE, "Block Limits VPD page reports MAX_WS_LEN "
			"as either 0 (==no limit) or >= %d. Test Unmapping "
			"%d blocks to verify that it can handle 2-byte "
			"lengths", i, i);

		logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
		memset(buf, 0xff, i * block_size);
		ret = write16(sd, 0,
			      i * block_size, block_size, 0, 0, 0, 0, 0, buf,
			      EXPECT_STATUS_GOOD);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		memset(buf, 0, block_size);
		ret = writesame16(sd, 0,
				  block_size, i, 0, 1, 0, 0, buf,
				  EXPECT_STATUS_GOOD);
		CU_ASSERT_EQUAL(ret, 0);

		if (rc16->lbprz) {
			logging(LOG_VERBOSE, "LBPRZ is set. Read the unmapped "
				"blocks back and verify they are all zero");

			logging(LOG_VERBOSE, "Read %d blocks and verify they "
				"are now zero", i);
			ret = read16(sd, NULL, 0,
				     i * block_size, block_size,
				     0, 0, 0, 0, 0, buf,
				     EXPECT_STATUS_GOOD);
			CU_ASSERT(all_zeroes(buf, i * block_size));
		} else {
			logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
				"and verify zero test");
		}
	} else if (i <= num_blocks) {
		logging(LOG_VERBOSE, "Block Limits VPD page reports MAX_WS_LEN "
			"as <256. Verify that a 256 block unmap fails with "
			"INVALID_FIELD_IN_CDB.");

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		ret = writesame16(sd, 0,
				  block_size, i, 0, 1, 0, 0, buf,
				  EXPECT_INVALID_FIELD_IN_CDB);
		CU_ASSERT_EQUAL(ret, 0);
	}


	i = 65536;
	if (i <= num_blocks
	    && (inq_bl->max_ws_len == 0 || inq_bl->max_ws_len >= i)) {
		logging(LOG_VERBOSE, "Block Limits VPD page reports MAX_WS_LEN "
			"as either 0 (==no limit) or >= %d. Test Unmapping "
			"%d blocks to verify that it can handle 4-byte "
			"lengths", i, i);

		logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i);
		memset(buf, 0xff, i * block_size);
		ret = write16(sd, 0,
			      i * block_size, block_size, 0, 0, 0, 0, 0, buf,
			      EXPECT_STATUS_GOOD);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		memset(buf, 0, block_size);
		ret = writesame16(sd, 0,
				  block_size, i, 0, 1, 0, 0, buf,
				  EXPECT_STATUS_GOOD);
		CU_ASSERT_EQUAL(ret, 0);

		if (rc16->lbprz) {
			logging(LOG_VERBOSE, "LBPRZ is set. Read the unmapped "
				"blocks back and verify they are all zero");

			logging(LOG_VERBOSE, "Read %d blocks and verify they "
				"are now zero", i);
			ret = read16(sd, NULL, 0,
				     i * block_size, block_size,
				     0, 0, 0, 0, 0, buf,
				     EXPECT_STATUS_GOOD);
			CU_ASSERT(all_zeroes(buf, i * block_size));
		} else {
			logging(LOG_VERBOSE, "LBPRZ is clear. Skip the read "
				"and verify zero test");
		}
	} else if (i <= num_blocks) {
		logging(LOG_VERBOSE, "Block Limits VPD page reports MAX_WS_LEN "
			"as <256. Verify that a 256 block unmap fails with "
			"INVALID_FIELD_IN_CDB.");

		logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i);
		ret = writesame16(sd, 0,
				  block_size, i, 0, 1, 0, 0, buf,
				  EXPECT_INVALID_FIELD_IN_CDB);
		CU_ASSERT_EQUAL(ret, 0);
	}

finished:
	free(buf);
}
コード例 #20
0
NVM_UINT64 SystemMemoryResources::getTotalAppDirectCapacity()
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);
	return m_capacities.app_direct_capacity;
}
コード例 #21
0
ファイル: Condition.cpp プロジェクト: sleimanf/aibot
StringPimpl Condition::getString() const
	throw(InternalProgrammerErrorException &)
{
	LOG_BOT_METHOD("StringPimpl Condition::getString() const");
	if(this->isBlockCondition())
	{
		logging("This is a block condition");
		if(m_pimpl->m_builder.predicateMatch(m_pimpl->m_predicateName.c_str(), m_pimpl->m_aimlPattern.c_str()))
		{
			logging("Matched the aimlpattern to the predicate's pattern");
			logging("Returning the string");
			return getStringFromSentence(m_pimpl->m_sentence);
		}
		else
		{
			logging("Did not match the aimlpattern, returning empty string");
			return StringPimpl();
		}
	}
	else 
	{
		logging("This is either a single or multi-predicate condition");		
		
		typedef ListSharedPtrInnerTemplate::const_iterator CI;

		for(CI it = m_pimpl->m_sentence.begin(); it != m_pimpl->m_sentence.end(); ++it) 
		{
			if((*it)->instanceOf("Li"))
			{
				shared_ptr<Li> li = std::static_pointer_cast<Li>(*it);
				StringPimpl liPredicateName = li->getPredicateName();
				StringPimpl liAimlPattern = li->getAimlPattern();

				if(li->isDefaultListItem())
				{
					logging("Encountered default list item.  Returning its string");
					String s = li->getString().c_str();
					trim(s);
					return s.c_str();
				}
				else if(this->isSinglePredicateCondition())
				{
					logging("This is a single Predicate condition");
					if(m_pimpl->m_builder.predicateMatch(m_pimpl->m_predicateName.c_str(), liAimlPattern.c_str()))
					{
						String s = (*it)->getString().c_str();
						trim(s);
						return s.c_str();
					}
				}
				else if(isMutliPredicateCondition())
				{
					logging("This is a multi-predicate condition");
					if(m_pimpl->m_builder.predicateMatch(liPredicateName.c_str(), liAimlPattern.c_str()))
					{
						String s = (*it)->getString().c_str();
						trim(s);
						return s.c_str();
					}
				}
				else
				{
					logging("Inernal programmer Error, the condition block code is corrupted.");
					throw InternalProgrammerErrorExceptionImpl("[StringPimpl Condition::getString()] Condition block code is corrupted.");
					return StringPimpl();
				}
			}
			else if((*it)->instanceOf("PlainWord"))
			{
				//Check for plain word.  If it is a plain word skip to the next
				continue;	
			}
			else
			{
				//Not a plain word, something else.  Throw a bad cast.
				logging("Internal programmer error.  Bad cast, was expecting a Li");
				throw InternalProgrammerErrorExceptionImpl("[StringPimpl Condition::getString() const].  Bad cast, was expecting a Li");
				return StringPimpl();
			}
		}
			
		logging("Nothing matched. Returning empty string");
		return StringPimpl();

	}
}
コード例 #22
0
ファイル: requests.c プロジェクト: 19fever/sws
int serve_dir(int fd, Req_info * req) {
    
    DIR *dp;
    char index[256];
    char buf[MAXBUF];
    char content[MAXBUF];
    char date[256];
    struct stat sbuf;
    struct stat sb;
    
    struct dirent *dirp;
    char last_modified[256];
    char path[256];
    if (req->uri[strlen(req->uri)-1]!='/')
        strcat(req->uri,"/");
    sprintf(index, "%sindex.html",req->uri);
    if( !lstat(index, &sbuf)){
        strncpy(req->uri,index,strlen(index)+1);
        return serve_static(fd, req,sbuf.st_size);
    }
    
    if ((dp = opendir(req->uri)) == NULL ) {
        req->status = 403;
        sws_response(fd, req);
        return 1;
    }
    sprintf(content,"<!DOCTYPE><html><head><title>Four0Four sws</title></head><body><h1>Index of %s:</h1><br/><table><tr><th align='left'>Name:</th><th align='right'>Last_Modified:</th></tr><tr><th colspan='5'><hr></th></tr>",basename(req->uri));    
    
    while ((dirp = readdir(dp)) != NULL ) {
        if (dirp->d_name[0] != '.') {
            sprintf(path,"%s%s",req->uri,dirp->d_name);
            if (stat(path, &sb) == -1) {
                if (lstat(path, &sb) == -1) {
                    strcpy(last_modified,"Cannot stat\0");
                }
            } 
            else {
                struct tm * tmp;
                tmp = gmtime(&sb.st_mtime);
                char *Wday[]={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
                char *Mth[]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
                sprintf(last_modified,"%s, %d %s %d %d:%d:%d GMT",Wday[tmp->tm_wday],(tmp->tm_mday),Mth[tmp->tm_mon],(1900+tmp->tm_year),(tmp->tm_hour),(tmp->tm_min),(tmp->tm_sec));    
            }            
            sprintf(content, "%s<tr><td align='left'>%s</td><td align='right'>%s</td></tr>",content,dirp->d_name,last_modified);    
        }
    }        
    sprintf(content, "%s<tr><th colspan='5'><hr></th></tr></table><br/><span>Four0Four Server page</span></body></html>",content);    
    closedir(dp);
    
    if (_simple_response !=1 ) {
        sprintf(buf, "HTTP/1.0 200 OK\r\n");
        get_timestamp(date);
        sprintf(buf, "%sDate: %s\r\n",buf,date);
        sprintf(buf, "%sServer: Four0Four\r\n", buf);
        sprintf(buf, "%sContent-type: text/html\r\n", buf);
        sprintf(buf, "%sContent-length: %d\r\n\r\n", buf, (int)strlen(content));
        Send(fd, buf, strlen(buf), 0);
    }
    
    if (_head_response != 1)
        Send(fd, content, strlen(content), 0);
        
    req->contLen = (int)strlen(content);
    logging(req);
    return 0;
}
コード例 #23
0
ファイル: test_read10_invalid.c プロジェクト: Swind/libiscsi
void
test_read10_invalid(void)
{
	struct iscsi_data data;
	char *buf = alloca(block_size);
	struct scsi_task *task_ret;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test invalid READ10 commands");
	logging(LOG_VERBOSE, "Block size is %zu", block_size);

	/* Try a read10 of 1 block but xferlength == 0 */
	task = malloc(sizeof(struct scsi_task));
	CU_ASSERT_PTR_NOT_NULL(task);

	memset(task, 0, sizeof(struct scsi_task));
	task->cdb[0] = SCSI_OPCODE_READ10;
	task->cdb[8] = 1;
	task->cdb_size = 10;
	task->xfer_dir = SCSI_XFER_READ;
	task->expxferlen = 0;

	/*
	 * we don't want autoreconnect since some targets will drop the session
	 * on this condition.
	 */
	iscsi_set_noautoreconnect(iscsic, 1);


	logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==0");

	task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL);
	CU_ASSERT_PTR_NOT_NULL(task_ret);
	CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */

	logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
	if (task->status != SCSI_STATUS_GOOD) {
		logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
			iscsi_get_error(iscsic));
	}
	CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

	logging(LOG_VERBOSE, "Verify residual overflow flag is set");
	if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
		logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
			"overflow flag");
	}
	CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

	logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow",
		block_size);
	if (task->residual != block_size) {
		logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
			"amount of residual. Expected %zu but got %zu.",
			block_size, task->residual);
	}
	CU_ASSERT_EQUAL(task->residual, block_size);
	scsi_free_scsi_task(task);
	task = NULL;

	/* in case the previous test failed the session */
	iscsi_set_noautoreconnect(iscsic, 0);


	logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==10000");
	task = malloc(sizeof(struct scsi_task));
	CU_ASSERT_PTR_NOT_NULL(task);

	memset(task, 0, sizeof(struct scsi_task));
	task->cdb[0] = SCSI_OPCODE_READ10;
	task->cdb[8] = 1;
	task->cdb_size = 10;
	task->xfer_dir = SCSI_XFER_READ;
	task->expxferlen = 10000;

	task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL);
	CU_ASSERT_PTR_NOT_NULL(task_ret);

	logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
	if (task->status != SCSI_STATUS_GOOD) {
		logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
			iscsi_get_error(iscsic));
	}
	CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

	logging(LOG_VERBOSE, "Verify we got a whole block back from the target");
	CU_ASSERT_EQUAL(task->datain.size, (int)block_size);

	logging(LOG_VERBOSE, "Verify residual underflow flag is set");
	if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) {
		logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
			"underflow flag");
	}
	CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_UNDERFLOW);

	logging(LOG_VERBOSE, "Verify we got %zu bytes of residual underflow",
		10000 - block_size);
	if (task->residual != 10000 - block_size) {
		logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
			"amount of residual. Expected %zu but got %zu.",
			10000 - block_size, task->residual);
	}
	CU_ASSERT_EQUAL(task->residual, 10000 - block_size);
	scsi_free_scsi_task(task);
	task = NULL;



	logging(LOG_VERBOSE, "Try reading one block but with iSCSI expected transfer length==200");
	task = malloc(sizeof(struct scsi_task));
	CU_ASSERT_PTR_NOT_NULL(task);

	memset(task, 0, sizeof(struct scsi_task));
	task->cdb[0] = SCSI_OPCODE_READ10;
	task->cdb[8] = 1;
	task->cdb_size = 10;
	task->xfer_dir = SCSI_XFER_READ;
	task->expxferlen = 200;

	task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL);
	CU_ASSERT_PTR_NOT_NULL(task_ret);

	logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
	if (task->status != SCSI_STATUS_GOOD) {
		logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
			iscsi_get_error(iscsic));
	}
	CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

	logging(LOG_VERBOSE, "Verify we got 200 bytes back from the target");
	CU_ASSERT_EQUAL(task->datain.size, 200);

	logging(LOG_VERBOSE, "Verify residual overflow flag is set");
	if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
		logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
			"overflow flag");
	}
	CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

	logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow",
		block_size - 200);
	if (task->residual != block_size - 200) {
		logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
			"amount of residual. Expected %zu but got %zu.",
			block_size - 200, task->residual);
	}
	CU_ASSERT_EQUAL(task->residual, block_size - 200);

	scsi_free_scsi_task(task);
	task = NULL;



	logging(LOG_VERBOSE, "Try reading two blocks but iSCSI expected "
		"transfer length==%zu (==one block)", block_size);
	task = malloc(sizeof(struct scsi_task));
	CU_ASSERT_PTR_NOT_NULL(task);

	memset(task, 0, sizeof(struct scsi_task));
	task->cdb[0] = SCSI_OPCODE_READ10;
	task->cdb[8] = 2;
	task->cdb_size = 10;
	task->xfer_dir = SCSI_XFER_READ;
	task->expxferlen = block_size;

	task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, NULL);
	CU_ASSERT_PTR_NOT_NULL(task_ret);

	logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
	if (task->status != SCSI_STATUS_GOOD) {
		logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
			iscsi_get_error(iscsic));
	}
	CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

	logging(LOG_VERBOSE, "Verify we got one whole block back from the target");
	CU_ASSERT_EQUAL(task->datain.size, (int)block_size);

	logging(LOG_VERBOSE, "Verify residual overflow flag is set");
	if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
		logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
			"overflow flag");
	}
	CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

	logging(LOG_VERBOSE, "Verify we got one block of residual overflow");
	if (task->residual != block_size) {
		logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
			"amount of residual. Expected %zu but got %zu.",
			block_size, task->residual);
	}
	CU_ASSERT_EQUAL(task->residual, block_size);

	scsi_free_scsi_task(task);
	task = NULL;



	logging(LOG_VERBOSE, "Try READ10 for one block but flag it as a write on the iSCSI layer.");
	task = malloc(sizeof(struct scsi_task));
	CU_ASSERT_PTR_NOT_NULL(task);

	memset(task, 0, sizeof(struct scsi_task));
	task->cdb[0] = SCSI_OPCODE_READ10;
	task->cdb[8] = 1;
	task->cdb_size = 10;
	task->xfer_dir = SCSI_XFER_WRITE;
	task->expxferlen = block_size;

	data.size = block_size;
	data.data = (unsigned char *)buf;

	iscsi_set_noautoreconnect(iscsic, 1);
	iscsi_set_timeout(iscsic, 3);
	task_ret = iscsi_scsi_command_sync(iscsic, tgt_lun, task, &data);
	iscsi_set_noautoreconnect(iscsic, 0);
	CU_ASSERT_PTR_NOT_NULL(task_ret);

	logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
	if (task->status != SCSI_STATUS_GOOD) {
		logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
			iscsi_get_error(iscsic));
	}
	CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);
	scsi_free_scsi_task(task);
	task = NULL;

}
int task_execute(oph_operator_struct *handle)
{
  if (!handle || !handle->operator_handle){
  	pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_NULL_OPERATOR_HANDLE );		
	  return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
  }

  //Only master process has to continue
  if (handle->proc_rank != 0)
	return OPH_ANALYTICS_OPERATOR_SUCCESS;

  ophidiadb *oDB = &((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->oDB;
  int id_container = ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container;
  int hidden = ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->hidden;
  int delete_type = ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->delete_type;
  char *container_name = ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->container_input;
  char *cwd = ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->cwd;
  char *user = ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->user;

  if(delete_type == OPH_DELETE_LOGIC_CODE) hidden = 0;

  //Check if user can operate on container and if container exists
  int permission = 0;
  int folder_id = 0;
  int container_exists = 0;
  //Check if input path exists
  if((oph_odb_fs_path_parsing("", cwd, &folder_id, NULL, oDB))) {
		//Check if user can work on datacube
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Path %s doesn't exists\n", cwd);
		logging(LOG_ERROR, __FILE__, __LINE__,  OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_CWD_ERROR, container_name, cwd );
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
  }
  if((oph_odb_fs_check_folder_session(folder_id, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->sessionid, oDB, &permission)) || !permission){
		//Check if user can work on datacube
		pmesg(LOG_ERROR, __FILE__, __LINE__, "User %s is not allowed to work in this folder\n", user);
		logging(LOG_ERROR, __FILE__, __LINE__,  OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_DATACUBE_PERMISSION_ERROR, container_name, user );
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
  }
  if(oph_odb_fs_retrieve_container_id_from_container_name(oDB, folder_id, container_name, hidden, &id_container)){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unknown input %s container\n", (hidden ? "hidden" : "visible"));
		logging(LOG_ERROR, __FILE__, __LINE__,id_container, OPH_LOG_OPH_DELETECONTAINER_NO_INPUT_CONTAINER, (hidden ? "hidden" : "visible"), container_name  );
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
  }
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container = id_container;

  if(delete_type == OPH_DELETE_PHYSIC_CODE){
	  if(oph_odb_fs_check_if_container_empty(oDB, id_container)){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Input container isn't empty\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_DELETECONTAINER_CONTAINER_NOT_EMPTY, container_name  );
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
	  }

	  //Remove also grid related to container dimensions
	  if(oph_odb_dim_delete_from_grid_table(oDB, id_container)){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while deleting grid related to container\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETECONTAINER_GRID_DELETE_ERROR );		
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;  
	  }

	  //Delete container and related dimensions/ dimension instances
	  if(oph_odb_fs_delete_from_container_table(oDB, id_container)){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while deleting input container\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETECONTAINER_CONTAINER_DELETE_ERROR );		
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;  
	  }
 
	  oph_odb_db_instance db_;
	  oph_odb_db_instance *db = &db_;
	  if (oph_dim_load_dim_dbinstance(db))
	  {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while loading dimension db paramters\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETECONTAINER_DIM_LOAD );
		oph_dim_unload_dim_dbinstance(db);		
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR; 
	  }
	  if (oph_dim_connect_to_dbms(db->dbms_instance, 0))
	  {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while connecting to dimension dbms\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETECONTAINER_DIM_CONNECT );
		oph_dim_disconnect_from_dbms(db->dbms_instance);
		oph_dim_unload_dim_dbinstance(db);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR; 
	  }
	  if (oph_dim_use_db_of_dbms(db->dbms_instance, db))
	  {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while opening dimension db\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETECONTAINER_DIM_USE_DB );
		oph_dim_disconnect_from_dbms(db->dbms_instance);
		oph_dim_unload_dim_dbinstance(db);
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR; 
	  }

	  char index_dimension_table_name[OPH_COMMON_BUFFER_LEN],label_dimension_table_name[OPH_COMMON_BUFFER_LEN];
	  snprintf(index_dimension_table_name,OPH_COMMON_BUFFER_LEN,OPH_DIM_TABLE_NAME_MACRO,((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container);
	  snprintf(label_dimension_table_name,OPH_COMMON_BUFFER_LEN,OPH_DIM_TABLE_LABEL_MACRO,((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container);

	  if (oph_dim_delete_table(db, index_dimension_table_name))
	  {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while deleting dimension table\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETECONTAINER_DIM_TABLE_DELETE_ERROR );
		oph_dim_disconnect_from_dbms(db->dbms_instance);
		oph_dim_unload_dim_dbinstance(db);	
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR; 
	  }
	  if (oph_dim_delete_table(db, label_dimension_table_name))
	  {
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Error while deleting dimension table\n");
		logging(LOG_ERROR, __FILE__, __LINE__, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container, OPH_LOG_OPH_DELETECONTAINER_DIM_TABLE_DELETE_ERROR );
		oph_dim_disconnect_from_dbms(db->dbms_instance);
		oph_dim_unload_dim_dbinstance(db);	
		return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR; 
	  }

	  oph_dim_disconnect_from_dbms(db->dbms_instance);
	  oph_dim_unload_dim_dbinstance(db);
  }
  else{
	//Check if hidden container exists in folder
	if(oph_odb_fs_is_hidden_container(folder_id, container_name,  oDB, &container_exists))
	{
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to check output container\n");
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_DELETECONTAINER_OUTPUT_CONTAINER_ERROR_NO_CONTAINER, container_name, container_name );	
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}
	if (container_exists)
	{
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Hidden container '%s' already exists in this folder\n", container_name);
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_DELETECONTAINER_OUTPUT_CONTAINER_EXIST_ERROR, container_name, container_name );
		return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
	}
	//If container exists then DELETE
	if(oph_odb_fs_set_container_hidden_status(id_container, 1, oDB)){
		pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to delete  logically  container %s\n", container_name);
		logging(LOG_ERROR, __FILE__, __LINE__, id_container, OPH_LOG_OPH_DELETECONTAINER_UPDATE_CONTAINER_ERROR, container_name );	
		return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
	}		
  }

  return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
コード例 #25
0
void
test_write16_residuals(void)
{
        struct scsi_task *task_ret;
        unsigned char buf[10000];
        struct iscsi_data data;
        int ok;
        unsigned int i;

        logging(LOG_VERBOSE, LOG_BLANK_LINE);
        logging(LOG_VERBOSE, "Test WRITE16 commands with residuals");
        logging(LOG_VERBOSE, "Block size is %zu", block_size);

        CHECK_FOR_DATALOSS;
        CHECK_FOR_SBC;

        if (sd->iscsi_ctx == NULL) {
                const char *err = "[SKIPPED] This WRITE16 test is only "
                        "supported for iSCSI backends";
                logging(LOG_NORMAL, "%s", err);
                CU_PASS(err);
                return;
        }

        /* Try a write16 of 1 block but xferlength == 0 */
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 1;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 0;

        /*
         * we don't want autoreconnect since some targets will drop the session
         * on this condition.
         */
        iscsi_set_noautoreconnect(sd->iscsi_ctx, 1);

        logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==0");

        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, NULL);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);
        CU_ASSERT_NOT_EQUAL(task->status, SCSI_STATUS_CANCELLED); /* XXX redundant? */

        if (task->status        == SCSI_STATUS_CHECK_CONDITION
            && task->sense.key  == SCSI_SENSE_ILLEGAL_REQUEST
            && task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
                logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented.");
                CU_PASS("WRITE16 is not implemented.");
                return;
        }        
        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow",
                block_size);
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);
        scsi_free_scsi_task(task);
        task = NULL;

        /* in case the previous test failed the session */
        iscsi_set_noautoreconnect(sd->iscsi_ctx, 0);


        logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==10000");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 1;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 10000;

        memset(buf, 0xa6, sizeof(buf));
        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual underflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "underflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_UNDERFLOW);

        logging(LOG_VERBOSE, "Verify we got %zu bytes of residual underflow",
                10000 - block_size);
        if (task->residual != 10000 - block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        10000 - block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, 10000 - block_size);
        scsi_free_scsi_task(task);
        task = NULL;


        logging(LOG_VERBOSE, "Try writing one block but with iSCSI expected transfer length==200");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 1;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 200;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        ok = task->status == SCSI_STATUS_GOOD ||
                (task->status == SCSI_STATUS_CHECK_CONDITION &&
                 task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST &&
                 task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_FIELD_IN_INFORMATION_UNIT);
        if (!ok) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT(ok);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got %zu bytes of residual overflow",
                block_size - 200);
        if (task->residual != block_size - 200) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size - 200, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size - 200);

        scsi_free_scsi_task(task);
        task = NULL;



        logging(LOG_VERBOSE, "Try writing two blocks but iSCSI expected "
                "transfer length==%zu (==one block)", block_size);
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 2;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = block_size;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got one block of residual overflow");
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);

        scsi_free_scsi_task(task);
        task = NULL;



        logging(LOG_VERBOSE, "Verify that if iSCSI EDTL > SCSI TL then we only write SCSI TL amount of data");

        logging(LOG_VERBOSE, "Write two blocks of 'a'");
        memset(buf, 'a', 10000);
        WRITE16(sd, 0, 2 * block_size, block_size, 0, 0, 0, 0, 0, buf,
                EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Write one block of 'b' but set iSCSI EDTL to 2 blocks.");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(buf, 'b', 10000);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 1;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = 2 * block_size;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual underflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_UNDERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "underflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_UNDERFLOW);

        logging(LOG_VERBOSE, "Verify we got one block of residual underflow");
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);
        scsi_free_scsi_task(task);
        task = NULL;

        logging(LOG_VERBOSE, "Read the two blocks");
        READ16(sd, NULL, 0, 2* block_size, block_size, 0, 0, 0, 0, 0, buf,
               EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'");
        for (i = 0; i < block_size; i++) {
                if (buf[i] != 'b') {
                        logging(LOG_NORMAL, "First block did not contain expected 'b'");
                        CU_FAIL("Block was not written correctly");
                        break;
                }
        }

        logging(LOG_VERBOSE, "Verify that the second block was NOT overwritten and still contains 'a'");
        for (i = block_size; i < 2 * block_size; i++) {
                if (buf[i] != 'a') {
                        logging(LOG_NORMAL, "Second block was overwritten and no longer contain 'a'");
                        CU_FAIL("Second block was incorrectly overwritten");
                        break;
                }
        }


        logging(LOG_VERBOSE, "Verify that if iSCSI EDTL < SCSI TL then we only write iSCSI EDTL amount of data");

        logging(LOG_VERBOSE, "Write two blocks of 'a'");
        memset(buf, 'a', 10000);
        WRITE16(sd, 0, 2 * block_size, block_size, 0, 0, 0, 0, 0, buf,
                EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Write two blocks of 'b' but set iSCSI EDTL to 1 blocks.");
        task = malloc(sizeof(struct scsi_task));
        CU_ASSERT_PTR_NOT_NULL_FATAL(task);

        memset(buf, 'b', 10000);

        memset(task, 0, sizeof(struct scsi_task));
        task->cdb[0] = SCSI_OPCODE_WRITE16;
        task->cdb[13] = 2;
        task->cdb_size = 16;
        task->xfer_dir = SCSI_XFER_WRITE;
        task->expxferlen = block_size;

        data.size = task->expxferlen;
        data.data = &buf[0];
        task_ret = iscsi_scsi_command_sync(sd->iscsi_ctx, sd->iscsi_lun, task, &data);
        CU_ASSERT_PTR_NOT_NULL_FATAL(task_ret);

        logging(LOG_VERBOSE, "Verify that the target returned SUCCESS");
        if (task->status != SCSI_STATUS_GOOD) {
                logging(LOG_VERBOSE, "[FAILED] Target returned error %s",
                        iscsi_get_error(sd->iscsi_ctx));
        }
        CU_ASSERT_EQUAL(task->status, SCSI_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify residual overflow flag is set");
        if (task->residual_status != SCSI_RESIDUAL_OVERFLOW) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set residual "
                        "overflow flag");
        }
        CU_ASSERT_EQUAL(task->residual_status, SCSI_RESIDUAL_OVERFLOW);

        logging(LOG_VERBOSE, "Verify we got one block of residual overflow");
        if (task->residual != block_size) {
                logging(LOG_VERBOSE, "[FAILED] Target did not set correct "
                        "amount of residual. Expected %zu but got %zu.",
                        block_size, task->residual);
        }
        CU_ASSERT_EQUAL(task->residual, block_size);
        scsi_free_scsi_task(task);
        task = NULL;

        logging(LOG_VERBOSE, "Read the two blocks");
        READ16(sd, NULL, 0, 2* block_size, block_size, 0, 0, 0, 0, 0, buf,
               EXPECT_STATUS_GOOD);

        logging(LOG_VERBOSE, "Verify that the first block was changed to 'b'");
        for (i = 0; i < block_size; i++) {
                if (buf[i] != 'b') {
                        logging(LOG_NORMAL, "First block did not contain expected 'b'");
                        CU_FAIL("Block was not written correctly");
                        break;
                }
        }

        logging(LOG_VERBOSE, "Verify that the second block was NOT overwritten and still contains 'a'");
        for (i = block_size; i < 2 * block_size; i++) {
                if (buf[i] != 'a') {
                        logging(LOG_NORMAL, "Second block was overwritten and no longer contain 'a'");
                        CU_FAIL("Second block was incorrectly overwritten");
                        break;
                }
        }
}
int env_set (HASHTBL *task_tbl, oph_operator_struct *handle)
{
  if (!handle){
  	pmesg(LOG_ERROR, __FILE__, __LINE__, "Null Handle\n");
	  return OPH_ANALYTICS_OPERATOR_NULL_OPERATOR_HANDLE;
  }

  if (!task_tbl){
	  pmesg(LOG_ERROR, __FILE__, __LINE__, "Null operator string\n");
      return OPH_ANALYTICS_OPERATOR_BAD_PARAMETER;
  }

  if (handle->operator_handle){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator handle already initialized\n");
    return OPH_ANALYTICS_OPERATOR_NOT_NULL_OPERATOR_HANDLE;
  }

  if (!(handle->operator_handle = (OPH_DELETECONTAINER_operator_handle *) calloc (1, sizeof (OPH_DELETECONTAINER_operator_handle)))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MEMORY_ERROR_HANDLE );
    return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }

  //1 - Set up struct to empty values
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->id_input_container = 0;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->container_input = NULL;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->cwd = NULL;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->user = NULL;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->hidden = 0;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->delete_type = 0;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys = NULL;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys_num = -1;
  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->sessionid = NULL;

  ophidiadb *oDB = &((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->oDB;
  oph_odb_init_ophidiadb(oDB);	

  //Only master process has to continue
  if (handle->proc_rank != 0)
	return OPH_ANALYTICS_OPERATOR_SUCCESS;

  //3 - Fill struct with the correct data
  char *container_name, *value;

  // retrieve objkeys
  value = hashtbl_get(task_tbl, OPH_IN_PARAM_OBJKEY_FILTER);
  if(!value){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_OBJKEY_FILTER);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_IN_PARAM_OBJKEY_FILTER );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(oph_tp_parse_multiple_value_param(value, &((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys, &((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys_num)){
    pmesg(LOG_ERROR, __FILE__, __LINE__, "Operator string not valid\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, "Operator string not valid\n");
    oph_tp_free_multiple_value_param_list(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys, ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->objkeys_num);
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }

  // retrieve sessionid
  value = hashtbl_get(task_tbl, OPH_ARG_SESSIONID);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_SESSIONID);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_FRAMEWORK_MISSING_INPUT_PARAMETER, OPH_ARG_SESSIONID);
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->sessionid = (char *) strndup (value, OPH_TP_TASKLEN))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_GENERIC_MEMORY_ERROR_INPUT, "sessionid" );
	return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }

  container_name = (!hashtbl_get(task_tbl, OPH_IN_PARAM_CONTAINER_INPUT) ? "NO-CONTAINER" : hashtbl_get(task_tbl, OPH_IN_PARAM_CONTAINER_INPUT));
  value = hashtbl_get(task_tbl, OPH_IN_PARAM_CONTAINER_INPUT);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_CONTAINER_INPUT);
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_IN_PARAM_CONTAINER_INPUT );
    return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->container_input = (char *) strndup (value, OPH_TP_TASKLEN))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MEMORY_ERROR_INPUT_NO_CONTAINER, container_name, "container output name" );
	return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }	

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_CWD);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_CWD);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_IN_PARAM_CWD );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->cwd = (char *) strndup (value, OPH_TP_TASKLEN))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MEMORY_ERROR_INPUT_NO_CONTAINER, container_name, "input path" );
	
	return OPH_ANALYTICS_OPERATOR_MEMORY_ERR;
  }	

  value = hashtbl_get(task_tbl, OPH_ARG_USERNAME);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_ARG_USERNAME);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_ARG_USERNAME );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if(!(((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->user = (char *) strndup (value, OPH_TP_TASKLEN))){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Error allocating memory\n");
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MEMORY_ERROR_INPUT_NO_CONTAINER, container_name, "username" );
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_DELETE_TYPE);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_DELETE_TYPE);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_IN_PARAM_DELETE_TYPE );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if( !strcmp(value, OPH_DELETE_PHYSIC_TYPE) ){
	((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->delete_type = OPH_DELETE_PHYSIC_CODE;
  }
  else{
	((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->delete_type = OPH_DELETE_LOGIC_CODE;
  }

  value = hashtbl_get(task_tbl, OPH_IN_PARAM_HIDDEN);
  if(!value){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Missing input parameter %s\n", OPH_IN_PARAM_HIDDEN);
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_MISSING_INPUT_PARAMETER, container_name, OPH_IN_PARAM_HIDDEN );
	return OPH_ANALYTICS_OPERATOR_INVALID_PARAM;
  }
  if( !strcmp(value, OPH_COMMON_NO_VALUE) ){
	  ((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->hidden = 0;
  }
  else{
	((OPH_DELETECONTAINER_operator_handle*)handle->operator_handle)->hidden = 1;
  }

  if(oph_odb_read_ophidiadb_config_file(oDB)){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to read OphidiaDB configuration\n");
    logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_OPHIDIADB_CONFIGURATION_FILE, container_name );
	return OPH_ANALYTICS_OPERATOR_UTILITY_ERROR;
  }

  if( oph_odb_connect_to_ophidiadb(oDB)){
	pmesg(LOG_ERROR, __FILE__, __LINE__, "Unable to connect to OphidiaDB. Check access parameters.\n");
	logging(LOG_ERROR, __FILE__, __LINE__, OPH_GENERIC_CONTAINER_ID, OPH_LOG_OPH_DELETECONTAINER_OPHIDIADB_CONNECTION_ERROR, container_name );
	return OPH_ANALYTICS_OPERATOR_MYSQL_ERROR;
  }

  return OPH_ANALYTICS_OPERATOR_SUCCESS;
}
コード例 #27
0
void
test_compareandwrite_miscompare(void)
{
	int i, ret;
	unsigned j;
	unsigned char *buf = alloca(2 * 256 * block_size);
	int maxbl;

	CHECK_FOR_DATALOSS;
	CHECK_FOR_SBC;

	if (inq_bl && inq_bl->max_cmp) {
		maxbl = inq_bl->max_cmp;
	} else {
		/* Assume we are not limited */
		maxbl = 256;
	}
	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-256 blocks at the "
		"start of the LUN. One Byte miscompare in the final block.");
	for (i = 1; i < 256; i++) {
		logging(LOG_VERBOSE, "Write %d blocks of 'A' at LBA:0", i);
		memset(buf, 'A', 2 * i * block_size);
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}
		ret = write16(iscsic, tgt_lun, 0, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		if (ret == -2) {
			logging(LOG_NORMAL, "[SKIPPED] WRITE16 is not implemented.");
			CU_PASS("WRITE16 is not implemented.");
			return;
		}	
		CU_ASSERT_EQUAL(ret, 0);

		
		logging(LOG_VERBOSE, "Change byte 27 from the end to 'C' so that it does not match.");
		buf[i * block_size - 27] = 'C';

		if (i > maxbl) {
			logging(LOG_VERBOSE, "Number of blocks %d is greater than "
				"BlockLimits.MaximumCompareAndWriteLength(%d). "
				"Command should fail with INVALID_FIELD_IN_CDB",
				i, maxbl);
			ret = compareandwrite_invalidfieldincdb(iscsic, tgt_lun, 0,
				buf, 2 * i * block_size, block_size,
				0, 0, 0, 0);
			if (ret == -2) {
				CU_PASS("[SKIPPED] Target does not support "
					"COMPARE_AND_WRITE. Skipping test");
				return;
			}
			CU_ASSERT_EQUAL(ret, 0);

			continue;
		}

		memset(buf + i * block_size, 'B', i * block_size);

		logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' "
			"at LBA:0 (if they all contain 'A')", i);
		ret = compareandwrite_miscompare(iscsic, tgt_lun, 0,
			buf, 2 * i * block_size, block_size, 0, 0, 0, 0);
		if (ret == -2) {
			CU_PASS("[SKIPPED] Target does not support "
				"COMPARE_AND_WRITE. Skipping test");
			return;
		}
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Read %d blocks at LBA:0 and verify "
			"they are still unchanged as 'A'", i);
		ret = read16(iscsic, tgt_lun, 0, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		for (j = 0; j < i * block_size; j++) {
			if (buf[j] != 'A') {
				logging(LOG_VERBOSE, "[FAILED] Data changed "
					"eventhough there was a miscompare");
				CU_FAIL("Block was written to");
				return;
			}
		}
	}


	logging(LOG_VERBOSE, "Test COMPARE_AND_WRITE of 1-256 blocks at the "
		"end of the LUN");
	for (i = 1; i < 256; i++) {
		logging(LOG_VERBOSE, "Write %d blocks of 'A' at LBA:%" PRIu64,
			i, num_blocks - i);
		memset(buf, 'A', 2 * i * block_size);
		if (maximum_transfer_length && maximum_transfer_length < i) {
			break;
		}
		ret = write16(iscsic, tgt_lun, num_blocks - i, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Change byte 27 from the end to 'C' so that it does not match.");
		buf[i * block_size - 27] = 'C';


		if (i > maxbl) {
			logging(LOG_VERBOSE, "Number of blocks %d is greater than "
				"BlockLimits.MaximumCompareAndWriteLength(%d). "
				"Command should fail with INVALID_FIELD_IN_CDB",
				i, maxbl);
			ret = compareandwrite_invalidfieldincdb(iscsic, tgt_lun, 0,
				buf, 2 * i * block_size, block_size,
				0, 0, 0, 0);
			CU_ASSERT_EQUAL(ret, 0);

			continue;
		}
		memset(buf + i * block_size, 'B', i * block_size);

		logging(LOG_VERBOSE, "Overwrite %d blocks with 'B' "
			"at LBA:%" PRIu64 " (if they all contain 'A')",
			i, num_blocks - i);
		ret = compareandwrite_miscompare(iscsic, tgt_lun,
			num_blocks - i,
			buf, 2 * i * block_size, block_size, 0, 0, 0, 0);
		CU_ASSERT_EQUAL(ret, 0);

		logging(LOG_VERBOSE, "Read %d blocks at LBA:%" PRIu64 
			"they are still unchanged as 'A'",
			i, num_blocks - i);
		ret = read16(iscsic, tgt_lun, num_blocks - i, i * block_size,
		    block_size, 0, 0, 0, 0, 0, buf);
		CU_ASSERT_EQUAL(ret, 0);

		for (j = 0; j < i * block_size; j++) {
			if (buf[j] != 'A') {
				logging(LOG_VERBOSE, "[FAILED] Data changed "
					"eventhough there was a miscompare");
				CU_FAIL("Block was written to");
				return;
			}
		}
	}
}
コード例 #28
0
void
test_preventallow_2_itnexuses(void)
{
	int ret;
	struct scsi_device sd2;

	CHECK_FOR_SBC;
	CHECK_FOR_REMOVABLE;

	logging(LOG_VERBOSE, LOG_BLANK_LINE);
	logging(LOG_VERBOSE, "Test that PREVENT MEDIUM REMOVAL are seen on other nexuses as well");

	if (sd->iscsi_ctx == NULL) {
		const char *err = "[SKIPPED] This PREVENTALLOW test is "
			"only supported for iSCSI backends";
		logging(LOG_NORMAL, "%s", err);
		CU_PASS(err);
		return;
	}

	logging(LOG_VERBOSE, "Set the PREVENT flag");
	ret = preventallow(sd, 1);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Try to eject the medium");
	ret = startstopunit(sd, 0, 0, 0, 0, 1, 0,
			    EXPECT_REMOVAL_PREVENTED);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Verify we can still access the media.");
	ret = testunitready(sd,
			    EXPECT_STATUS_GOOD);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Create a second connection to the target");
	memset(&sd2, 0, sizeof(sd2));
	sd2.iscsi_ctx = iscsi_context_login(initiatorname2, sd->iscsi_url, &sd->iscsi_lun);
	if (sd2.iscsi_ctx == NULL) {
		logging(LOG_VERBOSE, "Failed to login to target");
		return;
	}

	logging(LOG_VERBOSE, "Try to eject the medium on the second connection");
	ret = startstopunit(&sd2, 0, 0, 0, 0, 1, 0,
			    EXPECT_REMOVAL_PREVENTED);
	CU_ASSERT_EQUAL(ret, 0);


	logging(LOG_VERBOSE, "Logout the second connection from target");
	iscsi_logout_sync(sd2.iscsi_ctx);
	iscsi_destroy_context(sd2.iscsi_ctx);



	logging(LOG_VERBOSE, "Clear PREVENT and load medium in case target failed");
	logging(LOG_VERBOSE, "Test we can clear PREVENT flag");
	ret = preventallow(sd, 0);
	CU_ASSERT_EQUAL(ret, 0);

	logging(LOG_VERBOSE, "Load the medium");
	ret = startstopunit(sd, 0, 0, 0, 0, 1, 1,
			    EXPECT_STATUS_GOOD);
	CU_ASSERT_EQUAL(ret, 0);

}
コード例 #29
0
/*thread for new client connection, arg is the client_fd*/
void *port_mapper_thread(void *arg){
    int sockfd = (int *)arg;

    //LoadLink *link;
    //link = threadArgs->loadLink;

    char logmsg[128]; 

    /* There are 5 types of Packets to be exchanged via port-mapper:
     * 1) Register service (from server to port mapper)         (000)
     * 2) Register acknowledge (from port mapper to server)     (001)
     * 3) Hello Packets (from server to port mapper)            (111)
     * 4) Request server location (from client to portmapper)   (010)
     * 5) Response server location (from portmapper to client)  (011)
     * */

    struct timeval *tmpcost, cost, timer; // use high quality timer to calculate the ping cost
    struct timezone tzp;

    /* keep receiving Data from server or client */
    //while(1){

    gettimeofday(&timer, &tzp);

    /*lock the send back in case it interrupt by other threads*/
    pthread_mutex_lock(&mutex);

    Packet *packet_recv; // MUST use pointer to fit different Packet
    packet_recv = (Packet *)calloc(1, sizeof(Packet));

    //printf("==port-mapper 1==");
    Recv(sockfd, packet_recv, sizeof(Packet), MSG_NOSIGNAL);

    //printf("==port-mapper 2==");
    /* Register service */
    if(strcmp(packet_recv->packet_type, "000") == 0){
        int dup_register = 0;
        //snprintf(logmsg, sizeof(logmsg), "serverthread(0x%x): packet_recv type: %s\n", pthread_self(), packet_recv->packet_type);
        //logging(LOGFILE, logmsg);
        dup_register = writePortMapperTable(packet_recv, PORT_MAPPER_TABLE_FILE);
        sendRegisterReply(sockfd, packet_recv, dup_register);
    }
    /* Hello packet */
    else if(strcmp(packet_recv->packet_type, "111") == 0){
        snprintf(logmsg, sizeof(logmsg), "serverthread(0x%x): packet_recv type: %s\n", pthread_self(), packet_recv->packet_type);
        logging(LOGFILE, logmsg);
        //sendHello(sockfd, router, threadParam->port);
    }
    /* Request server location */
    else if(strcmp(packet_recv->packet_type, "010") == 0 ){
        snprintf(logmsg, sizeof(logmsg), "serverthread(0x%x): packet_recv type: %s\n", pthread_self(), packet_recv->packet_type);
        logging(LOGFILE, logmsg);
        /*record the chosen response into loadlink*/
        sendRequestReply(sockfd, packet_recv);
    }
    //printf("==port-mapper 3==");

    pthread_mutex_unlock(&mutex);

    shutdown(sockfd, SHUT_RDWR);
    //snprintf(logmsg, sizeof(logmsg), "serverthread(0x%x): served request, exiting thread\n", pthread_self());
    //logging(LOGFILE, logmsg);

    //pthread_exit(0);
    free(packet_recv);
    pthread_exit((void *)link);
    //return (void *) threadArgs->loadLink;
}
コード例 #30
0
/*
 * Retrieve a specific instance given an object path
 */
wbem::framework::Instance* wbem::memory::MemoryControllerFactory::getInstance(
	framework::ObjectPath &path, framework::attribute_names_t &attributes)
	throw (framework::Exception)
{
	LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__);

	// create the instance, initialize with attributes from the path
	framework::Instance *pInstance = new framework::Instance(path);
	try
	{
		checkAttributes(attributes);

		path.checkKey(CREATIONCLASSNAME_KEY, MEMORYCONTROLLER_CREATIONCLASSNAME);
		path.checkKey(SYSTEMCREATIONCLASSNAME_KEY, server::BASESERVER_CREATIONCLASSNAME);
		path.checkKey(SYSTEMNAME_KEY, server::getHostName());

		// extract the memory controller id from the object path
		framework::Attribute devIdAttr = path.getKeyValue(DEVICEID_KEY);
		COMMON_LOG_DEBUG_F("DeviceID: %s", devIdAttr.asStr().c_str());

		int rc = nvm_get_device_count();
		if (rc < NVM_SUCCESS)
		{
			throw exception::NvmExceptionLibError(rc);
		}
		else if (rc == 0)
		{
			throw framework::Exception(
					"Could not find any NVDIMMs connected to Memory Controller");
		}

		// get the device_discovery information for all of the dimms
		struct device_discovery dimms[rc];
		if ((rc = nvm_get_devices(dimms, rc)) < NVM_SUCCESS)
		{
			throw exception::NvmExceptionLibError(rc);
		}
		else if (rc == 0)
		{
			throw framework::Exception(
					"Could not find any NVDIMMs connected to Memory Controller");
		}

		// initialize indicator
		int instance_found = 0;
		// find the set of unique memory controller ids used across all DIMMs
		for (int i = 0; i < rc; i++)
		{
			// compare the current DIMM's mem controller to the one that we are searching for
			instance_found = (devIdAttr.stringValue().compare(
					generateUniqueMemoryControllerID(&(dimms[i]))) == 0);
			if (instance_found)
			{
				// if found, update pInstance
				MemoryControllerFactory::addNonKeyAttributesToInstance(
						pInstance, &attributes, &(dimms[i]));

				// break the loop since we found what we were looking for
				break;
			}
		}

		// handle failures
		if (!instance_found)
		{
			COMMON_LOG_ERROR_F("Device ID Not Found: %s", devIdAttr.stringValue().c_str());
			throw framework::ExceptionBadParameter(DEVICEID_KEY.c_str());
		}
	}
	catch (framework::Exception) // clean up and re-throw
	{
		delete pInstance;
		throw;
	}

	return pInstance;
}