/**********************************************************************
 *
 * Formatted to look for extended user location info
 *
 **********************************************************************/
static const char* userloc_format(
    const log4c_layout_t*       a_layout,
    const log4c_logging_event_t*a_event)
{
    static char buffer[4096];
    user_locinfo_t* uloc = NULL;

    sd_debug("Formatter s13_userloc checking location info for userdata %X",a_event->evt_loc->loc_data);
    if (a_event->evt_loc->loc_data != NULL)
    {
	sd_debug("Formatter s13_userloc getting a valid user location info pointer");
        uloc = (user_locinfo_t*) a_event->evt_loc->loc_data;
        sprintf(buffer, "[%s][HOST:%s][PID:%i][FILE:%s][LINE:%i][MSG:%s]",
		a_event->evt_category,  
		uloc->hostname, uloc->pid, a_event->evt_loc->loc_file,
		a_event->evt_loc->loc_line,a_event->evt_msg);

    }
    else
    {
        sprintf(buffer, "[%s]::[FILE:%s][LINE:%i][MSG::%s]", 
		a_event->evt_category,  
		a_event->evt_loc->loc_file,
		a_event->evt_loc->loc_line,a_event->evt_msg);
    }
    return buffer;
}
Exemple #2
0
/*
 * Timeout after request is issued after 5s.
 *
 * Heart-beat message will be sent periodically with 1s interval.
 * If the node of the other end of fd fails, we'll detect it in 3s
 */
int set_keepalive(int fd)
{
	int val = 1;

	if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &val, sizeof(val)) < 0) {
		sd_debug("%m");
		return -1;
	}
	val = 5;
	if (setsockopt(fd, SOL_TCP, TCP_KEEPIDLE, &val, sizeof(val)) < 0) {
		sd_debug("%m");
		return -1;
	}
	val = 1;
	if (setsockopt(fd, SOL_TCP, TCP_KEEPINTVL, &val, sizeof(val)) < 0) {
		sd_debug("%m");
		return -1;
	}
	val = 3;
	if (setsockopt(fd, SOL_TCP, TCP_KEEPCNT, &val, sizeof(val)) < 0) {
		sd_debug("%m");
		return -1;
	}
	return 0;
}
Exemple #3
0
/* Trim zero blocks of the beginning and end of the object. */
static int default_trim(int fd, uint64_t oid, const struct siocb *iocb,
			uint64_t *poffset, uint32_t *plen)
{
	trim_zero_blocks(iocb->buf, poffset, plen);

	if (iocb->offset < *poffset) {
		sd_debug("discard between %d, %ld, %" PRIx64, iocb->offset,
			 *poffset, oid);

		if (discard(fd, iocb->offset, *poffset) < 0)
			return -1;
	}

	if (*poffset + *plen < iocb->offset + iocb->length) {
		uint64_t end = iocb->offset + iocb->length;
		if (end == get_objsize(oid))
			/* This is necessary to punch the last block */
			end = round_up(end, BLOCK_SIZE);
		sd_debug("discard between %ld, %ld, %" PRIx64, *poffset + *plen,
			 end, oid);

		if (discard(fd, *poffset + *plen, end) < 0)
			return -1;
	}

	return 0;
}
Exemple #4
0
static int err_to_sderr(char *path, uint64_t oid, int err)
{
	struct stat s;
	char *dir = dirname(path);

	sd_debug("%s", dir);
	switch (err) {
	case ENOENT:
		if (stat(dir, &s) < 0) {
			sd_err("%s corrupted", dir);
			return md_handle_eio(dir);
		}
		sd_debug("object %016" PRIx64 " not found locally", oid);
		return SD_RES_NO_OBJ;
	case ENOSPC:
		/* TODO: stop automatic recovery */
		sd_err("diskfull, oid=%"PRIx64, oid);
		return SD_RES_NO_SPACE;
	case EMFILE:
	case ENFILE:
	case EINTR:
	case EAGAIN:
	case EEXIST:
		sd_err("%m, oid=%"PRIx64, oid);
		/* make gateway try again */
		return SD_RES_NETWORK_ERROR;
	default:
		sd_err("oid=%"PRIx64", %m", oid);
		return md_handle_eio(dir);
	}
}
Exemple #5
0
static int err_to_sderr(const char *path, uint64_t oid, int err)
{
	struct stat s;
	char p[PATH_MAX], *dir;

	/* Use a temporary buffer since dirname() may modify its argument. */
	pstrcpy(p, sizeof(p), path);
	dir = dirname(p);

	sd_debug("%s", path);
	switch (err) {
	case ENOENT:
		if (stat(dir, &s) < 0) {
			sd_err("%s corrupted", dir);
			return md_handle_eio(dir);
		}
		sd_debug("object %016" PRIx64 " not found locally", oid);
		return SD_RES_NO_OBJ;
	case ENOSPC:
		/* TODO: stop automatic recovery */
		sd_err("diskfull, oid=%"PRIx64, oid);
		return SD_RES_NO_SPACE;
	case EMFILE:
	case ENFILE:
	case EINTR:
	case EAGAIN:
	case EEXIST:
		sd_err("%m, oid=%"PRIx64, oid);
		/* make gateway try again */
		return SD_RES_NETWORK_ERROR;
	default:
		sd_err("oid=%"PRIx64", %m", oid);
		return md_handle_eio(dir);
	}
}
Exemple #6
0
/*
 * If the node is gateway, this function only finds the store driver.
 * Otherwise, this function initializes the backend store
 */
