Users may pass the following parameters to qemu: $ qemu-kvm -net nic -net user,smb= ... $ qemu-kvm -net nic -net user,smb ... $ qemu-kvm -net nic -net user,smb=bad_directory ...
In these cases, qemu started successfully while samba server failed to start. Users will confuse since samba server failed silently without any indication of what it did wrong. To avoid it, we check whether the shared directory exists or not when QEMU's "built-in" SMB server is enabled. Signed-off-by: Dunrong Huang <riegama...@gmail.com> --- net/slirp.c | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diff --git a/net/slirp.c b/net/slirp.c index 37b6ccf..a672cff 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -489,6 +489,20 @@ static int slirp_smb(SlirpState* s, const char *exported_dir, char smb_cmdline[128]; FILE *f; + if (access(CONFIG_SMBD_COMMAND, F_OK)) { + slirp_smb_cleanup(s); + error_report("could not find '%s', please install it", + CONFIG_SMBD_COMMAND); + return -1; + } + + if (access(exported_dir, F_OK)) { + slirp_smb_cleanup(s); + error_report("no such shared directory '%s', please check it", + exported_dir); + return -1; + } + snprintf(s->smb_dir, sizeof(s->smb_dir), "/tmp/qemu-smb.%ld-%d", (long)getpid(), instance++); if (mkdir(s->smb_dir, 0700) < 0) { -- 1.7.8.4