大家好,又见面了,我是你们的朋友全栈君。
virsh.c中 main-> vshParseArgv-> vshCommandArgvParse-> vshCommandParse-> vshCmddefSearch
int main(int argc, char **argv) { if (!vshParseArgv(ctl, argc, argv)) { vshDeinit(ctl); exit(EXIT_FAILURE); }
static bool vshParseArgv(vshControl *ctl, int argc, char **argv) { if (argc > optind) { /* parse command */ ctl->imode = false; if (argc – optind == 1) { vshDebug(ctl, VSH_ERR_INFO, “commands: ”%s”n”, argv[optind]); return vshCommandStringParse(ctl, argv[optind]); } else { return vshCommandArgvParse(ctl, argc – optind, argv optind); } }
static bool vshCommandArgvParse(vshControl *ctl, int nargs, char **argv) { vshCommandParser parser;
if (nargs <= 0) return false;
parser.arg_pos = argv; parser.arg_end = argv nargs; parser.getNextArg = vshCommandArgvGetArg; return vshCommandParse(ctl, &parser); }
static bool vshCommandParse(vshControl *ctl, vshCommandParser *parser) { if (cmd == NULL) { /* first token must be command name */ if (!(cmd = vshCmddefSearch(tkdata))) {
static const vshCmdGrp cmdGroups[] = { {VSH_CMD_GRP_DOM_MANAGEMENT, “domain”, domManagementCmds}, {VSH_CMD_GRP_DOM_MONITORING, “monitor”, domMonitoringCmds}, {VSH_CMD_GRP_HOST_AND_HV, “host”, hostAndHypervisorCmds}, {VSH_CMD_GRP_IFACE, “interface”, ifaceCmds}, {VSH_CMD_GRP_NWFILTER, “filter”, nwfilterCmds}, {VSH_CMD_GRP_NETWORK, “network”, networkCmds}, {VSH_CMD_GRP_NODEDEV, “nodedev”, nodedevCmds}, {VSH_CMD_GRP_SECRET, “secret”, secretCmds}, {VSH_CMD_GRP_SNAPSHOT, “snapshot”, snapshotCmds}, {VSH_CMD_GRP_STORAGE_POOL, “pool”, storagePoolCmds}, {VSH_CMD_GRP_STORAGE_VOL, “volume”, storageVolCmds}, {VSH_CMD_GRP_VIRSH, “virsh”, virshCmds}, {NULL, NULL, NULL} };
domManagementCmds
static const vshCmdDef domManagementCmds[] = { {“define”, cmdDefine, opts_define, info_define, 0},
返回vshCmdDef cmd = domManagementCmds
static bool vshParseArgv(vshControl *ctl, int argc, char **argv) { if (argc > optind) { /* parse command */ ctl->imode = false; if (argc – optind == 1) { vshDebug(ctl, VSH_ERR_INFO, “commands: ”%s”n”, argv[optind]); return vshCommandStringParse(ctl, argv[optind]);
int main(int argc, char **argv) {
if (!vshInit(ctl)) { vshDeinit(ctl); exit(EXIT_FAILURE); }
if (!ctl->imode) { ret = vshCommandRun(ctl, ctl->cmd);
static bool vshCommandRun(vshControl *ctl, const vshCmd *cmd) { while (cmd) { struct timeval before, after; bool enable_timing = ctl->timing;
if ((ctl->conn == NULL || disconnected) && !(cmd->def->flags & VSH_CMD_FLAG_NOCONNECT)) vshReconnect(ctl);
if (enable_timing) GETTIMEOFDAY(&before);
ret = cmd->def->handler(ctl, cmd);
define 调用cmdDefine static bool cmdDefine(vshControl *ctl, const vshCmd *cmd) { dom = virDomainDefineXML(ctl->conn, buffer);
virDomainPtr virDomainDefineXML(virConnectPtr conn, const char *xml) { /* add by c00165101 end */ if (conn->driver->domainDefineXML) { virDomainPtr ret; ret = conn->driver->domainDefineXML (conn, xml); 指向xen_driver.c中 static virDomainPtr xenUnifiedDomainDefineXML (virConnectPtr conn, const char *xml) { GET_PRIVATE(conn); int i; virDomainPtr ret;
for (i = 0; i < XEN_UNIFIED_NR_DRIVERS; i) if (priv->opened[i] && drivers[i]->xenDomainDefineXML) { ret = drivers[i]->xenDomainDefineXML (conn, xml); if (ret) return ret; }
return NULL; }
2013年5月23日上传
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/169806.html原文链接:https://javaforall.cn