コード例 #1
0
ファイル: idt_core.c プロジェクト: Cai900205/test
int idt_dev_open(int i2c_bus, int i2c_addr)
{
    char i2c_dev[32];
    int fd = -1;
    int ret;

    sprintf(i2c_dev, "/dev/i2c-%d", i2c_bus);
    fd = open(i2c_dev, O_RDWR);
    if (fd < 0) {
        return(fd);
    }

    ret = ioctl(fd, I2C_TENBIT, 0);
    if (ret < 0) {
        goto errout;
    }
    ret = ioctl(fd, I2C_SLAVE, i2c_addr);
    if (ret < 0) {
        goto errout;
    }

    idt_dev_info_t info;
    idt_dev_get_info(fd, &info);
    zlog_notice(idt_zc, "vendor_id = 0x%04x", info.vendor_id);
    zlog_notice(idt_zc, "device_id = 0x%04x", info.dev_id);
    zlog_notice(idt_zc, "revision  = %d.%c", info.major, info.minor + 'A');

    return(fd);

errout:
    if (fd > 0) {
        close(fd);
    }
    return(ret);
}
コード例 #2
0
ファイル: dfv_repo.c プロジェクト: Cai900205/test
ssize_t dfv_repo_get_diskcap(struct dfv_repo* repo)
{
    ssize_t dc = -1;
    
    assert(repo);

    struct statfs sfs;
#if 1
    int i;
    char pathname[SPK_MAX_PATHNAME];
    dc =0;
    char mnt_path[SPK_MAX_PATHNAME];
    strcpy(mnt_path, repo->mnt_path);
    for(i=0; i<repo->dev_num; i++) {
        sprintf(pathname, "/%s/%s/%s", DFV_PREFIX_PATH, mnt_path, DFV_POSTFIX_PATH);
        if(!statfs(pathname, &sfs)) {
            dc += sfs.f_blocks*sfs.f_bsize;
        }
        zlog_notice(dfv_zc, "diskcap: id=%d, pathname=%s, dc=%ld",
                 repo->repo_id, pathname, dc);
        mnt_path[2]++;
    }
#else
    if(!statfs(repo->root_path, &sfs)) {
        dc = sfs.f_blocks*sfs.f_bsize;
    }

#endif
    zlog_notice(dfv_zc, "diskcap: id=%d, root=%s, dc=%ld",
                 repo->repo_id, repo->root_path, dc);
    return (dc);
}
コード例 #3
0
ファイル: pim_zebra.c プロジェクト: Distrotech/quagga
void pim_zebra_init (struct thread_master *master, char *zebra_sock_path)
{
  int i;

  if (zebra_sock_path)
    zclient_serv_path_set(zebra_sock_path);

#ifdef HAVE_TCP_ZEBRA
  zlog_notice("zclient update contacting ZEBRA daemon at socket TCP %s,%d", "127.0.0.1", ZEBRA_PORT);
#else
  zlog_notice("zclient update contacting ZEBRA daemon at socket UNIX %s", zclient_serv_path_get());
#endif

  /* Socket for receiving updates from Zebra daemon */
  qpim_zclient_update = zclient_new (master);

  qpim_zclient_update->zebra_connected          = pim_zebra_connected;
  qpim_zclient_update->router_id_update         = pim_router_id_update_zebra;
  qpim_zclient_update->interface_add            = pim_zebra_if_add;
  qpim_zclient_update->interface_delete         = pim_zebra_if_del;
  qpim_zclient_update->interface_up             = pim_zebra_if_state_up;
  qpim_zclient_update->interface_down           = pim_zebra_if_state_down;
  qpim_zclient_update->interface_address_add    = pim_zebra_if_address_add;
  qpim_zclient_update->interface_address_delete = pim_zebra_if_address_del;
  qpim_zclient_update->ipv4_route_add           = redist_read_ipv4_route;
  qpim_zclient_update->ipv4_route_delete        = redist_read_ipv4_route;

  zclient_init(qpim_zclient_update, ZEBRA_ROUTE_PIM);
  if (PIM_DEBUG_PIM_TRACE) {
    zlog_info("zclient_init cleared redistribution request");
  }

  zassert(qpim_zclient_update->redist_default == ZEBRA_ROUTE_PIM);

  /* Request all redistribution */
  for (i = 0; i < ZEBRA_ROUTE_MAX; i++) {
    if (i == qpim_zclient_update->redist_default)
      continue;
    vrf_bitmap_set(qpim_zclient_update->redist[i], VRF_DEFAULT);
    if (PIM_DEBUG_PIM_TRACE) {
      zlog_debug("%s: requesting redistribution for %s (%i)", 
		 __PRETTY_FUNCTION__, zebra_route_string(i), i);
    }
  }

  /* Request default information */
  vrf_bitmap_set(qpim_zclient_update->default_information, VRF_DEFAULT);
  if (PIM_DEBUG_PIM_TRACE) {
    zlog_info("%s: requesting default information redistribution",
	      __PRETTY_FUNCTION__);

    zlog_notice("%s: zclient update socket initialized",
		__PRETTY_FUNCTION__);
  }

  zassert(!qpim_zclient_lookup);
  qpim_zclient_lookup = zclient_lookup_new();
  zassert(qpim_zclient_lookup);
}
コード例 #4
0
ファイル: ips_core.c プロジェクト: Cai900205/test
int ips_module_init(const char* log_cat)
{
    int i;
    int ret;

    if (ips_zc) {
        fprintf(stderr, "%s: already initialized!\n", __func__);
        return(SPKERR_BADSEQ);
    }
    ips_zc = zlog_get_category(log_cat?log_cat:"IPS");
    if (!ips_zc) {
        fprintf(stderr, "%s: failed to initialize log system!\n", __func__);
//        return(SPKERR_LOGSYS);
    }

    assert(!ips_sriodev);

    for (i = 0; i < IPS_MAX_PORTS_IN_DEV; i++) {
        ips_epctx_tbl[i] = NULL;
    }

    pthread_mutex_init(&ips_dma_ch_lock, NULL);
    pthread_mutex_init(&ips_zlog_lock, NULL);

    of_init();
    ret = fsl_srio_uio_init(&ips_sriodev);
    IPS_LOGINFO(IPS_EPID_UNKNOWN, "fsl_srio_uio_init: ret=%d", ret);
    if (ret) {
        return(SPKERR_EAGAIN);
    }

    zlog_notice(ips_zc, "module initialized.");

    return(SPK_SUCCESS);
}
コード例 #5
0
ファイル: sigevent.c プロジェクト: kkcloudy/daemongroup
void
signal_init (struct thread_master *m, int sigc,
             struct quagga_signal_t signals[])
{

