Changeset View
Standalone View
usr.sbin/bhyvectl/bhyvectl.c
Show First 20 Lines • Show All 1,705 Lines • ▼ Show 20 Lines | done: | ||||
nvlist_destroy(nvl); | nvlist_destroy(nvl); | ||||
if (socket_fd >= 0) | if (socket_fd >= 0) | ||||
close(socket_fd); | close(socket_fd); | ||||
return (err); | return (err); | ||||
} | } | ||||
static int | static int | ||||
snapshot_request(const char *vmname, const char *file, bool suspend) | open_directory(const char *file) | ||||
{ | { | ||||
char *path; | |||||
int fd; | |||||
if ((path = strdup(file)) == NULL) | |||||
return (-1); | |||||
dirname(path); | |||||
fd = open(path, O_DIRECTORY); | |||||
free(path); | |||||
return (fd); | |||||
} | |||||
static int | |||||
snapshot_request(const char *vmname, char *file, bool suspend) | |||||
{ | |||||
nvlist_t *nvl; | nvlist_t *nvl; | ||||
int fd; | |||||
if ((fd = open_directory(file)) < 0) | |||||
return (errno); | |||||
nvl = nvlist_create(0); | nvl = nvlist_create(0); | ||||
nvlist_add_string(nvl, "cmd", "checkpoint"); | nvlist_add_string(nvl, "cmd", "checkpoint"); | ||||
nvlist_add_string(nvl, "filename", file); | nvlist_add_string(nvl, "filename", basename(file)); | ||||
nvlist_add_bool(nvl, "suspend", suspend); | nvlist_add_bool(nvl, "suspend", suspend); | ||||
rew: what happens when just a filename is passed to open_directory? | |||||
Done Inline ActionsIf only name is described, snapshot is placed to the bhyvectl's current directory. I.e. fd will point to "." From man dirname(3): RETURN VALUES If path is a null pointer, the empty string, or contains no ‘/’ characters, dirname() returns a pointer to the string ".", signifying the current directory. Otherwise, it returns a pointer to the parent directory of path. gusev.vitaliy_gmail.com: ```
If only name is described, snapshot is placed to the bhyvectl's current directory.
```
I.e. | |||||
nvlist_move_descriptor(nvl, "fddir", fd); | |||||
return (send_message(vmname, nvl)); | return (send_message(vmname, nvl)); | ||||
} | } | ||||
#endif | #endif | ||||
Done Inline Actionswhat happens if basename() fails? rew: what happens if basename() fails? | |||||
Done Inline Actionsbase name never fails. From man: RETURN VALUES If path consists entirely of ‘/’ characters, a pointer to the string "/" is returned. If path is a null pointer or the empty string, a pointer to the string "." is returned. Otherwise, it returns a pointer to the last component of path. gusev.vitaliy_gmail.com: base name never fails.
From man:
```
RETURN VALUES
If path consists entirely of ‘/’… | |||||
int | int | ||||
Done Inline Actionswhere is this file descriptor being closed? rew: where is this file descriptor being closed? | |||||
Done Inline Actionsnvlist_move_descriptor() "owns" passed descriptor and it will be closed at nvlist_destroy(). gusev.vitaliy_gmail.com: nvlist_move_descriptor() "owns" passed descriptor and it will be closed at nvlist_destroy(). | |||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
char *vmname; | char *vmname; | ||||
int error, ch, vcpuid, ptenum; | int error, ch, vcpuid, ptenum; | ||||
vm_paddr_t gpa_pmap; | vm_paddr_t gpa_pmap; | ||||
struct vm_exit vmexit; | struct vm_exit vmexit; | ||||
Done Inline Actionssee basename(3) rew: see basename(3) | |||||
Done Inline Actionsbasename() is not case because it needs not constant pointer and therefore needs allocation and free-ing. Current implementation doesn't need any allocation. gusev.vitaliy_gmail.com: basename() is not case because it needs not constant pointer and therefore needs allocation and… | |||||
Done Inline ActionsI prefer to see basename() used as opposed to using a hand-rolled function - it's more idiomatic. its probably fine to drop the const qualifier or do the allocation...either way. rew: I prefer to see basename() used as opposed to using a hand-rolled function - it's more… | |||||
Done Inline ActionsWill update. gusev.vitaliy_gmail.com: Will update. | |||||
Done Inline ActionsDone. gusev.vitaliy_gmail.com: Done. | |||||
uint64_t rax, cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7; | uint64_t rax, cr0, cr2, cr3, cr4, dr0, dr1, dr2, dr3, dr6, dr7; | ||||
uint64_t rsp, rip, rflags, efer, pat; | uint64_t rsp, rip, rflags, efer, pat; | ||||
Done Inline Actionswhat's going to happen if open_directory() fails? rew: what's going to happen if open_directory() fails? | |||||
Done Inline ActionsNegative 'fd' will be added to nvl, and nvlist_send() will fail. If you think it needs additional log message, please describe which. gusev.vitaliy_gmail.com: Negative 'fd' will be added to nvl, and nvlist_send() will fail. If you think it needs… | |||||
Done Inline Actionswhy try to send the nvlist if the file descriptor is known to be bad? rew: why try to send the nvlist if the file descriptor is known to be bad? | |||||
Done Inline ActionsI wanted to make a code short. Understood your complaints and will update. Thanks. gusev.vitaliy_gmail.com: I wanted to make a code short. Understood your complaints and will update. Thanks. | |||||
Done Inline ActionsDone. gusev.vitaliy_gmail.com: Done. | |||||
uint64_t eptp, bm, addr, u64, pteval[4], *pte, info[2]; | uint64_t eptp, bm, addr, u64, pteval[4], *pte, info[2]; | ||||
struct vmctx *ctx; | struct vmctx *ctx; | ||||
struct vcpu *vcpu; | struct vcpu *vcpu; | ||||
cpuset_t cpus; | cpuset_t cpus; | ||||
bool cpu_intel; | bool cpu_intel; | ||||
uint64_t cs, ds, es, fs, gs, ss, tr, ldtr; | uint64_t cs, ds, es, fs, gs, ss, tr, ldtr; | ||||
struct tm tm; | struct tm tm; | ||||
struct option *opts; | struct option *opts; | ||||
▲ Show 20 Lines • Show All 651 Lines • Show Last 20 Lines |
what happens when just a filename is passed to open_directory?