Exemple #1
0
static int send_reply(fuse_req_t req, int error, const void *arg,
                      size_t argsize)
{
    struct fuse_out_header out;
    struct iovec iov[2];
    size_t count;
    int res;

    if (error <= -1000 || error > 0) {
        fprintf(stderr, "fuse: bad error value: %i\n",  error);
        error = -ERANGE;
    }

    out.unique = req->unique;
    out.error = error;
    count = 1;
    iov[0].iov_base = &out;
    iov[0].iov_len = sizeof(struct fuse_out_header);
    if (argsize && !error) {
        count++;
        iov[1].iov_base = (void *) arg;
        iov[1].iov_len = argsize;
    }
    out.len = iov_length(iov, count);

    if (req->f->debug) {
        printf("   unique: %llu, error: %i (%s), outsize: %i\n",
               out.unique, out.error, strerror(-out.error), out.len);
        fflush(stdout);
    }
    res = fuse_chan_send(req->ch, iov, count);
    free_req(req);

    return res;
}
Exemple #2
0
static int send_reply_iov(fuse_req_t req, int error, struct iovec *iov,
                          int count)
{
    struct fuse_out_header out;
    int res;

    if (error <= -1000 || error > 0) {
        fprintf(stderr, "fuse: bad error value: %i\n",  error);
        error = -ERANGE;
    }

    out.unique = req->unique;
    out.error = error;
    iov[0].iov_base = &out;
    iov[0].iov_len = sizeof(struct fuse_out_header);
    out.len = iov_length(iov, count);

    /* Foxconn removed start pling 06/19/2009 */
#if 0
    if (req->f->debug)
        fprintf(stderr, "   unique: %llu, error: %i (%s), outsize: %i\n",
                (unsigned long long) out.unique, out.error,
                strerror(-out.error), out.len);
#endif
    /* Foxconn removed end pling 06/19/2009 */

    res = fuse_chan_send(req->ch, iov, count);
    free_req(req);

    return res;
}
static void  FUNCTION_ATTRIBUTE
http_exit(HTTP_RESULT http_result)
{
	http_flag = 0;
	PRINTF("htt_result:%d\n", http_result);

	free_req();

	if(HTTP_TIMEOUT == http_result)
	{
		PRINTF("http time out!\n");
		free_http_buf();
		free_conn();
		user_cb(NULL);
	}
	else
	{
		os_timer_disarm(&timeout_timer);
	}

	if(DNS_FAIL == http_result)
	{
		free_http_buf();
		user_cb(NULL);
	}

	else if(HTTP_ERR == http_result)
	{
		free_http_buf();
		free_conn();
		user_cb(NULL);

	}

	if(HTTP_OK == http_result)
	{
		free_conn();

		const char * version = "HTTP/1.1 ";
		if (os_strncmp(http_buf->buffer, version, os_strlen(version)) != 0)
		{
			PRINTF("Invalid version in %s\n", http_buf->buffer);
			return;
		}

		int http_status = atoi(http_buf->buffer + os_strlen(version));

		char * body = (char *)os_strstr(http_buf->buffer, "\r\n\r\n") + 4;

		if (user_cb != NULL)
		{
			 // Callback is optional.
			user_cb(body);
		}

		free_http_buf();
	}

}
Exemple #4
0
static void hptiop_host_request_callback(struct hptiop_hba *hba, u32 tag)
{
	struct hpt_iop_request_scsi_command *req;
	struct scsi_cmnd *scp;

	req = (struct hpt_iop_request_scsi_command *)hba->reqs[tag].req_virt;
	dprintk("hptiop_host_request_callback: req=%p, type=%d, "
			"result=%d, context=0x%x tag=%d\n",
			req, req->header.type, req->header.result,
			req->header.context, tag);

	BUG_ON(!req->header.result);
	BUG_ON(req->header.type != cpu_to_le32(IOP_REQUEST_TYPE_SCSI_COMMAND));

	scp = hba->reqs[tag].scp;

	if (HPT_SCP(scp)->mapped)
		scsi_dma_unmap(scp);

	switch (le32_to_cpu(req->header.result)) {
	case IOP_RESULT_SUCCESS:
		scp->result = (DID_OK<<16);
		break;
	case IOP_RESULT_BAD_TARGET:
		scp->result = (DID_BAD_TARGET<<16);
		break;
	case IOP_RESULT_BUSY:
		scp->result = (DID_BUS_BUSY<<16);
		break;
	case IOP_RESULT_RESET:
		scp->result = (DID_RESET<<16);
		break;
	case IOP_RESULT_FAIL:
		scp->result = (DID_ERROR<<16);
		break;
	case IOP_RESULT_INVALID_REQUEST:
		scp->result = (DID_ABORT<<16);
		break;
	case IOP_RESULT_MODE_SENSE_CHECK_CONDITION:
		scp->result = SAM_STAT_CHECK_CONDITION;
		memset(&scp->sense_buffer,
				0, sizeof(scp->sense_buffer));
		memcpy(&scp->sense_buffer, &req->sg_list,
				min(sizeof(scp->sense_buffer),
					le32_to_cpu(req->dataxfer_length)));
		break;

	default:
		scp->result = ((DRIVER_INVALID|SUGGEST_ABORT)<<24) |
					(DID_ABORT<<16);
		break;
	}

	dprintk("scsi_done(%p)\n", scp);
	scp->scsi_done(scp);
	free_req(hba, &hba->reqs[tag]);
}
Exemple #5
0
static void discard_req(h2o_memcached_req_t *req)
{
    switch (req->type) {
    case REQ_TYPE_GET:
        h2o_multithread_send_message(req->data.get.receiver, &req->data.get.message);
        break;
    default:
        free_req(req);
        break;
    }
}
Exemple #6
0
void h2o_memcached_cancel_get(h2o_memcached_context_t *ctx, h2o_memcached_req_t *req)
{
    int do_free = 0;

    pthread_mutex_lock(&ctx->mutex);
    req->data.get.cb = NULL;
    if (h2o_linklist_is_linked(&req->pending)) {
        h2o_linklist_unlink(&req->pending);
        do_free = 1;
    }
    pthread_mutex_unlock(&ctx->mutex);

    if (do_free)
        free_req(req);
}
Exemple #7
0
void h2o_memcached_receiver(h2o_multithread_receiver_t *receiver, h2o_linklist_t *messages)
{
    while (!h2o_linklist_is_empty(messages)) {
        h2o_memcached_req_t *req = H2O_STRUCT_FROM_MEMBER(h2o_memcached_req_t, data.get.message.link, messages->next);
        h2o_linklist_unlink(&req->data.get.message.link);
        assert(req->type == REQ_TYPE_GET);
        if (req->data.get.cb != NULL) {
            if (req->data.get.value_is_encoded && req->data.get.value.len != 0) {
                h2o_iovec_t decoded = h2o_decode_base64url(NULL, req->data.get.value.base, req->data.get.value.len);
                h2o_mem_set_secure(req->data.get.value.base, 0, req->data.get.value.len);
                free(req->data.get.value.base);
                req->data.get.value = decoded;
            }
            req->data.get.cb(req->data.get.value, req->data.get.cb_data);
        }
        free_req(req);
    }
}
Exemple #8
0
/* Consumes connection file descriptors from the shared buffer and 
 * processes them.
 */