int init_store_driver(bool is_gateway)
{
	char driver_name[STORE_LEN], *p;

	pstrcpy(driver_name, sizeof(driver_name), (char *)sys->cinfo.store);

	p = memchr(driver_name, '\0', STORE_LEN);
	if (!p) {
		/*
		 * If the driver name is not NUL terminated we are in deep
		 * trouble, let's get out here.
		 */
		sd_debug("store name not NUL terminated");
		return SD_RES_NO_STORE;
	}

	/*
	 * The store file might not exist in case this is a new sheep that
	 * never joined a cluster before.
	 */
	if (p == driver_name)
		return 0;

	sd_store = find_store_driver(driver_name);
	if (!sd_store) {
		sd_debug("store %s not found", driver_name);
		return SD_RES_NO_STORE;
	}

	if (is_gateway)
		return SD_RES_SUCCESS;

	return sd_store->init();
}
Exemple #7
0
static int on_msg_error(struct xio_session *session,
			enum xio_status error,
			enum xio_msg_direction direction,
			struct xio_msg *msg,
			void *cb_user_context)
{
	/* struct server_data *sdata = (struct server_data *)cb_user_context; */

	if (direction == XIO_MSG_DIRECTION_OUT) {
		sd_debug("**** [%p] message %lu failed. reason: %s",
		       session, msg->sn, xio_strerror(error));
	} else {
		xio_release_response(msg);
		sd_debug("**** [%p] message %lu failed. reason: %s",
		       session, msg->request->sn, xio_strerror(error));
	}

	switch (error) {
	case XIO_E_MSG_FLUSHED:
		break;
	default:
		/* xio_disconnect(sdata->connection); */
		break;
	};

	return 0;
}
Exemple #8
0
static long parse_byte_size (const char *astring)
{
    /* Parse size in bytes depending on the suffix.   Valid suffixes are KB, MB and GB */
    size_t sz = strlen (astring);
    long res = strtol(astring, (char **) NULL, 10);

    if (res <= 0)
	return 0;

    if (astring[ sz - 1 ] == 'B') {
	switch (astring[ sz - 2 ]) {
	    case 'K':
		res *= 1024;
		break;
	    case 'M':
		res *= 1024 * 1024;
		break;
	    case 'G':
		res *= 1024 * 1024 * 1024;
		break;
	    default:
		sd_debug("Wrong suffix parsing size in bytes for string %s, ignoring suffix", 
			astring);
	}
    }
    sd_debug("Parsed size parameter %s to value %ld",astring, res);
    return (res);
}
Exemple #9
0
static int add_event(enum local_event_type type, struct local_node *lnode,
		      void *buf, size_t buf_len)
{
	struct local_node *n;
	struct local_event ev = {
		.type = type,
		.sender = *lnode,
	};

	ev.buf_len = buf_len;
	if (buf)
		memcpy(ev.buf, buf, buf_len);

	ev.nr_lnodes = get_nodes(ev.lnodes);

	switch (type) {
	case EVENT_JOIN:
		ev.lnodes[ev.nr_lnodes] = *lnode;
		ev.nr_lnodes++;
		break;
	case EVENT_LEAVE:
		xlremove(lnode, ev.lnodes, &ev.nr_lnodes, lnode_cmp);
		break;
	case EVENT_GATEWAY:
		n = xlfind(lnode, ev.lnodes, ev.nr_lnodes, lnode_cmp);
		n->gateway = true;
		break;
	case EVENT_NOTIFY:
	case EVENT_BLOCK:
		break;
	case EVENT_UPDATE_NODE:
		n = xlfind(lnode, ev.lnodes, ev.nr_lnodes, lnode_cmp);
		n->node = lnode->node;
		break;
	case EVENT_ACCEPT:
		abort();
	}

	sd_debug("type = %d, sender = %s", ev.type, lnode_to_str(&ev.sender));
	for (int i = 0; i < ev.nr_lnodes; i++)
		sd_debug("%d: %s", i, lnode_to_str(ev.lnodes + i));

	shm_queue_push(&ev);

	shm_queue_notify();

	return SD_RES_SUCCESS;
}
Exemple #10
0
int default_create_and_write(uint64_t oid, const struct siocb *iocb)
{
	char path[PATH_MAX], tmp_path[PATH_MAX];
	int flags = prepare_iocb(oid, iocb, true);
	int ret, fd;
	uint32_t len = iocb->length;
	bool ec = is_erasure_obj(oid, iocb->copy_policy);
	size_t obj_size;

	sd_debug("%"PRIx64, oid);
	get_obj_path(oid, path, sizeof(path));
	get_tmp_obj_path(oid, tmp_path, sizeof(tmp_path));

	if (uatomic_is_true(&sys->use_journal) &&
	    journal_write_store(oid, iocb->buf, iocb->length,
				iocb->offset, true)
	    != SD_RES_SUCCESS) {
		sd_err("turn off journaling");
		uatomic_set_false(&sys->use_journal);
		flags |= O_DSYNC;
		sync();
	}

	fd = open(tmp_path, flags, sd_def_fmode);
	if (fd < 0) {
		if (errno == EEXIST) {
			/*
			 * This happens if node membership changes during object
			 * creation; while gateway retries a CREATE request,
			 * recovery process could also recover the object at the
			 * same time.  They should try to write the same date,
			 * so it is okay to simply return success here.
			 */
			sd_debug("%s exists", tmp_path);
			return SD_RES_SUCCESS;
		}

		sd_err("failed to open %s: %m", tmp_path);
		return err_to_sderr(path, oid, errno);
	}

	if (ec) {
		uint8_t policy = iocb->copy_policy ?:
			get_vdi_copy_policy(oid_to_vid(oid));
		int d;
		ec_policy_to_dp(policy, &d, NULL);
		obj_size = SD_DATA_OBJ_SIZE / d;
	} else
Exemple #11
0
static inline void write_info_update(struct write_info *wi, int pos)
{
	sd_debug("%d, %d", wi->nr_sent, pos);
	wi->nr_sent--;
	memmove(wi->ent + pos, wi->ent + pos + 1,
		sizeof(struct write_info_entry) * (wi->nr_sent - pos));
}
Exemple #12
0
void *mount3_mnt(struct svc_req *req, struct nfs_arg *arg)
{
	static mountres3 result;
	static int auth = AUTH_UNIX; /* FIXME: add auth support */
	static struct svc_fh fh;
	char *p = arg->mnt;
	uint32_t vid;
	int ret;

	sd_debug("%s", p);

	ret = sd_lookup_vdi(p, &vid);
	switch (ret) {
	case SD_RES_SUCCESS:
		fh.ino = fs_root_ino(vid);
		result.fhs_status = MNT3_OK;
		break;
	case SD_RES_NO_VDI:
		result.fhs_status = MNT3ERR_NOENT;
		goto out;
	default:
		result.fhs_status = MNT3ERR_SERVERFAULT;
		goto out;
	}

	result.mountres3_u.mountinfo.fhandle.fhandle3_len = sizeof(fh);
	result.mountres3_u.mountinfo.fhandle.fhandle3_val = (char *)&fh;
	result.mountres3_u.mountinfo.auth_flavors.auth_flavors_len = 1;
	result.mountres3_u.mountinfo.auth_flavors.auth_flavors_val = &auth;
out:
	return &result;
}
/* *********************************
   void serdisp_directgfx_init(dd)
   *********************************
   initialise
   *********************************
   dd     ... display descriptor
*/
void serdisp_directgfx_init(serdisp_t* dd) {
  char caption[40];
  SDL_Surface* screen;

  if (fp_SDL_Init(SDL_INIT_VIDEO) != 0) {
    sd_error(SERDISP_ENOTSUP, "%s(): unable to initialise SDL: %s", __func__, fp_SDL_GetError());
    sd_runtimeerror = 1;
    fp_SDL_Quit();
    return;
  }

  screen = serdisp_directgfx_internal_getStruct(dd)->screen = 
    (void*)fp_SDL_SetVideoMode(dd->width, dd->height, 0 /*sdl_depth*/, SDL_HWSURFACE | SDL_HWACCEL);

  if (screen == NULL) {
    sd_error(SERDISP_ENOTSUP, "%s(): unable to set video mode: %s", __func__, fp_SDL_GetError());
    sd_runtimeerror = 1;
    fp_SDL_Quit();
    return;
  }

  snprintf(caption, sizeof(caption)-1, "serdisplib::SDL %dx%dx%d", screen->w, screen->h, screen->format->BitsPerPixel);
  fp_SDL_WM_SetCaption(caption, NULL);

  sd_debug(2, "%s(): done with initialising", __func__);
}
void serdisp_t6963_checkready(serdisp_t* dd) {
  /* active-low signals are internally seen active-high because they will be auto-inverted later if needed */
  long td_clk1 =          SIG_CD         ;
  long td_clk2 = SIG_CE | SIG_CD | SIG_RD;
  long td_clk3 =          SIG_CD         ;

  int cnt = 0;

  /* check, if at least one of D0, D1, or D3 is high */
  long rc;     /* returned status byte */
  long rc_check = SIG_D0 | SIG_D1 | SIG_D3;

  if (dd->feature_backlight && dd->curr_backlight) {
    td_clk1 |= SIG_BACKLIGHT;
    td_clk2 |= SIG_BACKLIGHT;
    td_clk3 |= SIG_BACKLIGHT;
  }

  do {
    SDCONN_write(dd->sdcd, td_clk1, dd->sdcd->io_flags_writecmd);
    sdtools_nsleep( (dd->delay < 2) ? 2 : dd->delay);
    SDCONN_write(dd->sdcd, td_clk2, dd->sdcd->io_flags_writecmd);
    sdtools_nsleep( (dd->delay < 2) ? 2 : dd->delay);
    rc = SDCONN_read(dd->sdcd, dd->sdcd->io_flags_readstatus);
    sdtools_nsleep( (dd->delay < 2) ? 2 : dd->delay);
    SDCONN_write(dd->sdcd, td_clk3, dd->sdcd->io_flags_writecmd);
    sdtools_nsleep(dd->delay);
    cnt ++;
  } while (  (!(rc & rc_check)) && cnt < 10);

  if (cnt > 1)   
    sd_debug(1, "serdisp_t6963_checkready(): delay too small? (cnt = %d; rc = 0x%08lx)", cnt, rc);
}
Exemple #15
0
static int gw_client_on_response(struct xio_session *session,
				 struct xio_msg *rsp,
				 int last_in_rxq,
				 void *cb_user_context)
{
	struct xio_forward_info_entry *fi_entry =
		(struct xio_forward_info_entry *)cb_user_context;
	struct xio_forward_info *fi = fi_entry->fi;

	struct xio_vmsg *pimsg = &rsp->in;
	struct xio_iovec_ex *isglist = vmsg_sglist(pimsg);

	int nents = vmsg_sglist_nents(pimsg), total = 0;

	sd_debug("response on fi_entry %p", fi_entry);

	for (int i = 0; i < nents; i++) {
		memcpy((char *)fi_entry->buf + total,
		       isglist[i].iov_base, isglist[i].iov_len);

		total += isglist[i].iov_len;
	}

	fi->nr_done++;
	if (fi->nr_done == fi->nr_send)
		xio_context_stop_loop(fi->ctx);

	return 0;
}
Exemple #16
0
static int server_on_request(struct xio_session *session,
			     struct xio_msg *xio_req,
			     int last_in_rxq,
			     void *cb_user_conext)
{
	struct client_info *ci = (struct client_info *)cb_user_conext;
	struct sd_req *hdr;
	struct request *req;

	struct xio_iovec_ex *sglist = vmsg_sglist(&xio_req->in);
	int nents = vmsg_sglist_nents(&xio_req->in);

	sd_debug("on request: %p, %p, nents: %d", session, xio_req, nents);
	hdr = xio_req->in.header.iov_base;

	req = alloc_request(ci, hdr->data_length);
	memcpy(&req->rq, hdr, sizeof(req->rq));

	if (hdr->data_length && hdr->flags & SD_FLAG_CMD_WRITE) {
		sd_assert(nents == 1);
		req->data = sglist[0].iov_base;
	}

	xio_req->in.header.iov_base  = NULL;
	xio_req->in.header.iov_len  = 0;
	vmsg_sglist_set_nents(&xio_req->in, 0);

	ci->xio_req = xio_req;

	queue_request(req);

	xio_context_stop_loop(xio_get_main_ctx());
	return 0;
}
Exemple #17
0
static int move_object_to_stale_dir(uint64_t oid, const char *wd,
				    uint32_t epoch, uint8_t ec_index,
				    struct vnode_info *vinfo, void *arg)
{
	char path[PATH_MAX], stale_path[PATH_MAX];
	uint32_t tgt_epoch = *(uint32_t *)arg;

	/* ec_index from md.c is reliable so we can directly use it */
	if (ec_index < SD_MAX_COPIES) {
		snprintf(path, PATH_MAX, "%s/%016"PRIx64"_%d",
			 md_get_object_dir(oid), oid, ec_index);
		snprintf(stale_path, PATH_MAX,
			 "%s/.stale/%016"PRIx64"_%d.%"PRIu32,
			 md_get_object_dir(oid), oid, ec_index, tgt_epoch);
	} else {
		snprintf(path, PATH_MAX, "%s/%016" PRIx64,
			 md_get_object_dir(oid), oid);
		snprintf(stale_path, PATH_MAX, "%s/.stale/%016"PRIx64".%"PRIu32,
			 md_get_object_dir(oid), oid, tgt_epoch);
	}

	if (unlikely(rename(path, stale_path)) < 0) {
		sd_err("failed to move stale object %" PRIX64 " to %s, %m", oid,
		       path);
		return SD_RES_EIO;
	}

	sd_debug("moved object %"PRIx64, oid);
	return SD_RES_SUCCESS;
}
Exemple #18
0
static int init_signal(void)
{
	sigset_t mask;
	int ret;

	sigemptyset(&mask);
	sigaddset(&mask, SIGTERM);
	sigprocmask(SIG_BLOCK, &mask, NULL);

	sigfd = signalfd(-1, &mask, SFD_NONBLOCK);
	if (sigfd < 0) {
		sd_err("failed to create a signal fd: %m");
		return -1;
	}

	ret = register_event(sigfd, signal_handler, NULL);
	if (ret) {
		sd_err("failed to register signal handler (%d)", ret);
		return -1;
	}

	sd_debug("register signal_handler for %d", sigfd);

	return 0;
}
Exemple #19
0
int do_read(int sockfd, void *buf, int len, bool (*need_retry)(uint32_t epoch),
	    uint32_t epoch, uint32_t max_count)
{
	int ret, repeat = max_count;
reread:
	ret = read(sockfd, buf, len);
	if (ret == 0) {
		sd_debug("connection is closed (%d bytes left)", len);
		return 1;
	}
	if (ret < 0) {
		if (errno == EINTR)
			goto reread;
		/*
		 * Since we set timeout for read, we'll get EAGAIN even for
		 * blocking sockfd.
		 */
		if (errno == EAGAIN && repeat &&
		    (need_retry == NULL || need_retry(epoch))) {
			repeat--;
			goto reread;
		}

		sd_err("failed to read from socket: %d, %m", ret);
		return 1;
	}

	len -= ret;
	buf = (char *)buf + ret;
	if (len)
		goto reread;

	return 0;
}
Exemple #20
0
int default_get_hash(uint64_t oid, uint32_t epoch, uint8_t *sha1)
{
	int ret;
	void *buf;
	struct siocb iocb = {};
	uint32_t length;
	bool is_readonly_obj = oid_is_readonly(oid);
	char path[PATH_MAX];

	ret = get_object_path(oid, epoch, path, sizeof(path));
	if (ret != SD_RES_SUCCESS)
		return ret;

	if (is_readonly_obj) {
		if (get_object_sha1(path, sha1) == 0) {
			sd_debug("use cached sha1 digest %s",
				 sha1_to_hex(sha1));
			return SD_RES_SUCCESS;
		}
	}

	length = get_store_objsize(oid);
	buf = valloc(length);
	if (buf == NULL)
		return SD_RES_NO_MEM;

	iocb.epoch = epoch;
	iocb.buf = buf;
	iocb.length = length;

	ret = default_read_from_path(oid, path, &iocb);
	if (ret != SD_RES_SUCCESS) {
		free(buf);
		return ret;
	}

	get_buffer_sha1(buf, length, sha1);
	free(buf);

	sd_debug("the message digest of %"PRIx64" at epoch %d is %s", oid,
		 epoch, sha1_to_hex(sha1));

	if (is_readonly_obj)
		set_object_sha1(path, sha1);

	return ret;
}
Exemple #21
0
static int sd_inand_staff_init(struct mmc *mmc)
{
	struct aml_card_sd_info * sdio=mmc->priv;
    unsigned base;
		
	sd_debug("");
    sdio->sdio_pwr_prepare(sdio->sdio_port);
	sd_debug("power off");
	sdio->sdio_pwr_off(sdio->sdio_port);
	
	if(sdio->sdio_port == SDIO_PORT_B){  //only power ctrl for external tf card
        base=get_timer(0);
#if defined(CONFIG_VLSI_EMULATOR)
	    while(get_timer(base)<1);
#else
        while(get_timer(base)<200);
#endif 
    }
    sd_debug("pre power on");
    sdio->sdio_pwr_on(sdio->sdio_port);
    sdio->sdio_init(sdio->sdio_port);
    
    //clear sd d1~d3 pinmux,
    //just for sdio debug board, only can work with 1bit mode
    if((sdio->sdio_port == SDIO_PORT_B)&&(sdio_debug_1bit_flag)){   
    	clrbits_le32(P_PERIPHS_PIN_MUX_2,7<<12);
    	mmc->host_caps = MMC_MODE_HS;
    }
    	
    sd_debug("post power on");
    if(sdio->sdio_port == SDIO_PORT_B){   //only power ctrl for external tf card
        base=get_timer(0);
#if defined(CONFIG_VLSI_EMULATOR)
	    while(get_timer(base)<1);
#else
        while(get_timer(base)<200);
#endif 
    }
    
    aml_sd_cfg_swth(mmc);
    if(!sdio->inited_flag)
        sdio->inited_flag = 1;
//    int ret=rom_c();
//    sd_debug("rom_c==%d",rom_c());
//    return ret;
	return SD_NO_ERROR;
}
Exemple #22
0
int default_write(uint64_t oid, const struct siocb *iocb)
{
	int flags = prepare_iocb(oid, iocb, false), fd,
	    ret = SD_RES_SUCCESS;
	char path[PATH_MAX];
	ssize_t size;
	uint32_t len = iocb->length;
	uint64_t offset = iocb->offset;
	static bool trim_is_supported = true;

	if (iocb->epoch < sys_epoch()) {
		sd_debug("%"PRIu32" sys %"PRIu32, iocb->epoch, sys_epoch());
		return SD_RES_OLD_NODE_VER;
	}

	if (uatomic_is_true(&sys->use_journal) &&
	    unlikely(journal_write_store(oid, iocb->buf, iocb->length,
					 iocb->offset, false))
	    != SD_RES_SUCCESS) {
		sd_err("turn off journaling");
		uatomic_set_false(&sys->use_journal);
		flags |= O_DSYNC;
		sync();
	}

	get_store_path(oid, iocb->ec_index, path);

	/*
	 * Make sure oid is in the right place because oid might be misplaced
	 * in a wrong place, due to 'shutdown/restart with less/more disks' or
	 * any bugs. We need call err_to_sderr() to return EIO if disk is broken
	 */
	if (!default_exist(oid, iocb->ec_index))
		return err_to_sderr(path, oid, ENOENT);

	fd = open(path, flags, sd_def_fmode);
	if (unlikely(fd < 0))
		return err_to_sderr(path, oid, errno);

	if (trim_is_supported && is_sparse_object(oid)) {
		if (default_trim(fd, oid, iocb, &offset, &len) < 0) {
			trim_is_supported = false;
			offset = iocb->offset;
			len = iocb->length;
		}
	}

	size = xpwrite(fd, iocb->buf, len, offset);
	if (unlikely(size != len)) {
		sd_err("failed to write object %"PRIx64", path=%s, offset=%"
		       PRId32", size=%"PRId32", result=%zd, %m", oid, path,
		       iocb->offset, iocb->length, size);
		ret = err_to_sderr(path, oid, errno);
		goto out;
	}
out:
	close(fd);
	return ret;
}
Exemple #23
0
void *mount3_umnt(struct svc_req *req, struct nfs_arg *arg)
{
	static void *result;
	char *p = arg->umnt;

	sd_debug("%s", p);

	return &result;
}
Exemple #24
0
LOG4C_API log4c_rollingpolicy_t* log4c_rollingpolicy_new(const char* a_name){
  log4c_rollingpolicy_t* this;
  
  sd_debug("log4c_rollingpolicy_new[ ");
  if (!a_name)
    return NULL;
  sd_debug("new policy name='%s'", a_name);
  this	          = sd_calloc(1, sizeof(log4c_rollingpolicy_t));
  this->policy_name     = sd_strdup(a_name);
  this->policy_type     = &log4c_rollingpolicy_type_sizewin;
  this->policy_udata    = NULL;
  this->policy_rfudatap  = NULL;
  this->policy_flags = 0; 
  
  sd_debug("]");
  
  return this;
}
Exemple #25
0
/*
 * If force_create is true, this function create the file even when the
 * temporary file exists.
 */
int atomic_create_and_write(const char *path, const char *buf, size_t len,
			    bool force_create)
{
	int fd, ret;
	char tmp_path[PATH_MAX];

	snprintf(tmp_path, PATH_MAX, "%s.tmp", path);
again:
	fd = open(tmp_path, O_WRONLY | O_CREAT | O_SYNC | O_EXCL, sd_def_fmode);
	if (fd < 0) {
		if (errno == EEXIST) {
			if (force_create) {
				sd_debug("clean up a temporary file %s",
					 tmp_path);
				unlink(tmp_path);
				goto again;
			} else
				sd_debug("someone else is dealing with %s",
					 tmp_path);
		} else
			sd_err("failed to open temporal file %s, %m", tmp_path);
		ret = -1;
		goto end;
	}

	ret = xwrite(fd, buf, len);
	if (unlikely(ret != len)) {
		sd_err("failed to write %s, %m", path);
		ret = -1;
		goto close_fd;
	}

	ret = rename(tmp_path, path);
	if (unlikely(ret < 0)) {
		sd_err("failed to rename %s, %m", path);
		ret = -1;
	}

close_fd:
	close(fd);
end:
	return ret;
}
Exemple #26
0
static int sd_inand_staff_init(struct mmc *mmc)
{
	struct aml_card_sd_info * sdio=mmc->priv;
    unsigned base;
	
	sd_debug("");
    sdio->sdio_pwr_prepare(sdio->sdio_port,sdio);
	sd_debug("power off");
	sdio->sdio_pwr_off(sdio->sdio_port,sdio);
		
	if(sdio->sdio_pwr_flag&CARD_SD_SDIO_PWR_OFF)
	{	
	    sdio->sdio_pwr_flag &=~CARD_SD_SDIO_PWR_OFF;
        base=get_timer(0);
#if defined(CONFIG_VLSI_EMULATOR)
 		while(get_timer(base)<1);
#else
        while(get_timer(base)<200);
#endif 
    }
    sd_debug("pre power on");
    sdio->sdio_pwr_on(sdio->sdio_port,sdio);
    sdio->sdio_init(sdio->sdio_port,sdio);
    sd_debug("post power on");
        
    if(sdio->sdio_pwr_flag&CARD_SD_SDIO_PWR_ON)
    {    	
        sdio->sdio_pwr_flag &=~CARD_SD_SDIO_PWR_ON;
        base=get_timer(0);
#if defined(CONFIG_VLSI_EMULATOR)
 		while(get_timer(base)<1);
#else
        while(get_timer(base)<200);
#endif 
    }
    aml_sd_cfg_swth(mmc);
    if(!sdio->inited_flag)
        sdio->inited_flag = 1;
//    int ret=rom_c();
//    sd_debug("rom_c==%d",rom_c());
//    return ret;
	return SD_NO_ERROR;
}
Exemple #27
0
static int do_epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len,
			     time_t *timestamp)
{
	int fd, ret, nr_nodes;
	char path[PATH_MAX];
	struct stat epoch_stat;

	snprintf(path, sizeof(path), "%s%08u", epoch_path, epoch);
	fd = open(path, O_RDONLY);
	if (fd < 0) {
		sd_debug("failed to open epoch %"PRIu32" log, %m", epoch);
		goto err;
	}

	memset(&epoch_stat, 0, sizeof(epoch_stat));
	ret = fstat(fd, &epoch_stat);
	if (ret < 0) {
		sd_err("failed to stat epoch %"PRIu32" log, %m", epoch);
		goto err;
	}

	if (len < epoch_stat.st_size - sizeof(*timestamp)) {
		sd_err("invalid epoch %"PRIu32" log", epoch);
		goto err;
	}

	ret = xread(fd, nodes, epoch_stat.st_size - sizeof(*timestamp));
	if (ret < 0) {
		sd_err("failed to read epoch %"PRIu32" log, %m", epoch);
		goto err;
	}

	/* Broken epoch, just ignore */
	if (ret % sizeof(struct sd_node) != 0) {
		sd_err("invalid epoch %"PRIu32" log", epoch);
		goto err;
	}

	nr_nodes = ret / sizeof(struct sd_node);

	if (timestamp) {
		ret = xread(fd, timestamp, sizeof(*timestamp));
		if (ret != sizeof(*timestamp)) {
			sd_err("invalid epoch %"PRIu32" log", epoch);
			goto err;
		}
	}

	close(fd);
	return nr_nodes;
err:
	if (fd >= 0)
		close(fd);
	return -1;
}
Exemple #28
0
int init_disk_space(const char *base_path)
{
	int ret = SD_RES_SUCCESS;
	uint64_t space_size = 0, mds;
	struct statvfs fs;

	if (sys->gateway_only)
		goto out;

	/* We need to init md even we don't need to update sapce */
	mds = md_init_space();

	/* If it is restarted */
	ret = get_node_space(&space_size);
	if (space_size != 0) {
		sys->disk_space = space_size;
		goto out;
	}

	/* User has specified the space at startup */
	if (sys->disk_space) {
		ret = set_node_space(sys->disk_space);
		goto out;
	}

	if (mds) {
		sys->disk_space = mds;
	} else {
		ret = statvfs(base_path, &fs);
		if (ret < 0) {
			sd_debug("get disk space failed %m");
			ret = SD_RES_EIO;
			goto out;
		}
		sys->disk_space = (uint64_t)fs.f_frsize * fs.f_bavail;
	}

	ret = set_node_space(sys->disk_space);
out:
	sd_debug("disk free space is %" PRIu64, sys->disk_space);
	return ret;
}
Exemple #29
0
/*
int aml_sdio_io_init(struct mmc *mmc, ulong flag)
{
	char *pe[MODSIG_SDIO_MAX];
	int padindex, ret;
	unsigned i, sdio_port;
	aml_module_t sdio_module;
	struct aml_card_sd_info *aml_priv = NULL;
	if(mmc == NULL)
		return -1;
	
	aml_priv = mmc->priv;
	sdio_port = aml_priv->sdio_port;
	
	switch (sdio_port) {
	case 0:
		pe[0] = getenv("MODULE_SDIOA.MODSIG_SDIO_CMD");
		pe[1] = getenv("MODULE_SDIOA.MODSIG_SDIO_CLK");
		pe[2] = getenv("MODULE_SDIOA.MODSIG_SDIO_D0");
		pe[3] = getenv("MODULE_SDIOA.MODSIG_SDIO_D1");
		pe[4] = getenv("MODULE_SDIOA.MODSIG_SDIO_D2");
		pe[5] = getenv("MODULE_SDIOA.MODSIG_SDIO_D3");
		pe[6] = getenv("MODULE_SDIOA.MODSIG_SDIO_DET");
		pe[7] = getenv("MODULE_SDIOA.MODSIG_SDIO_WP");
		pe[8] = getenv("MODULE_SDIOA.MODSIG_SDIO_PWR");
		sdio_module = MODULE_SDIOA;
		break;
	case 1:
		pe[0] = getenv("MODULE_SDIOB.MODSIG_SDIO_CMD");
		pe[1] = getenv("MODULE_SDIOB.MODSIG_SDIO_CLK");
		pe[2] = getenv("MODULE_SDIOB.MODSIG_SDIO_D0");
		pe[3] = getenv("MODULE_SDIOB.MODSIG_SDIO_D1");
		pe[4] = getenv("MODULE_SDIOB.MODSIG_SDIO_D2");
		pe[5] = getenv("MODULE_SDIOB.MODSIG_SDIO_D3");
		pe[6] = getenv("MODULE_SDIOB.MODSIG_SDIO_DET");
		pe[7] = getenv("MODULE_SDIOB.MODSIG_SDIO_WP");
		pe[8] = getenv("MODULE_SDIOB.MODSIG_SDIO_PWR");
		sdio_module = MODULE_SDIOB;
		break;
	case 2:
		pe[0] = getenv("MODULE_SDIOC.MODSIG_SDIO_CMD");
		pe[1] = getenv("MODULE_SDIOC.MODSIG_SDIO_CLK");
		pe[2] = getenv("MODULE_SDIOC.MODSIG_SDIO_D0");
		pe[3] = getenv("MODULE_SDIOC.MODSIG_SDIO_D1");
		pe[4] = getenv("MODULE_SDIOC.MODSIG_SDIO_D2");
		pe[5] = getenv("MODULE_SDIOC.MODSIG_SDIO_D3");
		pe[6] = getenv("MODULE_SDIOC.MODSIG_SDIO_DET");
		pe[7] = getenv("MODULE_SDIOC.MODSIG_SDIO_WP");
		pe[8] = getenv("MODULE_SDIOC.MODSIG_SDIO_PWR");
		sdio_module = MODULE_SDIOC;
		break;
	default:
		break;
	}

	for (i = 0; i < MODSIG_SDIO_MAX; i++) {
		if(pe[i] == NULL) {
			printf("MODULE_SDIO%c io %u error! Use default config.\n", 'A'+ sdio_module - MODULE_SDIOA, i);
			set_default_sdio(sdio_port);
			return 0;
		}
	}
	
	padindex = search_pad(pe[0]);
	ret = switch_padsig(padindex, sdio_module, MODSIG_SDIO_CMD, 1);
	if(ret)
		return -1;
	SD_CMD_PAD = padindex;
	
	padindex = search_pad(pe[1]);
	ret = switch_padsig(padindex, sdio_module, MODSIG_SDIO_CLK, 1);
	if(ret)
		return -1;
	SD_CLK_PAD = padindex;
	
	padindex = search_pad(pe[2]);
	ret = switch_padsig(padindex, sdio_module, MODSIG_SDIO_D0, 1);
	if(ret)
		return -1;
	SD_DAT0_PAD = padindex;
	
	padindex = search_pad(pe[3]);
	ret = switch_padsig(padindex, sdio_module, MODSIG_SDIO_D1, 1);
	if(ret)
		return -1;
	SD_DAT1_PAD = padindex;
	
	padindex = search_pad(pe[4]);
	ret = switch_padsig(padindex, sdio_module, MODSIG_SDIO_D2, 1);
	if(ret)
		return -1;
	SD_DAT2_PAD = padindex;
	
	padindex = search_pad(pe[5]);
	ret = switch_padsig(padindex, sdio_module, MODSIG_SDIO_D3, 1);
	if(ret)
		return -1;
	SD_DAT3_PAD = padindex;
	
	padindex = search_pad(pe[6]);
	ret = switch_padsig(padindex, MODULE_GPIO, 0, 1);
	if(ret)
		return -1;
	SD_DET_PAD = padindex;
	ret = ctrl_padlevel(padindex, 1, 0);
	
	padindex = search_pad(pe[7]);
	ret = switch_padsig(padindex, MODULE_GPIO, 0, 1);
	if(ret)
		return -1;
	SD_WP_PAD = padindex;
	ret = ctrl_padlevel(padindex, 1, 0);
	
	padindex = search_pad(pe[8]);
	ret = switch_padsig(padindex, MODULE_GPIO, 0, 1);
	if(ret)
		return -1;
	SD_PWR_PAD = padindex;
	SD_PWR_EN_LEVEL = 0;
	ret = ctrl_padlevel(padindex, 0, 1);
	return 0;
}
 */