    int i = 0;
    struct quagga_signal_t *sig;

    /* First establish some default handlers that can be overridden by
       the application. */
    trap_default_signals();

    while (i < sigc)
    {
        sig = &signals[i];
        if ( signal_set (sig->signal) < 0 ) {
            zlog_notice("signal_init exit(-1)\n");
            EXIT(-1);

        }
        i++;
    }

    sigmaster.sigc = sigc;
    sigmaster.signals = signals;

#ifdef SIGEVENT_SCHEDULE_THREAD
    sigmaster.t =
        thread_add_timer (m, quagga_signal_timer, &sigmaster,
                          QUAGGA_SIGNAL_TIMER_INTERVAL);
#endif /* SIGEVENT_SCHEDULE_THREAD */
}
コード例 #6
0
ファイル: idt_core.c プロジェクト: Cai900205/test
int idt_port_recovery(int fd, PORT_ID port)
{

    idt_reg_w32(fd, IDTR_PORTn_ERR_RATE_EN_CSR(port), 0); // disable all
    idt_reg_w32(fd, IDTR_PORTn_ERR_RATE_THRESH_CSR(port), 0); // disable all trigger

    for(int i=0; i<4; i++) {
        idt_reg_w32(fd, IDTR_LANEn_ERR_RATE_EN(port*4+i), 0); // disable all
    }

    // PWIDTH_OVRD:0b110 (disable 2xmode) | INPUT_PORT_EN:1
    idt_reg_w32(fd, IDTR_PORTn_CTL_1_CSR(port), 0xd6600001);
    // CLR:1
    idt_reg_w32(fd, IDTR_PORTn_LOCAL_ACKID_CSR(port), 0x80000000);
    // CMD: 0b011 (Reset Device)
    idt_reg_w32(fd, IDTR_PORTn_LINK_MAINT_REQ_CSR(port), 0x00000003);

    while(!(idt_reg_r32(fd, IDTR_PORTn_LINK_MAINT_RESP_CSR(port)) &
            0x80000000/* VALID*/)) {
        usleep(100);
    }

    // DO_RESET: 1
    idt_reg_w32(fd, IDTR_DEVICE_RESET_CTL, (0x80000000 | (0x1<<port)));
    // CMD: 0b100 (Input Status)
    idt_reg_w32(fd, IDTR_PORTn_LINK_MAINT_REQ_CSR(port), 0x00000004);

    zlog_notice(idt_zc, "port recovery done: port_id=%u", port);

    return 0;
}
コード例 #7
0
ファイル: cmi_core.c プロジェクト: Cai900205/test
cmi_intf_t* cmi_intf_open(cmi_type type,
                          cmi_intf_type intf_type,
                          cmi_endian endian_req)
{
    cmi_intf_t* cmi_intf = NULL;

    assert(intf_type == cmi_intf_tcp ||
           intf_type == cmi_intf_udp);
    // only server can use auto endian
    assert(!((endian_req == cmi_endian_auto) && (type != cmi_type_server)));

    zlog_notice(cmi_zc, "open cmi intf: type=%s, intf_type=%s, endian=%s",
                        cmi_desc_type2str(type),
                        cmi_desc_intftype2str(intf_type),
                        cmi_desc_endian2str(endian_req));
    cmi_intf = malloc(sizeof(cmi_intf_t));
    assert(cmi_intf);
    memset(cmi_intf, 0, sizeof(cmi_intf_t));

    cmi_intf->type = type;
    cmi_intf->intf_type = intf_type;
    cmi_intf->endian_req = endian_req;
    pthread_mutex_init(&cmi_intf->conn_lock, NULL);

    return (cmi_intf);
}
コード例 #8
0
ファイル: idt_core.c プロジェクト: Cai900205/test
int idt_routetbl_set(int fd, PORT_ID src_port, DEV_ID dst_id, PORT_ID dst_port)
{
    uint32_t regaddr = IDTR_PORTn_DEV_RTE_TABLE(src_port, dst_id);

    zlog_notice(idt_zc, "route_tbl: set entry [%d] 0x%02x -> [%d]", src_port, dst_id, dst_port);

    return (idt_reg_w32(fd, regaddr, dst_port));
}
コード例 #9
0
ファイル: cmi_core.c プロジェクト: Cai900205/test
void cmi_intf_close(cmi_intf_t* intf)
{
    cmi_intf_disconnect(intf);
    SAFE_RELEASE(intf);

    zlog_notice(cmi_zc, "cmi interface closed");
    return;
}
コード例 #10
0
ファイル: syslk.c プロジェクト: Cai900205/test
void sys_change_state(int new_state)
{
    if (sys_ctx.sys_state != new_state) {
        zlog_notice(sys_zc, "*** change state: %s -> %s",
                    cmi_desc_sysstate2str(sys_ctx.sys_state),
                    cmi_desc_sysstate2str(new_state));
        sys_ctx.sys_state = new_state;
    }
}
/* Schedule connection for now. */
static void zclient_lookup_sched_now(struct zclient *zlookup)
{
  zassert(!zlookup->t_connect);

  zlookup->t_connect = thread_add_event(master, zclient_lookup_connect,
					zlookup, 0);

  zlog_notice("%s: zclient lookup immediate connection scheduled",
	      __PRETTY_FUNCTION__);
}
/* Schedule connection with delay. */
static void zclient_lookup_sched(struct zclient *zlookup, int delay)
{
  zassert(!zlookup->t_connect);

  THREAD_TIMER_ON(master, zlookup->t_connect,
		  zclient_lookup_connect,
		  zlookup, delay);

  zlog_notice("%s: zclient lookup connection scheduled for %d seconds",
	      __PRETTY_FUNCTION__, delay);
}
コード例 #13
0
ファイル: syslk_cmd.c プロジェクト: Cai900205/test
static int sys_cmd_exec_synctime(cmi_cmd_t* cmd)
{
    uint64_t synctime = sys_lktm_to_systm(cmd->u.tm.lktime);
    struct tm* local_time = localtime((time_t*)&synctime);
    char tmstr[256];
    strftime(tmstr, sizeof(tmstr), "%Y/%m/%d-%H:%M:%S", local_time);
    zlog_notice(sys_zc, "synctime: %s", tmstr);

    sprintf(tmstr, "date %02d%02d%02d%02d%04d.%02d",
            local_time->tm_mon + 1,
            local_time->tm_mday,
            local_time->tm_hour,
            local_time->tm_min,
            local_time->tm_year + 1900,
            local_time->tm_sec);
    zlog_notice(sys_zc, tmstr);
    spk_os_exec(tmstr);

    return(SPK_SUCCESS);
}
コード例 #14
0
ファイル: syslk_cmd.c プロジェクト: Cai900205/test
void* __sys_wkr_autorec(void* args)
{
    zlog_notice(sys_zc, "autorec> spawn ...");

    while(sys_ctx.auto_rec) {
        if (sys_ctx.sys_state == sys_state_idle) {
            sys_cmd_exec_startrec(NULL);
        }
        usleep(100);
        int wkr_state = sys_state_idle;
        for (int i=0; i<SYS_MAX_PIPES; i++) {
            sys_wkr_ctx_t* wkr_ctx = sys_ctx.wkr_ctx_tbl[i];
            if (wkr_ctx && wkr_ctx->wkr_state != sys_state_idle) {
                wkr_state = wkr_ctx->wkr_state;
            }
        }
        sys_change_state(wkr_state);
    }
    zlog_notice(sys_zc, "autorec> terminated");
    return(NULL);
}
コード例 #15
0
ファイル: sibling_ctrl.c プロジェクト: ecks/harry
int recv_features_reply(struct ctrl_client * ctrl_client, struct rfpbuf * buffer)
{
  struct rfp_router_features * rrf = buffer->data;
  struct interface * ifp;
  int i;
  unsigned int ifindex;
  unsigned int mtu;
  int offset = offsetof(struct rfp_router_features, ports);
  size_t n_ports = ((ntohs(rrf->header.length)
                                     - offset)
                        / sizeof(*rrf->ports));
  if(IS_OSPF6_SIBLING_DEBUG_MSG)
  {
    zlog_notice("number of ports: %d", n_ports);
  }
  for(i = 0; i < n_ports; i++)
  {  
    const struct rfp_phy_port * rpp = &rrf->ports[i];
    ifindex = ntohs(rpp->port_no);
    mtu = ntohl(rpp->mtu);
    if(IS_OSPF6_SIBLING_DEBUG_MSG)
    {
      zlog_notice("port #: %d, name: %s, mtu: %d", ifindex, rpp->name, mtu);
    }
    /* create new interface if not created */
    ifp = if_get_by_name(ctrl_client->if_list, rpp->name);

    // fill up the interface info
    ifp->ifindex = ifindex;

    // fill up the mtu
    ifp->mtu = mtu;
    // copy over the flags
    ifp->state = ntohl(rpp->state);
    ospf6_interface_if_add(ifp, ctrl_client);
  }

  return 0;
}
コード例 #16
0
ファイル: main.c プロジェクト: junpei-yoshino/quagga
/* SIGINT handler. */
static void
sigint (void)
{
  zlog_notice ("Terminating on signal");

  if (!retain_mode)
    rib_close ();
#ifdef HAVE_IRDP
  irdp_finish();
#endif

  exit (0);
}
コード例 #17
0
ファイル: syslk_job.c プロジェクト: Cai900205/test
static int __sys_job_do_config(sys_wkr_ctx_t* wkr_ctx,
                               IPS_EPID src_id, int pc_id, char* config_buf, size_t buf_sz)
{
    int ret = -1;
#ifdef ARCH_ppc64
    struct ips_pcctx* pcctx = NULL;
    int wkr_id = wkr_ctx->wkr_id;

    zlog_notice(sys_zc, "wkr#%d> prepare for config: ips={0x%x:%d}, config={0x%08x}+%lu",
                        wkr_id, src_id, pc_id,
                        *(uint32_t*)config_buf, buf_sz);


    // open ips srio
    pcctx = ips_chan_open(src_id, pc_id);
    if (!pcctx) {
        zlog_fatal(sys_zc, "wkr#%d> failed to open ips channel", wkr_id);
        ret = SPKERR_EACCESS;
        goto out;
    }

    zlog_notice(sys_zc, "wkr#%d> ---------- start config ----------", wkr_id);
    char *out_buf = NULL;
    size_t out_sz = 0;
    ret = ips_chan_config(pcctx, config_buf, buf_sz, &out_buf, &out_sz);
    memcpy(&sys_fpga_stat[wkr_id], (out_buf+8), sizeof(sys_fpga_stat[wkr_id]));
    free(out_buf);
out:
    zlog_notice(sys_zc, "wkr#%d> ---------- stop config ---------- ret=%d", wkr_id, ret);

    // close ips srio
    if (pcctx) {
        ips_chan_close(pcctx);
        pcctx = NULL;
    }
#endif
    return(ret);
}
コード例 #18
0
ファイル: zserv.c プロジェクト: MichaelQQ/Quagga-PE
/* If client sent routes of specific type, zebra removes it
 * and returns number of deleted routes.
 */
