#include <sanlock_resource.h>
#include <sanlock_admin.h>
+#include "dirname.h"
#include "lock_driver.h"
#include "logging.h"
#include "virterror_internal.h"
int rv;
struct sanlk_lockspace ls;
char *path = NULL;
+ char *dir = NULL;
if (virAsprintf(&path, "%s/%s",
driver->autoDiskLeasePath,
*/
if (stat(path, &st) < 0) {
VIR_DEBUG("Lockspace %s does not yet exist", path);
+
+ if (!(dir = mdir_name(path))) {
+ virReportOOMError();
+ goto error;
+ }
+ if (stat(dir, &st) < 0 || !S_ISDIR(st.st_mode)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to create lockspace %s: parent directory"
+ " does not exist or is not a directory"),
+ path);
+ goto error;
+ }
+
if ((fd = open(path, O_WRONLY|O_CREAT|O_EXCL, 0600)) < 0) {
if (errno != EEXIST) {
virReportSystemError(errno,
error:
VIR_FORCE_CLOSE(fd);
VIR_FREE(path);
+ VIR_FREE(dir);
return -1;
}