void *thread(void *vargp){
    // avoid memory leak
    Pthread_detach(pthread_self());
    req_t request;
    int result;
    while(1){
        int connfd = sbuf_remove(&sbuf);
        if((result = process_request(connfd, &request)) == -1){
            fprintf(stderr,"process_request failed\n");
            bad_request(connfd);
            free_req(request);
            Close(connfd);
            continue;
        }

        forward_request(connfd, request);
        Close(connfd);	
    }	
}
Exemple #9
0
void check_reqs() {
	while (reqs) {
		int val = reqs->status;
		if (val != BUSY) {
			enum atypes type =  (reqs->type);
			reqs->type = done;
			switch (type) {
			case aread:
				handle_read(reqs);
				break;
			case awrite:
				handle_write(reqs);
				break;
#ifdef F_ASYNC_GETDIR
			case agetdir:
				handle_getdir(reqs);
				break;
#endif
#ifdef F_ASYNC_DB_EXEC
			case adbexec:
				handle_db_exec(reqs);
				break;
#endif
			case done:
				//must have had an error while handling it before.
				break;
			default:
				fatal("unknown async type\n");
			}
			struct request *here = reqs;
			reqs = reqs->next;
			if(!reqs)
				lastreq = reqs;
			free_funp(here->fun->f.fp);
			free_cb(here->fun);
			free_req(here);
		} else
			return;
	}
}
Exemple #10
0
// 
// The function to handle a client connection
//
void handle_connection(int fd)
{
    http_req req;
    FILE *rx, *tx;

    exit_msg((fd < 0) || (fd > FD_SETSIZE), "bad fd");
    
    // for streams with sockets, need one for read and one for write
    rx = fdopen(fd, "r");
    tx = fdopen(dup(fd), "w");

    init_req(&req);
    http_get_request(rx, &req);
    http_process_request(&req);
    http_response(tx, &req);

    shutdown(fileno(rx), SHUT_RDWR);
    fclose(rx);
    fclose(tx);
    free_req(&req);
    return;
}
Exemple #11
0
void fuse_reply_none(fuse_req_t req)
{
    fuse_chan_send(req->ch, NULL, 0);
    free_req(req);
}
Exemple #12
0
static int
write_read_e2e_dp_tests(struct dev *dev, nvme_build_io_req_fn_t build_io_fn, const char *test_name)
{
	int rc = 0;
	uint32_t lba_count;
	uint32_t io_flags = 0;

	struct io_request *req;
	struct spdk_nvme_ns *ns;
	struct spdk_nvme_qpair *qpair;
	const struct spdk_nvme_ns_data *nsdata;

	ns = spdk_nvme_ctrlr_get_ns(dev->ctrlr, 1);
	if (!ns) {
		fprintf(stderr, "Null namespace\n");
		return 0;
	}

	if (!(spdk_nvme_ns_get_flags(ns) & SPDK_NVME_NS_DPS_PI_SUPPORTED))
		return 0;

	nsdata = spdk_nvme_ns_get_data(ns);
	if (!nsdata || !spdk_nvme_ns_get_sector_size(ns)) {
		fprintf(stderr, "Empty nsdata or wrong sector size\n");
		return 0;
	}

	req = rte_zmalloc(NULL, sizeof(*req), 0);
	if (!req) {
		fprintf(stderr, "Allocate request failed\n");
		return 0;
	}

	/* IO parameters setting */
	lba_count = build_io_fn(ns, req, &io_flags);

	if (!lba_count) {
		fprintf(stderr, "%s: %s bypass the test case\n", dev->name, test_name);
		free_req(req);
		return 0;
	}

	qpair = spdk_nvme_ctrlr_alloc_io_qpair(dev->ctrlr, 0);
	if (!qpair) {
		free_req(req);
		return -1;
	}

	ns_data_buffer_reset(ns, req, DATA_PATTERN);
	if (req->use_extended_lba)
		rc = spdk_nvme_ns_cmd_write(ns, qpair, req->contig, req->lba, lba_count,
					    io_complete, req, io_flags);
	else
		rc = spdk_nvme_ns_cmd_write_with_md(ns, qpair, req->contig, req->metadata, req->lba, lba_count,
						    io_complete, req, io_flags, req->apptag_mask, req->apptag);

	if (rc != 0) {
		fprintf(stderr, "%s: %s write submit failed\n", dev->name, test_name);
		spdk_nvme_ctrlr_free_io_qpair(qpair);
		free_req(req);
		return -1;
	}

	io_complete_flag = 0;

	while (!io_complete_flag)
		spdk_nvme_qpair_process_completions(qpair, 1);

	if (io_complete_flag != 1) {
		fprintf(stderr, "%s: %s write exec failed\n", dev->name, test_name);
		spdk_nvme_ctrlr_free_io_qpair(qpair);
		free_req(req);
		return -1;
	}

	/* reset completion flag */
	io_complete_flag = 0;

	ns_data_buffer_reset(ns, req, 0);
	if (req->use_extended_lba)
		rc = spdk_nvme_ns_cmd_read(ns, qpair, req->contig, req->lba, lba_count,
					   io_complete, req, io_flags);
	else
		rc = spdk_nvme_ns_cmd_read_with_md(ns, qpair, req->contig, req->metadata, req->lba, lba_count,
						   io_complete, req, io_flags, req->apptag_mask, req->apptag);

	if (rc != 0) {
		fprintf(stderr, "%s: %s read failed\n", dev->name, test_name);
		spdk_nvme_ctrlr_free_io_qpair(qpair);
		free_req(req);
		return -1;
	}

	while (!io_complete_flag)
		spdk_nvme_qpair_process_completions(qpair, 1);

	if (io_complete_flag != 1) {
		fprintf(stderr, "%s: %s read failed\n", dev->name, test_name);
		spdk_nvme_ctrlr_free_io_qpair(qpair);
		free_req(req);
		return -1;
	}

	rc = ns_data_buffer_compare(ns, req, DATA_PATTERN);
	if (rc < 0) {
		fprintf(stderr, "%s: %s write/read success, but memcmp Failed\n", dev->name, test_name);
		spdk_nvme_ctrlr_free_io_qpair(qpair);
		free_req(req);
		return -1;
	}

	fprintf(stdout, "%s: %s test passed\n", dev->name, test_name);
	spdk_nvme_ctrlr_free_io_qpair(qpair);
	free_req(req);
	return rc;
}
Exemple #13
0
/* Takes a request and forwards it to its destination server by opening a client
 * connection. Returns the response of the destination server.
 * This function frees memory allocated for the request also using free_req() 
 */