static void
zebra_score_rib (int client_sock)
{
  int i;

  for (i = ZEBRA_ROUTE_RIP; i < ZEBRA_ROUTE_MAX; i++)
    if (client_sock == route_type_oaths[i])
      {
        zlog_notice ("client %d disconnected. %lu %s routes removed from the rib",
                      client_sock, rib_score_proto (i), zebra_route_string (i));
        route_type_oaths[i] = 0;
        break;
      }
}
コード例 #19
0
ファイル: dfv_repo.c プロジェクト: Cai900205/test
int dfv_repo_sync(dfv_repo_t* repo)
{
    int fix_count = 0;

    for (int i=0; i<DFV_MAX_SLOTS; i++) {
        dfv_fmeta_t* fmeta = dfv_fmeta_get(repo, i);
        if (!fmeta) {
            struct stat statbuff;
            char pathname[SPK_MAX_PATHNAME];
            sprintf(pathname, "%s/%d/", repo->root_path, i);
            if(stat(pathname, &statbuff) >= 0){
                // file exists but meta not found
                zlog_warn(dfv_zc, "sync: slot exists while meta is NULL:"
                                    "root=%s, slot=%d",
                                     repo->root_path, i);
                char pathname[SPK_MAX_PATHNAME];
                sprintf(pathname, "rm %s/%d -Rf", repo->root_path, i);
                spk_os_exec(pathname);
                fix_count++;
            }
        } else {
            ssize_t slot_sz = dfv_repo_get_slotsize(repo, i);
            if (slot_sz < 0) {
                // meta exists while slot is empty
                // delete fmeta
                zlog_warn(dfv_zc, "sync: meta exists while slot is empty:"
                                    "root=%s, slot=%d",
                                     repo->root_path, i);
                repo->rmeta.fmeta_tbl[i] = NULL;
                SAFE_RELEASE(fmeta);
                fix_count++;
            } else {
                // size mismatch
                if (fmeta->slot_sz != slot_sz) {
                    zlog_warn(dfv_zc, "sync: slot file mismatch:"
                                        "root=%s, slot=%d",
                                         repo->root_path, i);
                    fmeta->slot_sz = slot_sz;
                    fix_count++;
                }
            }
        }
    }
 
    dfv_rmeta_save(&repo->rmeta, repo->meta_path);
    zlog_notice(dfv_zc, "repo fixed: id=%d, root=%s, fix_count=%d",
                 repo->repo_id, repo->root_path, fix_count);

    return(fix_count);   
}
コード例 #20
0
ファイル: ospf_nsm.c プロジェクト: AsherBond/quagga
static void
nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event)
{
  /* Logging change of status. */
  if (IS_DEBUG_OSPF (nsm, NSM_STATUS))
    zlog_debug ("NSM[%s:%s]: State change %s -> %s (%s)",
               IF_NAME (nbr->oi), inet_ntoa (nbr->router_id),
               LOOKUP (ospf_nsm_state_msg, nbr->state),
               LOOKUP (ospf_nsm_state_msg, next_state),
               ospf_nsm_event_str [event]);

  /* Optionally notify about adjacency changes */
  if (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_CHANGES) &&
      (CHECK_FLAG(nbr->oi->ospf->config, OSPF_LOG_ADJACENCY_DETAIL) ||
       (next_state == NSM_Full) || (next_state < nbr->state)))
    zlog_notice("AdjChg: Nbr %s on %s: %s -> %s (%s)",
                inet_ntoa (nbr->router_id), IF_NAME (nbr->oi),
                LOOKUP (ospf_nsm_state_msg, nbr->state),
                LOOKUP (ospf_nsm_state_msg, next_state),
                ospf_nsm_event_str [event]);

  /* Advance in NSM */
  if (next_state > nbr->state)
    nbr->ts_last_progress = recent_relative_time ();
  else /* regression in NSM */
    {
      nbr->ts_last_regress = recent_relative_time ();
      nbr->last_regress_str = ospf_nsm_event_str [event];
    }

