1
/*********************************************************
2
* Copyright (C) 2011 VMware, Inc. All rights reserved.
4
* This program is free software; you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License as published
6
* by the Free Software Foundation version 2.1 and no later version.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10
* or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public
11
* License for more details.
13
* You should have received a copy of the GNU Lesser General Public License
14
* along with this program; if not, write to the Free Software Foundation, Inc.,
15
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
17
*********************************************************/
20
* @file vmSyncDriver.c
22
* A sync driver backend that uses VMware's "vmsync" driver.
26
#include <sys/ioctl.h>
28
#include "syncDriverInt.h"
29
#include "syncDriverIoc.h"
32
#define SYNC_PROC_PATH "/proc/driver/vmware-sync"
34
typedef struct VmSyncDriver {
41
*******************************************************************************
42
* VmSyncThaw -- */ /**
44
* Thaws filesystems previously frozen.
46
* @param[in] handle Handle returned by the freeze operation.
48
* @return A SyncDriverErr.
50
*******************************************************************************
54
VmSyncThaw(const SyncDriverHandle handle)
56
const VmSyncDriver *sync = (VmSyncDriver *) handle;
57
ASSERT(handle != SYNCDRIVER_INVALID_HANDLE);
58
return ioctl(sync->fd, SYNC_IOC_THAW) != -1 ? SD_SUCCESS : SD_ERROR;
63
*******************************************************************************
64
* VmSyncClose -- */ /**
66
* Closes the descriptor used to talk to the vmsync driver and frees memory
69
* @param[in] handle Handle to close.
71
*******************************************************************************
75
VmSyncClose(SyncDriverHandle handle)
77
VmSyncDriver *sync = (VmSyncDriver *) handle;
84
*******************************************************************************
85
* VmSync_Freeze -- */ /**
87
* Tries to freeze the requested filesystems with the vmsync driver.
89
* Opens a description to the driver's proc node, and if successful, send an
90
* ioctl to freeze the requested filesystems.
92
* @param[in] paths Paths to freeze (colon-delimited).
93
* @param[out] handle Where to store the handle to use for thawing.
95
* @return A SyncDriverErr.
97
*******************************************************************************
101
VmSync_Freeze(const char *paths,
102
SyncDriverHandle *handle)
105
VmSyncDriver *sync = NULL;
107
Debug(LGPFX "Freezing using vmsync driver...\n");
109
file = open(SYNC_PROC_PATH, O_RDONLY);
111
return SD_UNAVAILABLE;
114
sync = calloc(1, sizeof *sync);
119
sync->driver.thaw = VmSyncThaw;
120
sync->driver.close = VmSyncClose;
123
if (ioctl(file, SYNC_IOC_FREEZE, paths) == -1) {
134
*handle = &sync->driver;
136
return sync != NULL ? SD_SUCCESS : SD_ERROR;