void forward_request(int fd, req_t request){
    int server;
    size_t n, total_read;
    cache_obj* entry;
    char *name, *portstr, http[1024], buf[MAXLINE], cachebuf[MAX_OBJECT_SIZE];
    rio_t rio;

    cachebuf[0] = '\0';
    name = strtok(request.domain, ":");
    portstr = strtok(NULL, ":");
    if(name == NULL){ 
        free_req(request);
        return;
    }
    if(portstr == NULL) portstr = "80";
    
    // checking the cache is still updating it (age)
    P(&w);
    if((entry = in_cache(request.path, num_entries, cache)) != NULL){
        V(&w);
        Rio_writen(fd, entry->buf, entry->obj_size);
    } else {
        V(&w);
         server = Open_clientfd_r(name, atoi(portstr));
         if(server != -1){
            sprintf(http, "GET /%s HTTP/1.0\r\n", request.path);
            strcat(http, request.hdrs);
            Rio_writen(server, http, strlen(http));
            Rio_writen(server, "\r\n", 2);
        } else {
            reparse(&request);
            char *wdpath;
            wdpath = getcwd(NULL,0);
            wdpath = Realloc(wdpath, strlen(wdpath) + strlen(request.path) +1);
            strcat(wdpath, request.path);
            server = open(wdpath, O_RDONLY);
            Free(wdpath);
            if(server == -1){
                not_found(fd);
                free_req(request);
                return;
            }
        }
    	Rio_readinitb(&rio, server);

    	total_read = 0;
    	while((n = Rio_readlineb(&rio, buf, MAXLINE)) > 0){
            if(total_read+n <= MAX_OBJECT_SIZE){
                strcat(cachebuf, buf);
            }
            total_read += n;
            Rio_writen(fd, buf, n);
    	}
        // cache update, critical section
        if(total_read <= MAX_OBJECT_SIZE){
            P(&w);
            cache = cache_write(request.path, cachebuf, num_entries, cache);
            num_entries++;
            V(&w);
        } 
    }
    free_req(request);
}