static int add_entry(struct sockaddr_atmpvc *from,struct sockaddr_atmpvc *to) { LINK *l_from,*l_to; TABLE *entry; l_from = find_link(from->sap_addr.itf); l_to = find_link(to->sap_addr.itf); if (!l_from || !l_to) return -ENODEV; for (entry = l_from->table; entry; entry = entry->next) if (entry->in_vpi == from->sap_addr.vpi && (entry->in_vci == ATM_VCI_UNSPEC || from->sap_addr.vci == ATM_VCI_UNSPEC || entry->in_vci == from->sap_addr.vci)) return -EEXIST; entry = alloc_t(TABLE); entry->out = l_to; entry->in_vpi = from->sap_addr.vpi; entry->in_vci = from->sap_addr.vci; entry->out_vpi = to->sap_addr.vpi; entry->out_vci = to->sap_addr.vci; entry->next = l_from->table; l_from->table = entry; if (entry->in_vci == ATM_VCI_UNSPEC) diag(COMPONENT,DIAG_INFO,"added VP %d.%d -> %d.%d",l_from->id, entry->in_vpi,l_to->id,entry->out_vpi); else diag(COMPONENT,DIAG_INFO,"added VC %d.%d.%d -> %d.%d.%d",l_from->id, entry->in_vpi,entry->in_vci,l_to->id,entry->out_vpi,entry->out_vci); return 0; }
static int del_entry(struct sockaddr_atmpvc *from,struct sockaddr_atmpvc *to) { LINK *l_from,*l_to; TABLE **entry,*this; l_from = find_link(from->sap_addr.itf); l_to = find_link(to->sap_addr.itf); if (!l_from || !l_to) return -ENODEV; for (entry = &l_from->table; *entry; entry = &(*entry)->next) if ((*entry)->out == l_to && (*entry)->in_vpi == from->sap_addr.vpi && (*entry)->in_vci == from->sap_addr.vci && ((*entry)->in_vci == ATM_VCI_UNSPEC || (*entry)->out_vci == to->sap_addr.vci)) break; if (!*entry) return -EHOSTUNREACH; this = *entry; *entry = this->next; if (this->in_vci == ATM_VCI_UNSPEC) diag(COMPONENT,DIAG_INFO,"deleted VP %d.%d -> %d.%d",l_from->id, this->in_vpi,l_to->id,this->out_vpi); else diag(COMPONENT,DIAG_INFO,"deleted VC %d.%d.%d -> %d.%d.%d",l_from->id, this->in_vpi,this->in_vci,l_to->id,this->out_vpi,this->out_vci); free(this); return 0; }
/* * According to devfs path name, it will print device node name. */ static void print_node_name(char *drv_name, char *strdevfspath) { di_node_t curnode; char *devfspath = NULL; char *node_name = NULL; curnode = di_drv_first_node(drv_name, devinfo_root); for (; curnode != DI_NODE_NIL; curnode = di_drv_next_node(curnode)) { devfspath = di_devfs_path(curnode); logmsg(MSG_INFO, "find: devfspath %s\n", devfspath); if (devfspath == NULL) continue; if ((strlen(strdevfspath) == strlen(devfspath)) && (strncmp(strdevfspath, devfspath, strlen(devfspath)) == 0)) { node_name = find_link(curnode); if (node_name == NULL) { (void) printf("NOT MAPPED\n"); } else { (void) printf("%s\n", node_name); } return; } } }
void loadlinkdb() { char master[NICKLEN+1]; char slave[NICKLEN+1]; MYSQL_RES *result; MYSQL_ROW row; if (!reconnect_to_db()) { fprintf(stderr,"Cannot connect to db\n"); operlog("Cannot connect to db"); return; } mysql_query(&mysql,"SELECT * FROM child_links"); if ((result = mysql_use_result(&mysql)) == NULL) { printf("CRITICAL: Cannot load link table: mysql_use_result returned NULL\n"); return; } while ((row = mysql_fetch_row(result))) { strncpy(master,row[0],NICKLEN); strncpy(slave,row[1],NICKLEN); if (find_link(slave) || find_link2(master,slave)) continue; AddLink(master,slave); if (vv) printf("Link added with master %s and slave %s\n",master,slave); } mysql_close(&mysql); }
struct node *handle_IIA (int index, struct node **tree, struct node *u) // Handle the case in which the suffix link of node u is UNKNOWN, and u's parent is not root. { struct node *up = u -> parent; // B = input_string [u->starti : u->endi] return find_link (index, up, u, u -> starti, u -> endi); }
char *hostlink_filename(char *hostname) { link_t *link; if (!linksloaded) load_all_links(); link = find_link(hostname); return (link ? link->filename : NULL); }
void handle_ack(int link, FRAME f){ //printf("handle ack called for mesg #%d\n", p.mesg_seq_no); if(f.payload.dest == nodeinfo.address && f.payload.mesg_seq_no == links[link].msg_in_sender_Q) links[link].ack_received[f.payload.A] = true; if(f.payload.dest != nodeinfo.address){ int forwarding_link = find_link(f.payload.dest); f.checksum = 0; f.checksum = CNET_ccitt((unsigned char *)&f, FRAME_HEADER_SIZE); queue_add(links[forwarding_link].ack_sender, &f, FRAME_HEADER_SIZE); schedule_and_send(forwarding_link); } }
void create_ack(PACKET p){ FRAME ack; ack.payload.kind = DL_ACK; ack.payload.dest = p.source; ack.payload.source = nodeinfo.address; ack.payload.A = p.A; ack.payload.len = FRAME_HEADER_SIZE; ack.payload.mesg_seq_no = p.mesg_seq_no; ack.checksum = 0; ack.checksum = CNET_ccitt((unsigned char *)&ack, (int)FRAME_HEADER_SIZE); int link = find_link(p.source); queue_add(links[link].ack_sender, &ack, FRAME_HEADER_SIZE); schedule_and_send(link); }
char *hostlink(char *hostname) { static char *linkurl = NULL; link_t *link; if (linkurl == NULL) linkurl = (char *)malloc(PATH_MAX); if (!linksloaded) load_all_links(); link = find_link(hostname); if (link) { sprintf(linkurl, "%s/%s", link->urlprefix, link->filename); return linkurl; } return NULL; }
void handle_data(int link, FRAME f, size_t len){ // If packet is sent to this node, accept it, reconstruct the whole message and send it to the application layer //printf("handle data called for message #%d\n", f.payload.mesg_seq_no); if(f.payload.dest == nodeinfo.address){ queue_add(receiver, &f, len); process_frames(); } // Else forward it according to the routing information that we have, this node will act as a router else{ //printf("Processing forward to %d from %d via %d\n", f.payload.dest, f.payload.source, nodeinfo.address); int forwarding_link = find_link(f.payload.dest); f.checksum = 0; f.checksum = CNET_ccitt((unsigned char *)&f, (int)(f.payload.len) + FRAME_HEADER_SIZE); queue_add(links[forwarding_link].forwarding_queue, &f, len); //will have to schedule with sender queue schedule_and_send(forwarding_link); } }
char *columnlink(char *colname) { static char *linkurl = NULL; link_t *link; if (linkurl == NULL) linkurl = (char *)malloc(PATH_MAX); if (!linksloaded) load_all_links(); link = find_link(colname); if (link) { sprintf(linkurl, "%s/%s", link->urlprefix, link->filename); } else if (columndocurl) { sprintf(linkurl, columndocurl, colname); } else { *linkurl = '\0'; } return linkurl; }
static int check_ci(struct sockaddr_atmpvc *pvc) { LINK *lnk; TABLE *walk; int vci; lnk = find_link(pvc->sap_addr.itf); if (!lnk) return 0; if (pvc->sap_addr.vpi == ATM_VPI_ANY) pvc->sap_addr.vpi = 0; /* that was easy :-) */ for (walk = lnk->table; walk; walk = walk->next) if (walk->in_vpi == pvc->sap_addr.vpi) break; if (walk && walk->in_vci == ATM_VCI_UNSPEC) return 0; if (pvc->sap_addr.vci == ATM_VCI_UNSPEC) return !walk; if (pvc->sap_addr.vci != ATM_VCI_ANY) return !vci_exists(lnk,pvc->sap_addr.vpi,pvc->sap_addr.vci); for (vci = ATM_NOT_RSV_VCI; vci < MAX_VCI; vci++) if (!vci_exists(lnk,pvc->sap_addr.vpi,vci)) { pvc->sap_addr.vci = vci; return 1; } return 0; }
/* * routine: * do_copy * * purpose: * to propagate a creation or change * * parameters: * file pointer * src/dst indication for who gets the copy * * returns: * error mask * * note: * after any successful operation we update the stat/info * structure for the updated file. This is somewhat redundant * because we will restat at the end of the routine, but these * anticipatory updates help to ensure that the link finding * code will still behave properly in notouch mode (when restats * cannot be done). */ errmask_t do_copy(struct file *fp, side_t srcdst) { char *src, *dst; char cmdbuf[ MAX_PATH + MAX_NAME ]; int mode, maj, min, type; uid_t uid; gid_t gid; int rc; long mtime; int do_chmod = 0; int do_chown = 0; int do_chgrp = 0; int do_unlink = 0; int do_acls = 0; int do_create = 0; char *errstr = "???"; errmask_t errs = 0; struct base *bp; struct file *lp; struct fileinfo *sp, *dp; struct utimbuf newtimes; struct stat statb; bp = fp->f_base; /* see if this is a forbidden propagation */ if (srcdst == opt_oneway) { fp->f_problem = gettext(PROB_prohibited); fp->f_flags |= F_CONFLICT; bp->b_unresolved++; return (ERR_UNRESOLVED); } /* figure out who is the source and who is the destination */ if (srcdst == OPT_SRC) { sp = &fp->f_info[ OPT_DST ]; dp = &fp->f_info[ OPT_SRC ]; src = dstname; dst = srcname; } else { sp = &fp->f_info[ OPT_SRC ]; dp = &fp->f_info[ OPT_DST ]; src = srcname; dst = dstname; } /* note information about the file to be created */ type = sp->f_type; /* type of the new file */ uid = sp->f_uid; /* owner of the new file */ gid = sp->f_gid; /* group of the new file */ mode = sp->f_mode; /* modes for the new file */ mtime = sp->f_modtime; /* modtime (if preserving) */ maj = sp->f_rd_maj; /* major (if it is a device) */ min = sp->f_rd_min; /* minor (if it is a device) */ /* * creating a file does not guarantee it will get the desired * modes, uid and gid. If the file already exists, it will * retain its old ownership and protection. If my UID/GID * are not the desired ones, the new file will also require * manual correction. If the file has the wrong type, we will * need to delete it and recreate it. If the file is not writable, * it is easier to delete it than to chmod it to permit overwrite */ if ((dp->f_type == S_IFREG && sp->f_type == S_IFREG) && (dp->f_mode & 0200)) { /* if the file already exists */ if (dp->f_uid != uid) do_chown = 1; if (dp->f_gid != gid) do_chgrp = 1; if (dp->f_mode != mode) do_chmod = 1; } else { /* if we will be creating a new file */ do_create = 1; if (dp->f_type) do_unlink = 1; if (uid != my_uid) do_chown = 1; if (gid != my_gid) do_chgrp = 1; } /* * if the source has acls, we will surely have to set them for dest */ if (sp->f_numacls) do_acls = 1; /* * for any case other than replacing a normal file with a normal * file, we need to delete the existing file before creating * the new one. */ if (do_unlink) { if (dp->f_type == S_IFDIR) { if (!opt_quiet) fprintf(stdout, "rmdir %s\n", noblanks(dst)); errstr = gettext(PROB_rmdir); #ifdef DBG_ERRORS /* should we simulate a rmdir failure */ if (errno = dbg_chk_error(dst, 'D')) rc = -1; else #endif rc = opt_notouch ? 0 : rmdir(dst); } else { if (!opt_quiet) fprintf(stdout, "rm %s\n", noblanks(dst)); errstr = gettext(PROB_unlink); #ifdef DBG_ERRORS /* should we simulate a unlink failure */ if (errno = dbg_chk_error(dst, 'u')) rc = -1; else #endif rc = opt_notouch ? 0 : unlink(dst); } if (rc != 0) goto cant; /* note that this file no longer exists */ dp->f_type = 0; dp->f_mode = 0; } if (opt_debug & DBG_RECON) { fprintf(stderr, "RECO: do_copy %s %s (", src, dst); if (do_unlink) fprintf(stderr, "unlink "); if (do_chmod) fprintf(stderr, "chmod "); if (do_acls) fprintf(stderr, "acls "); if (do_chown) fprintf(stderr, "chown "); if (do_chgrp) fprintf(stderr, "chgrp "); fprintf(stderr, ")\n"); } /* * how we go about copying a file depends on what type of file * it is that we are supposed to copy */ switch (type) { case S_IFDIR: if (!opt_quiet) { fprintf(stdout, "mkdir %s;", noblanks(dst)); fprintf(stdout, " chmod %o %s;\n", mode, noblanks(dst)); } errstr = gettext(PROB_mkdir); #ifdef DBG_ERRORS /* should we simulate a mkdir failure */ if (errno = dbg_chk_error(dst, 'd')) rc = -1; else #endif rc = opt_notouch ? 0 : mkdir(dst, mode); /* update stat with what we have just created */ if (rc == 0) { dp->f_type = S_IFDIR; dp->f_uid = my_uid; dp->f_gid = my_gid; dp->f_mode = mode; } break; case S_IFLNK: errstr = gettext(PROB_readlink); #ifdef DBG_ERRORS /* should we simulate a symlink read failure */ if (errno = dbg_chk_error(dst, 'r')) rc = -1; else #endif rc = readlink(src, cmdbuf, sizeof (cmdbuf)); if (rc > 0) { cmdbuf[rc] = 0; if (!opt_quiet) { fprintf(stdout, "ln -s %s", noblanks(cmdbuf)); fprintf(stdout, " %s;\n", noblanks(dst)); } errstr = gettext(PROB_symlink); #ifdef DBG_ERRORS /* should we simulate a symlink failure */ if (errno = dbg_chk_error(dst, 'l')) rc = -1; else #endif rc = opt_notouch ? 0 : symlink(cmdbuf, dst); if (rc == 0) dp->f_type = S_IFLNK; } break; case S_IFBLK: case S_IFCHR: if (!opt_quiet) fprintf(stdout, "mknod %s %s %d %d\n", noblanks(dst), (type == S_IFBLK) ? "b" : "c", maj, min); errstr = gettext(PROB_mknod); #ifdef DBG_ERRORS /* should we simulate a mknod failure */ if (errno = dbg_chk_error(dst, 'd')) rc = -1; else #endif rc = opt_notouch ? 0 : mknod(dst, mode|type, makedev(maj, min)); /* update stat with what we have just created */ if (rc == 0) { dp->f_type = type; dp->f_uid = my_uid; dp->f_gid = my_gid; dp->f_mode = 0666; if (dp->f_mode != mode) do_chmod = 1; } break; case S_IFREG: /* * The first thing to do is ascertain whether or not * the alleged new copy might in fact be a new link. * We trust find_link to weigh all the various factors, * so if he says make a link, we'll do it. */ lp = find_link(fp, srcdst); if (lp) { /* figure out name of existing file */ src = full_name(lp, srcdst, OPT_BASE); /* * if file already exists, it must be deleted */ if (dp->f_type) { if (!opt_quiet) fprintf(stdout, "rm %s\n", noblanks(dst)); errstr = gettext(PROB_unlink); #ifdef DBG_ERRORS /* should we simulate a unlink failure */ if (errno = dbg_chk_error(dst, 'u')) rc = -1; else #endif rc = opt_notouch ? 0 : unlink(dst); /* * if we couldn't do the unlink, we must * mark the linkee in conflict as well * so his reference count remains the same * in the baseline and he continues to show * up on the change list. */ if (rc != 0) { lp->f_flags |= F_CONFLICT; lp->f_problem = gettext(PROB_link); goto cant; } } if (!opt_quiet) { fprintf(stdout, "ln %s", noblanks(src)); fprintf(stdout, " %s\n", noblanks(dst)); } errstr = gettext(PROB_link); #ifdef DBG_ERRORS /* should we simulate a link failure */ if (errno = dbg_chk_error(dst, 'l')) rc = -1; else #endif rc = opt_notouch ? 0 : link(src, dst); /* * if this is a link, there is no reason to worry * about ownership and modes, they are automatic */ do_chown = 0; do_chgrp = 0; do_chmod = 0; do_acls = 0; if (rc == 0) { dp->f_type = type; dp->f_uid = uid; dp->f_gid = gid; dp->f_mode = mode; break; } else { /* * if we failed to make a link, we want to * mark the linkee in conflict too, so that * his reference count remains the same in * the baseline, and he shows up on the change * list again next time. */ lp->f_flags |= F_CONFLICT; lp->f_problem = errstr; break; } /* * in some situation we haven't figured out yet * we might want to fall through and try a copy * if the link failed. */ } /* we are going to resolve this by making a copy */ if (!opt_quiet) { fprintf(stdout, "cp %s", noblanks(src)); fprintf(stdout, " %s\n", noblanks(dst)); } rc = opt_notouch ? 0 : copy(src, dst, mode); if (rc != 0) { errs |= rc; if (copy_err_str) errstr = copy_err_str; else errstr = gettext(PROB_copy); /* * The new copy (if it exists at all) is a botch. * If this was a new create or a remove and copy * we should get rid of the botched copy so that * it doesn't show up as two versions next time. */ if (do_create) unlink(dst); } else if (dp->f_mode == 0) { dp->f_type = S_IFREG; dp->f_uid = my_uid; dp->f_gid = my_gid; dp->f_mode = mode; /* FIX: inode number is still wrong */ } /* for normal files we have an option to preserve mod time */ if (rc == 0 && opt_notouch == 0 && opt_mtime) { newtimes.actime = mtime; newtimes.modtime = mtime; /* ignore the error return on this one */ (void) utime(dst, &newtimes); } break; default: errstr = gettext(PROB_deal); rc = -1; } /* * if any of the file's attributes need attention, I should let * do_like take care of them, since it knows all rules for who * can and cannot make what types of changes. */ if (rc == 0 && (do_chmod || do_chown || do_chgrp || do_acls)) { rc = do_like(fp, srcdst, FALSE); errstr = fp->f_problem; errs |= rc; } /* * finish off by re-stating the destination and using that to * update the baseline. If we were completely successful in * our chowns/chmods, stating the destination will confirm it. * If we were unable to make all the necessary changes, stating * the destination will make the source appear to have changed, * so that the differences will continue to reappear as new * changes (inconsistancies). */ if (rc == 0) if (!opt_notouch) { errstr = gettext(PROB_restat); #ifdef DBG_ERRORS /* should we simulate a restat failure */ if (errno = dbg_chk_error(dst, 'R')) rc = -1; else #endif rc = lstat(dst, &statb); if (rc == 0) { note_info(fp, &statb, srcdst); link_update(fp, srcdst); if (do_acls) (void) get_acls(dst, dp); update_info(fp, srcdst); } } else { /* * BOGOSITY ALERT * we are in notouch mode and haven't really * done anything, but if we want link detection * to work and be properly reflected in the * what-I-would-do output for a case where * multiple links are created to a new file, * we have to make the new file appear to * have been created. Since we didn't create * the new file we can't stat it, but if * no file exists, we can't make a link to * it, so we will pretend we created a file. */ if (dp->f_ino == 0 || dp->f_nlink == 0) { dp->f_ino = sp->f_ino; dp->f_nlink = 1; } } cant: if (rc != 0) { fprintf(stderr, gettext(ERR_cannot), errstr, dst); bp->b_unresolved++; fp->f_flags |= F_CONFLICT; fp->f_problem = errstr; if (errs == 0) errs = ERR_PERM; errs |= ERR_UNRESOLVED; } else { /* update the statistics */ if (srcdst == OPT_SRC) bp->b_src_copies++; else bp->b_dst_copies++; errs |= ERR_RESOLVABLE; } return (errs); }
int main(int argc, char **argv) { kstat_ctl_t *kc; kstat_t *ksp; kstat_named_t *knp; struct vcpu *vc; struct core *core; struct pchip *chip; struct link **ins; char *s; int nspec; int optc; int opt_s = 0; int opt_p = 0; int opt_v = 0; int ex = 0; cmdname = basename(argv[0]); (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); /* collect the kstats */ if ((kc = kstat_open()) == NULL) die(_("kstat_open() failed")); if ((ksp = kstat_lookup(kc, "cpu_info", -1, NULL)) == NULL) die(_("kstat_lookup() failed")); for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) { if (strcmp(ksp->ks_module, "cpu_info") != 0) continue; if (kstat_read(kc, ksp, NULL) == NULL) die(_("kstat_read() failed")); vc = find_link(&vcpus, ksp->ks_instance, &ins); if (vc == NULL) { vc = zalloc(sizeof (struct vcpu)); vc->v_link.l_id = ksp->ks_instance; vc->v_link_core.l_id = ksp->ks_instance; vc->v_link_pchip.l_id = ksp->ks_instance; vc->v_link.l_ptr = vc; vc->v_link_core.l_ptr = vc; vc->v_link_pchip.l_ptr = vc; ins_link(ins, &vc->v_link); } if ((knp = kstat_data_lookup(ksp, "state")) != NULL) { vc->v_state = mystrdup(knp->value.c); } else { vc->v_state = "unknown"; } if ((knp = kstat_data_lookup(ksp, "cpu_type")) != NULL) { vc->v_cpu_type = mystrdup(knp->value.c); } if ((knp = kstat_data_lookup(ksp, "fpu_type")) != NULL) { vc->v_fpu_type = mystrdup(knp->value.c); } if ((knp = kstat_data_lookup(ksp, "state_begin")) != NULL) { vc->v_state_begin = knp->value.l; } if ((knp = kstat_data_lookup(ksp, "clock_MHz")) != NULL) { vc->v_clock_mhz = knp->value.l; } if ((knp = kstat_data_lookup(ksp, "brand")) == NULL) { vc->v_brand = _("(unknown)"); } else { vc->v_brand = mystrdup(knp->value.str.addr.ptr); } if ((knp = kstat_data_lookup(ksp, "socket_type")) == NULL) { vc->v_socket = "Unknown"; } else { vc->v_socket = mystrdup(knp->value.str.addr.ptr); } if ((knp = kstat_data_lookup(ksp, "implementation")) == NULL) { vc->v_impl = _("(unknown)"); } else { vc->v_impl = mystrdup(knp->value.str.addr.ptr); } /* * Legacy code removed the chipid and cpuid fields... we * do the same for compatibility. Note that the original * pattern is a bit strange, and we have to emulate this because * on SPARC we *do* emit these. The original pattern we are * emulating is: $impl =~ s/(cpuid|chipid)\s*\w+\s+//; */ if ((s = strstr(vc->v_impl, "chipid")) != NULL) { char *x = s + strlen("chipid"); while (isspace(*x)) x++; if ((!isalnum(*x)) && (*x != '_')) goto nochipid; while (isalnum(*x) || (*x == '_')) x++; if (!isspace(*x)) goto nochipid; while (isspace(*x)) x++; (void) strcpy(s, x); } nochipid: if ((s = strstr(vc->v_impl, "cpuid")) != NULL) { char *x = s + strlen("cpuid"); while (isspace(*x)) x++; if ((!isalnum(*x)) && (*x != '_')) goto nocpuid; while (isalnum(*x) || (*x == '_')) x++; if (!isspace(*x)) goto nocpuid; while (isspace(*x)) x++; (void) strcpy(s, x); } nocpuid: if ((knp = kstat_data_lookup(ksp, "chip_id")) != NULL) vc->v_pchip_id = knp->value.l; chip = find_link(&pchips, vc->v_pchip_id, &ins); if (chip == NULL) { chip = zalloc(sizeof (struct pchip)); chip->p_link.l_id = vc->v_pchip_id; chip->p_link.l_ptr = chip; ins_link(ins, &chip->p_link); } vc->v_pchip = chip; if ((knp = kstat_data_lookup(ksp, "core_id")) != NULL) vc->v_core_id = knp->value.l; core = find_link(&cores, vc->v_core_id, &ins); if (core == NULL) { core = zalloc(sizeof (struct core)); core->c_link.l_id = vc->v_core_id; core->c_link.l_ptr = core; core->c_link_pchip.l_id = vc->v_core_id; core->c_link_pchip.l_ptr = core; core->c_pchip = chip; ins_link(ins, &core->c_link); chip->p_ncore++; (void) find_link(&chip->p_cores, core->c_link.l_id, &ins); ins_link(ins, &core->c_link_pchip); } vc->v_core = core; /* now put other linkages in place */ (void) find_link(&chip->p_vcpus, vc->v_link.l_id, &ins); ins_link(ins, &vc->v_link_pchip); chip->p_nvcpu++; (void) find_link(&core->c_vcpus, vc->v_link.l_id, &ins); ins_link(ins, &vc->v_link_core); core->c_nvcpu++; } (void) kstat_close(kc); nspec = 0; while ((optc = getopt(argc, argv, "pvs")) != EOF) { switch (optc) { case 's': opt_s = 1; break; case 'p': opt_p = 1; break; case 'v': opt_v = 1; break; default: usage(NULL); } } while (optind < argc) { long id; char *eptr; struct link *l; id = strtol(argv[optind], &eptr, 10); l = find_link(&vcpus, id, NULL); if ((*eptr != '\0') || (l == NULL)) { (void) fprintf(stderr, _("%s: processor %s: Invalid argument\n"), cmdname, argv[optind]); ex = 2; } else { ((struct vcpu *)l->l_ptr)->v_doit = 1; ((struct vcpu *)l->l_ptr)->v_pchip->p_doit = 1; ((struct vcpu *)l->l_ptr)->v_core->c_doit = 1; } nspec++; optind++; } if (opt_s && opt_v) { usage(_("options -s and -v are mutually exclusive")); } if (opt_s && nspec != 1) { usage(_("must specify exactly one processor if -s used")); } if (opt_v && opt_p) { print_vp(nspec); } else if (opt_s && opt_p) { print_ps(); } else if (opt_p) { print_p(nspec); } else if (opt_v) { print_v(nspec); } else if (opt_s) { print_s(); } else { print_normal(nspec); } return (ex); }
/* * A simple walk of event sets: dispatch and print a event SET every 2 sec */ void walk_el(int update_time, int time_between, int verb) { struct el *el; struct es *es_hd; struct es *es; assert (g_el->next); assert (get_myid >= 0); print_el(); /* initialize link set, routing table, and routing table */ create_ls(); create_rt(); init_rt_from_n2h(); for (el = g_el->next ; el != g_el ; el = el->next) { assert(el); es_hd = el->es_head; assert (es_hd); int *updated = (int *) calloc(256, sizeof(int)); struct es *myCurrES = es_hd->next; while(myCurrES->ev != _es_null){ if(myCurrES->ev == _es_link){ if(get_myid() == myCurrES->peer0){ update_rte(myCurrES->peer1, myCurrES->cost, myCurrES->peer1); updated[myCurrES->peer1] = 1; }else{ update_rte(myCurrES->peer0, myCurrES->cost, myCurrES->peer0); updated[myCurrES->peer0] = 1; } }else if(myCurrES->ev == _td_link){ struct link *linkToTd = find_link(myCurrES->name); if(get_myid() == linkToTd->peer0){ update_rte(linkToTd->peer1, -1, linkToTd->peer1); updated[myCurrES->peer1] = 1; }else{ update_rte(linkToTd->peer0, -1, linkToTd->peer0); updated[myCurrES->peer0] = 1; } }else if(myCurrES->ev == _ud_link){ struct link *linkToUd = find_link(myCurrES->name); if(get_myid() == linkToUd->peer0){ update_rte(linkToUd->peer1, myCurrES->cost, linkToUd->peer1); updated[myCurrES->peer1] = 1; }else{ update_rte(linkToUd->peer0, myCurrES->cost, linkToUd->peer0); updated[myCurrES->peer0] = 1; } } myCurrES = myCurrES->next; } printf("[es] >>>>>>>>>> Dispatch next event set <<<<<<<<<<<<<\n"); for (es=es_hd->next ; es!=es_hd ; es=es->next) { printf("[es] Dispatching next event ... \n"); dispatch_event(es); } runDVA(updated, 1); sleep(3); printf("[es] >>>>>>> Start dumping data stuctures <<<<<<<<<<<\n"); print_n2h(); print_ls(); print_rt(); } }
/* * Operates on a single di_node_t, collecting all the device properties * that we need. devnvl is allocated by the caller, and we add our nvpairs * to it if they don't already exist. * * We are _only_ interested in devices which have a devid. We pull in * devices even when they're excluded via stmsboot -D (driver), because * we don't want to miss out on any devid data that might be handy later. */ static int popcheck_devnvl(di_node_t thisnode, nvlist_t *devnvl, char *strdevid) { char *path = NULL; char *curpath = NULL; char *devfspath = NULL; char *prop = NULL; int scsivhciparent = 0; int rv = 0; boolean_t mpxenp = B_FALSE; errno = 0; devfspath = di_devfs_path(thisnode); if (devfspath == NULL) { logmsg(MSG_ERROR, gettext("Unable to determine devfs path for node: %s\n"), strerror(errno)); return (-1); } /* Add a convenient devfspath to devid inverse map */ if (nvlist_add_string(mapnvl, devfspath, strdevid) != 0) { logmsg(MSG_ERROR, gettext("Unable to add device path %s with devid " "%s to mapnvl\n"), devfspath, strdevid); return (-1); } if (di_prop_lookup_strings(DDI_DEV_T_ANY, di_parent_node(thisnode), "mpxio-disable", &prop) >= 0) { if (strncmp(prop, "yes", 3) == 0) { if (!mpxprop) mpxprop++; } } if (strncmp(di_driver_name(di_parent_node(thisnode)), "scsi_vhci", 9) == 0) { scsivhciparent = 1; if (!mpxenabled) mpxenabled++; rv = nvlist_lookup_boolean_value(devnvl, NVL_MPXEN, &mpxenp); if (rv || (mpxenp == B_FALSE)) { rv = nvlist_add_boolean_value(devnvl, NVL_MPXEN, B_TRUE); if (rv) { logmsg(MSG_ERROR, gettext("Unable to add property %s " "(set to B_TRUE) for device %s: " "%s (%d)\n"), NVL_MPXEN, devfspath, strerror(rv), rv); return (-1); } logmsg(MSG_INFO, "NVL_MPXEN :: (B_FALSE->B_TRUE)\n"); } } else { /* turn _off_ the flag if it was enabled */ rv = nvlist_add_boolean_value(devnvl, NVL_MPXEN, B_FALSE); if (rv) { logmsg(MSG_ERROR, gettext("Unable to add property %s " "(set to B_FALSE) for device %s: %s (%d)\n"), NVL_MPXEN, devfspath, strerror(rv), rv); return (-1); } logmsg(MSG_INFO, "NVL_MPXEN :: (B_TRUE-> B_FALSE)\n"); } rv = nvlist_add_string(devnvl, NVL_PHYSPATH, devfspath); if (rv) { logmsg(MSG_ERROR, gettext("Unable to add physical device path (%s) " "property to nvl\n")); return (-1); } if ((curpath = calloc(1, MAXPATHLEN)) == NULL) { logmsg(MSG_ERROR, gettext("Unable to allocate space for current path\n")); return (-1); } curpath = find_link(thisnode); if (curpath == NULL) { if (readonlyroot) { return (0); } logmsg(MSG_ERROR, gettext("Unable to determine device path for node %s\n"), devfspath); return (-1); } rv = nvlist_lookup_string(devnvl, NVL_MPXPATH, &path); if (scsivhciparent) { (void) nvlist_add_string(devnvl, NVL_MPXPATH, curpath); } else { (void) nvlist_add_string(devnvl, NVL_PATH, curpath); path = curpath; } /* * This next block provides the path to devid inverse mapping * that other functions require */ if (path != NULL) { if (nvlist_add_string(mapnvl, path, strdevid) != 0) { logmsg(MSG_ERROR, gettext("Unable to add device %s with devid " "%s to mapnvl\n"), path, strdevid); return (-1); } logmsg(MSG_INFO, "popcheck_devnvl: added path %s :: %s\n", path, strdevid); } if (nvlist_add_string(mapnvl, curpath, strdevid) != 0) { logmsg(MSG_ERROR, gettext("Unable to add device %s with devid " "%s to mapnvl: %s\n"), curpath, strdevid, strerror(errno)); return (-1); } logmsg(MSG_INFO, "popcheck_devnvl: added curpath %s :: %s\n", curpath, strdevid); return (0); }
struct node *handle_IIB (int index, struct node **tree, struct node *u) // Handle the case in which the suffix link of node u is UNKNOWN, and u's parent is root. { struct node *up = u -> parent; return find_link (index, up, u, u -> starti + 1, u -> endi); }
/* * Scan the directory and create a manifest from it's contents. * Return 0 on error. */ int manifest_scan (manifest_t *m, const char *dirname) { FTS *dir; FTSENT *node; char *argv[2], *path, *target, buf[BSDFS_BSIZE]; struct stat st; int prefix_len, mode, len; /* Clear manifest header. */ m->first = 0; m->last = 0; m->filemode = 0664; m->dirmode = 0775; m->owner = 0; m->group = 0; /* Open directory. */ argv[0] = (char*) dirname; argv[1] = 0; dir = fts_open (argv, FTS_PHYSICAL | FTS_NOCHDIR, &ftsent_compare); if (! dir) { fprintf (stderr, "%s: cannot open\n", dirname); return 0; } prefix_len = strlen (dirname); printf ("# Manifest for directory %s\n", dirname); for (;;) { /* Read next directory entry. */ node = fts_read(dir); if (! node) break; path = node->fts_path + prefix_len; if (path[0] == 0) continue; st = *node->fts_statp; mode = st.st_mode & 07777; switch (node->fts_info) { case FTS_D: /* Directory. */ add_entry (m, 'd', path, 0, mode, st.st_uid, st.st_gid, 0, 0); break; case FTS_F: /* Regular file. */ if (st.st_nlink > 1) { /* Hard link to file. */ target = find_link (st.st_dev, st.st_ino); if (target) { add_entry (m, 'l', path, target, mode, st.st_uid, st.st_gid, 0, 0); break; } keep_link (st.st_dev, st.st_ino, path); } add_entry (m, 'f', path, 0, mode, st.st_uid, st.st_gid, 0, 0); break; case FTS_SL: /* Symlink. */ if (st.st_nlink > 1) { /* Hard link to symlink. */ target = find_link (st.st_dev, st.st_ino); if (target) { add_entry (m, 'l', path, target, mode, st.st_uid, st.st_gid, 0, 0); break; } keep_link (st.st_dev, st.st_ino, path); } /* Get the target of symlink. */ len = readlink (node->fts_accpath, buf, sizeof(buf) - 1); if (len < 0) { fprintf (stderr, "%s: cannot read\n", node->fts_accpath); break; } buf[len] = 0; add_entry (m, 's', path, buf, mode, st.st_uid, st.st_gid, 0, 0); break; default: /* Ignore all other variants. */ break; } } fts_close (dir); return 1; }
void network_send(){ if(queue_nitems(msg_queue) == 0){ CNET_start_timer(EV_TIMER0, 100000, 0); return; // do nothing } //Fragment each message into a small unit and send along the link designated by the routing table size_t len = 0; next = queue_peek(msg_queue, &len); CnetAddr dest = next->dest; int dest_number = find_nodenumber(dest); //get link to send from the routing table int currLink = find_link(dest); //printf("Link to send is : %d\n", currLink); if(queue_nitems(links[currLink].sender) > 0){ //free(next); //printf("Some items in SENDER queue!\n"); CNET_start_timer(EV_TIMER0, 100000, 0); return; // do nothing } //Remove the topmost message from the queue next = queue_remove(msg_queue, &len); links[currLink].msg_in_sender_Q = node_buffer[dest_number].mesg_seq_no_to_generate; //printf("Message is to be processed! To be sent to %d from %d and size %d and message number is %d\n", dest, nodeinfo.address, len, mesg_seq_no); //printf("Creating frames for message #%d\n", mesg_seq_no); int int_len = len - MESSAGE_HEADER_SIZE; char *data_ptr; data_ptr = &next->data[0]; //printf("Message is to be processed! To be sent to %d from %d and size %d and message is %s.\n", dest, nodeinfo.address, len, data); //Enable application is message queue grows too small if(queue_nitems(msg_queue) < MAX_MSG_QUEUE_SIZE/2){ application_enabled = true; CNET_enable_application(ALLNODES); } size_t frame_len = table[dest_number].min_mtu - FRAME_HEADER_SIZE; // removing the length occupied by the destination address in the MESSAGE //printf("Min mtu - FRAME_HEADER_SIZE is : %d Initial message size was %d, after removing dest part it is %d\n", frame_len, len, int_len); //queue packets up int seqno; for(seqno = 0; int_len > 0; seqno++){ FRAME f; memset(&f.payload.data[0], '\0', MAX_MESSAGE_SIZE); f.payload.kind = DL_DATA; f.payload.source = nodeinfo.address; f.payload.dest = dest; f.payload.mesg_seq_no = node_buffer[dest_number].mesg_seq_no_to_generate; f.payload.len = (int_len < frame_len) ? int_len : frame_len; f.payload.flag_offset = (int_len <= frame_len) ? 1 : 0; getcurrtime(&f.payload.timestamp); f.payload.A = seqno; memcpy(&f.payload.data[0], data_ptr, f.payload.len); //printf("Length of frame to send is : %d and the payload is %s (before adding to queue)\n", strlen(f.payload.data) + FRAME_HEADER_SIZE, f.payload.data); f.checksum = 0; f.checksum = CNET_ccitt((unsigned char *)&f, (int)(f.payload.len) + FRAME_HEADER_SIZE); len = f.payload.len + FRAME_HEADER_SIZE; queue_add(links[currLink].sender, &f, len); int_len = int_len - frame_len; data_ptr = data_ptr + frame_len; } printf("Message read from application layer destined for address %d | size %d | msg #%d | # frames %d \n", dest, len - MESSAGE_HEADER_SIZE, node_buffer[dest_number].mesg_seq_no_to_generate, seqno); //printf("Created %d frames\n", seqno); node_buffer[dest_number].mesg_seq_no_to_generate++; for(int i = 0; i < seqno; i++) links[currLink].ack_received[i] = false; schedule_and_send(currLink); CNET_start_timer(EV_TIMER0, 100000, 0); }