void aml_sd_cfg_swth(struct mmc *mmc)
{
	//DECLARE_GLOBAL_DATA_PTR;
	
	struct aml_card_sd_info *aml_priv = mmc->priv;
    
    
	unsigned long sdio_config =	0;
	
	unsigned bus_width=(mmc->bus_width == 4)?1:0;
	if(mmc->clock<mmc->f_min)
	    mmc->clock=mmc->f_min;
	if(mmc->clock>mmc->f_max)
	    mmc->clock=mmc->f_max;
	
	int clk=clk_get_rate(SDIO_CLKSRC);
	unsigned clk_div=(clk / (2*mmc->clock));
		
    writel(1<<soft_reset_bit, PREG_SDIO_IRQ_CFG);
    mdelay(3);
    //printf("test get_clk81:%d,sdio clk_div:0x%x,clock:%d\n",clk,clk_div,mmc->clock);

	sdio_config = ((2 << sdio_write_CRC_ok_status_bit) |
                      (2 << sdio_write_Nwr_bit) |
                      (3 << m_endian_bit) |
                      (bus_width<<bus_width_bit)|
                      (39 << cmd_argument_bits_bit) |
                      (0 << cmd_out_at_posedge_bit) |
                      (0 << cmd_disable_CRC_bit) |
                      (0 << response_latch_at_negedge_bit) |
                      (clk_div << cmd_clk_divide_bit));

	sd_debug("sdio_config=%x",sdio_config);
	writel(sdio_config, PREG_SDIO_CFG);
	writel((aml_priv->sdio_port & 0x3), PREG_SDIO_MULT_CFG);	//Switch to	SDIO_A/B/C
	
	sd_debug("bus_width=%d\tclk_div=%d\n\tclk=%d\tsd_clk=%d",
	    bus_width,clk_div,clk,mmc->clock);
    	    
	sd_debug("port=%d act_clk=%d",aml_priv->sdio_port,clk/(2*(clk_div+1)));
	return;
}
Exemple #30
0
static void check_host_env(void)
{
	struct rlimit r;

	if (getrlimit(RLIMIT_NOFILE, &r) < 0)
		sd_err("failed to get nofile %m");
	else if (r.rlim_cur < SD_RLIM_NOFILE) {
		r.rlim_cur = SD_RLIM_NOFILE;
		r.rlim_max = SD_RLIM_NOFILE;
		if (setrlimit(RLIMIT_NOFILE, &r) != 0) {
			sd_err("failed to set nofile to suggested %lu, %m",
			       r.rlim_cur);
			sd_err("please increase nofile via sysctl fs.nr_open");
		} else {
			sd_info("allowed open files set to suggested %lu",
				r.rlim_cur);
		}
	}

	if (getrlimit(RLIMIT_CORE, &r) < 0)
		sd_debug("failed to get core %m");
	else if (r.rlim_cur < RLIM_INFINITY)
		sd_debug("allowed core file size %lu, suggested unlimited",
			 r.rlim_cur);

	/*
	 * Disable glibc's dynamic mmap threshold and set it as 512k.
	 *
	 * We have to disable dynamic threshold because its inefficiency to
	 * release freed memory back to OS. Setting it as 512k practically means
	 * allocation larger than or equal to 512k will use mmap() for malloc()
	 * and munmap() for free(), guaranteeing allocated memory will not be
	 * cached in the glibc's ptmalloc internal pool.
	 *
	 * 512k is not a well tested optimal value for IO request size, I choose
	 * it because it is default value for disk drive that it can transfer at
	 * a time. So default installation of guest will issue at most 512K
	 * sized request.
	 */
	mallopt(M_MMAP_THRESHOLD, 512 * 1024);
}