#ifdef HAVE_SNMP
  /* Terminal state or regression */ 
  if ((next_state == NSM_Full) 
      || (next_state == NSM_TwoWay)
      || (next_state < nbr->state))
    {
      /* ospfVirtNbrStateChange */
      if (nbr->oi->type == OSPF_IFTYPE_VIRTUALLINK)
        ospfTrapVirtNbrStateChange(nbr);
      /* ospfNbrStateChange trap  */
      else	
        /* To/From FULL, only managed by DR */
        if (((next_state != NSM_Full) && (nbr->state != NSM_Full)) 
            || (nbr->oi->state == ISM_DR))
          ospfTrapNbrStateChange(nbr);
    }
#endif
}
コード例 #21
0
ファイル: main.c プロジェクト: OPSF/uClinux
/* SIGINT handler. */
void
sigint (void)
{
  /* Decrared in rib.c */
  void rib_close ();

  zlog_notice ("Terminating on signal");

  if (!retain_mode)
    rib_close ();
#ifdef HAVE_IRDP
  irdp_finish();
#endif

  exit (0);
}
コード例 #22
0
ファイル: net_core.c プロジェクト: Cai900205/test
int net_module_init(const char* log_cat)
{
    if (net_zc) {
        fprintf(stderr, "%s: already initialized!\n", __func__);
        return(SPKERR_BADSEQ);
    }

    net_zc = zlog_get_category(log_cat?log_cat:"NET");
    if (!net_zc) {
        fprintf(stderr, "%s: failed to initialize log system!\n", __func__);
        return(SPKERR_LOGSYS);
    }
    zlog_notice(net_zc, "module initialized.");

    return(SPK_SUCCESS);
}
コード例 #23
0
ファイル: cmi_core.c プロジェクト: Cai900205/test
void cmi_intf_disconnect(cmi_intf_t* intf)
{
    if (intf->conn_valid) {
        pthread_mutex_lock(&intf->conn_lock);
        if (intf->conn_sockfd > 0) {
            close(intf->conn_sockfd);
            intf->conn_sockfd = -1;
        }
        if (intf->sock_svr > 0) {
            close(intf->sock_svr);
            intf->sock_svr = -1;
        }
        intf->conn_valid = 0;
        pthread_mutex_unlock(&intf->conn_lock);
        zlog_notice(cmi_zc, "cmi interface disconnected");
    }
}
コード例 #24
0
ファイル: idt_core.c プロジェクト: Cai900205/test
int idt_module_init(const char* log_cat)
{
    if (idt_zc) {
        fprintf(stderr, "%s: already initialized!\n", __func__);
        return(SPKERR_BADSEQ);
    }

    idt_zc = zlog_get_category(log_cat?log_cat:"IDT");
    if (!idt_zc) {
        fprintf(stderr, "%s: failed to initialize log system!\n", __func__);
//        return(SPKERR_LOGSYS);
    }

    pthread_mutex_init(&idt_i2c_lock, NULL);

    zlog_notice(idt_zc, "module initialized.");

    return(SPK_SUCCESS);
}
コード例 #25
0
ファイル: cmi_core.c プロジェクト: Cai900205/test
int cmi_module_init(const char* log_cat)
{
    if (cmi_zc) {
        fprintf(stderr, "%s: already initialized!\n", __func__);
        return(SPKERR_BADSEQ);
    }

    cmi_zc = zlog_get_category(log_cat?log_cat:"CMI");
    if (!cmi_zc) {
        fprintf(stderr, "%s: failed to initialize log system!\n", __func__);
        return(SPKERR_LOGSYS);
    }

    pthread_mutex_init(&cmi_data_tag_lock, NULL);

    zlog_notice(cmi_zc, "module initialized.");

    signal(SIGPIPE, SIG_IGN);
    return(SPK_SUCCESS);
}
コード例 #26
0
ファイル: dfv_repo.c プロジェクト: Cai900205/test
dfv_repo_t* dfv_repo_open(int repo_id, const char* mnt_path, const char* dev_path, int flag)
{
    struct stat info;
    int ret;
    char root_path[SPK_MAX_PATHNAME];
    
    sprintf(root_path, "/%s/%s/%s", DFV_PREFIX_PATH, mnt_path, DFV_POSTFIX_PATH);
    ret = stat(root_path, &info);
    if (ret) {
        // root path not exist
        zlog_fatal(dfv_zc, "root_path not found: path=%s", root_path);
        return NULL;
    } 
   
    dfv_repo_t* repo = malloc(sizeof(dfv_repo_t));
    assert(repo);
    memset(repo, 0, sizeof(dfv_repo_t));

    repo->repo_id = repo_id;
    strcpy(repo->root_path, root_path);
    strcpy(repo->mnt_path, mnt_path);
    if (dev_path) {
        strcpy(repo->dev_path, dev_path);
    }
    sprintf(repo->meta_path, "%s/.meta", root_path);

    ret = dfv_rmeta_load(&repo->rmeta, repo->meta_path);
    if (ret < 0) {
        zlog_warn(dfv_zc, "failed to load rmeta: path=%s, ret=%d",
                     repo->meta_path, ret);
        dfv_rmeta_reset(&repo->rmeta);
        dfv_rmeta_save(&repo->rmeta, repo->meta_path);
    }

    zlog_notice(dfv_zc, "repo opened: id=%d, path=%s",
                         repo_id, repo->root_path);
    dfv_rmeta_dump(ZLOG_LEVEL_NOTICE, &repo->rmeta);

    return(repo);
}
コード例 #27
0
ファイル: svz_sisis.c プロジェクト: ecks/sis-is
int
shim_sisis_accept(struct thread * thread)
{
  int accept_sock;
  int sisis_sock;
  struct sisis_listener *listener;
  union sockunion su;
  char buf[SU_ADDRSTRLEN];

  accept_sock = THREAD_FD (thread);
  if (accept_sock < 0)
  {
    zlog_err ("accept_sock is negative value %d", accept_sock);
    return -1;
  }
  thread_add_read (master, shim_sisis_accept, NULL, accept_sock);

  sisis_sock = sockunion_accept(accept_sock, &su);

  if (sisis_sock < 0)
  {
    zlog_err ("[Error] SISIS socket accept failed (%s)", safe_strerror (errno));
    return -1;
  }

  zlog_notice ("SISIS connection from host %s", inet_sutop (&su, buf));
 
  listener = XMALLOC (MTYPE_SHIM_SISIS_LISTENER, sizeof(*listener));
  listener->fd = accept_sock;
  listener->ibuf = stream_new (SV_HEADER_SIZE + 1500);
//  memcpy(&listener->su, sa, salen);
  listener->sisis_fd = sisis_sock;
  listener->dif = stream_fifo_new();
  listener->chksum_stream = stream_new(4 * 20); // need to figure out good size for buffering
  listener->read_thread = thread_add_read (master, shim_sisis_read, listener, sisis_sock);
  listnode_add (sm->listen_sockets, listener);

  return 0;
}
コード例 #28
0
ファイル: dfv_repo.c プロジェクト: Cai900205/test
int dfv_repo_delete(struct dfv_repo* repo, int slot_id)
{
    dfv_fmeta_t* fmeta = dfv_fmeta_get(repo, slot_id);
    dfv_rmeta_t* rmeta = dfv_rmeta_get(repo);
    if (!fmeta) {
        return(SPKERR_EACCESS);
    }
    
    pthread_mutex_lock(&fmeta->open_cnt_lock);
    if (fmeta->open_cnt > 0) {
        zlog_error(dfv_zc, "file busy: id=%d, slot=%d, open_cnt=%d",
                            repo->repo_id, slot_id, fmeta->open_cnt);
        pthread_mutex_unlock(&fmeta->open_cnt_lock);
        return(SPKERR_EAGAIN);
    }
    char pathname[SPK_MAX_PATHNAME];
#if 1
    int i;

    char mnt_path[SPK_MAX_PATHNAME];
    strcpy(mnt_path, repo->mnt_path);
    for (i=0; i<fmeta->slice_num; i++) {
        sprintf(pathname, " rm /%s/%s/%s/%d -Rf", DFV_PREFIX_PATH, mnt_path, DFV_POSTFIX_PATH, slot_id);
        spk_os_exec(pathname);
        mnt_path[2]++;
    }
#else
    sprintf(pathname, "rm %s/%d -Rf", repo->root_path, slot_id);
    spk_os_exec(pathname);
    
#endif
    rmeta->fmeta_tbl[slot_id] = NULL;

    pthread_mutex_unlock(&fmeta->open_cnt_lock);
    SAFE_RELEASE(fmeta);
    
    zlog_notice(dfv_zc, "file deleted: id=%d, slot=%d", repo->repo_id, slot_id);
    return(SPK_SUCCESS);
}
コード例 #29
0
ファイル: syslk_job.c プロジェクト: Cai900205/test
static int __sys_job_do_download(sys_wkr_ctx_t* wkr_ctx,
                                 int slot_id,
                                 uint32_t req_frag,
                                 uint64_t blk_start,
                                 uint64_t blk_num)
{
    int wkr_id = wkr_ctx->wkr_id;

    int ret = -1;
    uint32_t frag_id = 0;
    int is_eof = 0;

    do {
        // cache if necessary
        ret = sys_func_dl_prepare(slot_id,
                                  blk_start,
                                  blk_num,
                                  frag_id);

        if (ret != SPK_SUCCESS) {
            break;
        }
        if (wkr_ctx->reset_req) {
            // download aborted
            is_eof = 0x02;
        }
        ret = sys_func_dl_sendfrag(slot_id, blk_start,
                                   blk_num, frag_id, &is_eof);
        if (ret != SPK_SUCCESS) {
            break;
        }
        frag_id++;
    } while(!is_eof);

    zlog_notice(sys_zc, "wkr#%d> download done: eof=%d", wkr_id, is_eof);

    return(ret);
}
コード例 #30
0
ファイル: dfv_repo.c プロジェクト: Cai900205/test
int dfv_repo_format_common(dfv_repo_t* repo)
{
    char cmd[SPK_MAX_PATHNAME];
#if 0
    int ret;
    
    assert(repo);

    sprintf(cmd, "rm %s -Rf", repo->root_path);
    ret = spk_os_exec(cmd);
    
    ret = mkdir(repo->root_path, 0666);
    if (ret) {
        zlog_error(dfv_zc, "failed to create repo dir: path=%s, errmsg=\'%s\'\n",
                        repo->root_path, strerror(errno));
        return(SPKERR_BADRES);
    }

#else
    int i;

    char mnt_path[SPK_MAX_PATHNAME];
    strcpy(mnt_path, repo->mnt_path);
    for (i=0; i<repo->dev_num; i++) {
        sprintf(cmd, "rm /%s/%s/%s/* -Rf", DFV_PREFIX_PATH, mnt_path, DFV_POSTFIX_PATH);
      //  sprintf(cmd, "rm %s/"DFV_SLICE_FILEPATH"/*  -Rf", repo->root_path, i+1);
        mnt_path[2]++;
        spk_os_exec(cmd);
    }
#endif
    dfv_rmeta_reset(&repo->rmeta);
    dfv_rmeta_save(&repo->rmeta, repo->meta_path);

    zlog_notice(dfv_zc, "repo formatted (common): id=%d, root=%s",
                         repo->repo_id, repo->root_path);
    
    return(SPK_SUCCESS);
}