1*7c604eeaShaad /* $NetBSD: dm-log-userspace.h,v 1.1.1.1 2009/12/02 00:25:40 haad Exp $ */ 2*7c604eeaShaad 3*7c604eeaShaad /* 4*7c604eeaShaad * Copyright (C) 2006-2009 Red Hat, Inc. 5*7c604eeaShaad * 6*7c604eeaShaad * This file is released under the LGPL. 7*7c604eeaShaad */ 8*7c604eeaShaad 9*7c604eeaShaad #ifndef __DM_LOG_USERSPACE_H__ 10*7c604eeaShaad #define __DM_LOG_USERSPACE_H__ 11*7c604eeaShaad 12*7c604eeaShaad #include <linux/dm-ioctl.h> /* For DM_UUID_LEN */ 13*7c604eeaShaad 14*7c604eeaShaad /* 15*7c604eeaShaad * The device-mapper userspace log module consists of a kernel component and 16*7c604eeaShaad * a user-space component. The kernel component implements the API defined 17*7c604eeaShaad * in dm-dirty-log.h. Its purpose is simply to pass the parameters and 18*7c604eeaShaad * return values of those API functions between kernel and user-space. 19*7c604eeaShaad * 20*7c604eeaShaad * Below are defined the 'request_types' - DM_ULOG_CTR, DM_ULOG_DTR, etc. 21*7c604eeaShaad * These request types represent the different functions in the device-mapper 22*7c604eeaShaad * dirty log API. Each of these is described in more detail below. 23*7c604eeaShaad * 24*7c604eeaShaad * The user-space program must listen for requests from the kernel (representing 25*7c604eeaShaad * the various API functions) and process them. 26*7c604eeaShaad * 27*7c604eeaShaad * User-space begins by setting up the communication link (error checking 28*7c604eeaShaad * removed for clarity): 29*7c604eeaShaad * fd = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_CONNECTOR); 30*7c604eeaShaad * addr.nl_family = AF_NETLINK; 31*7c604eeaShaad * addr.nl_groups = CN_IDX_DM; 32*7c604eeaShaad * addr.nl_pid = 0; 33*7c604eeaShaad * r = bind(fd, (struct sockaddr *) &addr, sizeof(addr)); 34*7c604eeaShaad * opt = addr.nl_groups; 35*7c604eeaShaad * setsockopt(fd, SOL_NETLINK, NETLINK_ADD_MEMBERSHIP, &opt, sizeof(opt)); 36*7c604eeaShaad * 37*7c604eeaShaad * User-space will then wait to receive requests form the kernel, which it 38*7c604eeaShaad * will process as described below. The requests are received in the form, 39*7c604eeaShaad * ((struct dm_ulog_request) + (additional data)). Depending on the request 40*7c604eeaShaad * type, there may or may not be 'additional data'. In the descriptions below, 41*7c604eeaShaad * you will see 'Payload-to-userspace' and 'Payload-to-kernel'. The 42*7c604eeaShaad * 'Payload-to-userspace' is what the kernel sends in 'additional data' as 43*7c604eeaShaad * necessary parameters to complete the request. The 'Payload-to-kernel' is 44*7c604eeaShaad * the 'additional data' returned to the kernel that contains the necessary 45*7c604eeaShaad * results of the request. The 'data_size' field in the dm_ulog_request 46*7c604eeaShaad * structure denotes the availability and amount of payload data. 47*7c604eeaShaad */ 48*7c604eeaShaad 49*7c604eeaShaad /* 50*7c604eeaShaad * DM_ULOG_CTR corresponds to (found in dm-dirty-log.h): 51*7c604eeaShaad * int (*ctr)(struct dm_dirty_log *log, struct dm_target *ti, 52*7c604eeaShaad * unsigned argc, char **argv); 53*7c604eeaShaad * 54*7c604eeaShaad * Payload-to-userspace: 55*7c604eeaShaad * A single string containing all the argv arguments separated by ' 's 56*7c604eeaShaad * Payload-to-kernel: 57*7c604eeaShaad * None. ('data_size' in the dm_ulog_request struct should be 0.) 58*7c604eeaShaad * 59*7c604eeaShaad * The UUID contained in the dm_ulog_request structure is the reference that 60*7c604eeaShaad * will be used by all request types to a specific log. The constructor must 61*7c604eeaShaad * record this assotiation with instance created. 62*7c604eeaShaad * 63*7c604eeaShaad * When the request has been processed, user-space must return the 64*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and 65*7c604eeaShaad * 'data_size' appropriately. 66*7c604eeaShaad */ 67*7c604eeaShaad #define DM_ULOG_CTR 1 68*7c604eeaShaad 69*7c604eeaShaad /* 70*7c604eeaShaad * DM_ULOG_DTR corresponds to (found in dm-dirty-log.h): 71*7c604eeaShaad * void (*dtr)(struct dm_dirty_log *log); 72*7c604eeaShaad * 73*7c604eeaShaad * Payload-to-userspace: 74*7c604eeaShaad * A single string containing all the argv arguments separated by ' 's 75*7c604eeaShaad * Payload-to-kernel: 76*7c604eeaShaad * None. ('data_size' in the dm_ulog_request struct should be 0.) 77*7c604eeaShaad * 78*7c604eeaShaad * The UUID contained in the dm_ulog_request structure is all that is 79*7c604eeaShaad * necessary to identify the log instance being destroyed. There is no 80*7c604eeaShaad * payload data. 81*7c604eeaShaad * 82*7c604eeaShaad * When the request has been processed, user-space must return the 83*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and clearing 84*7c604eeaShaad * 'data_size' appropriately. 85*7c604eeaShaad */ 86*7c604eeaShaad #define DM_ULOG_DTR 2 87*7c604eeaShaad 88*7c604eeaShaad /* 89*7c604eeaShaad * DM_ULOG_PRESUSPEND corresponds to (found in dm-dirty-log.h): 90*7c604eeaShaad * int (*presuspend)(struct dm_dirty_log *log); 91*7c604eeaShaad * 92*7c604eeaShaad * Payload-to-userspace: 93*7c604eeaShaad * None. 94*7c604eeaShaad * Payload-to-kernel: 95*7c604eeaShaad * None. 96*7c604eeaShaad * 97*7c604eeaShaad * The UUID contained in the dm_ulog_request structure is all that is 98*7c604eeaShaad * necessary to identify the log instance being presuspended. There is no 99*7c604eeaShaad * payload data. 100*7c604eeaShaad * 101*7c604eeaShaad * When the request has been processed, user-space must return the 102*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and 103*7c604eeaShaad * 'data_size' appropriately. 104*7c604eeaShaad */ 105*7c604eeaShaad #define DM_ULOG_PRESUSPEND 3 106*7c604eeaShaad 107*7c604eeaShaad /* 108*7c604eeaShaad * DM_ULOG_POSTSUSPEND corresponds to (found in dm-dirty-log.h): 109*7c604eeaShaad * int (*postsuspend)(struct dm_dirty_log *log); 110*7c604eeaShaad * 111*7c604eeaShaad * Payload-to-userspace: 112*7c604eeaShaad * None. 113*7c604eeaShaad * Payload-to-kernel: 114*7c604eeaShaad * None. 115*7c604eeaShaad * 116*7c604eeaShaad * The UUID contained in the dm_ulog_request structure is all that is 117*7c604eeaShaad * necessary to identify the log instance being postsuspended. There is no 118*7c604eeaShaad * payload data. 119*7c604eeaShaad * 120*7c604eeaShaad * When the request has been processed, user-space must return the 121*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and 122*7c604eeaShaad * 'data_size' appropriately. 123*7c604eeaShaad */ 124*7c604eeaShaad #define DM_ULOG_POSTSUSPEND 4 125*7c604eeaShaad 126*7c604eeaShaad /* 127*7c604eeaShaad * DM_ULOG_RESUME corresponds to (found in dm-dirty-log.h): 128*7c604eeaShaad * int (*resume)(struct dm_dirty_log *log); 129*7c604eeaShaad * 130*7c604eeaShaad * Payload-to-userspace: 131*7c604eeaShaad * None. 132*7c604eeaShaad * Payload-to-kernel: 133*7c604eeaShaad * None. 134*7c604eeaShaad * 135*7c604eeaShaad * The UUID contained in the dm_ulog_request structure is all that is 136*7c604eeaShaad * necessary to identify the log instance being resumed. There is no 137*7c604eeaShaad * payload data. 138*7c604eeaShaad * 139*7c604eeaShaad * When the request has been processed, user-space must return the 140*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and 141*7c604eeaShaad * 'data_size' appropriately. 142*7c604eeaShaad */ 143*7c604eeaShaad #define DM_ULOG_RESUME 5 144*7c604eeaShaad 145*7c604eeaShaad /* 146*7c604eeaShaad * DM_ULOG_GET_REGION_SIZE corresponds to (found in dm-dirty-log.h): 147*7c604eeaShaad * uint32_t (*get_region_size)(struct dm_dirty_log *log); 148*7c604eeaShaad * 149*7c604eeaShaad * Payload-to-userspace: 150*7c604eeaShaad * None. 151*7c604eeaShaad * Payload-to-kernel: 152*7c604eeaShaad * uint64_t - contains the region size 153*7c604eeaShaad * 154*7c604eeaShaad * The region size is something that was determined at constructor time. 155*7c604eeaShaad * It is returned in the payload area and 'data_size' is set to 156*7c604eeaShaad * reflect this. 157*7c604eeaShaad * 158*7c604eeaShaad * When the request has been processed, user-space must return the 159*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field appropriately. 160*7c604eeaShaad */ 161*7c604eeaShaad #define DM_ULOG_GET_REGION_SIZE 6 162*7c604eeaShaad 163*7c604eeaShaad /* 164*7c604eeaShaad * DM_ULOG_IS_CLEAN corresponds to (found in dm-dirty-log.h): 165*7c604eeaShaad * int (*is_clean)(struct dm_dirty_log *log, region_t region); 166*7c604eeaShaad * 167*7c604eeaShaad * Payload-to-userspace: 168*7c604eeaShaad * uint64_t - the region to get clean status on 169*7c604eeaShaad * Payload-to-kernel: 170*7c604eeaShaad * int64_t - 1 if clean, 0 otherwise 171*7c604eeaShaad * 172*7c604eeaShaad * Payload is sizeof(uint64_t) and contains the region for which the clean 173*7c604eeaShaad * status is being made. 174*7c604eeaShaad * 175*7c604eeaShaad * When the request has been processed, user-space must return the 176*7c604eeaShaad * dm_ulog_request to the kernel - filling the payload with 0 (not clean) or 177*7c604eeaShaad * 1 (clean), setting 'data_size' and 'error' appropriately. 178*7c604eeaShaad */ 179*7c604eeaShaad #define DM_ULOG_IS_CLEAN 7 180*7c604eeaShaad 181*7c604eeaShaad /* 182*7c604eeaShaad * DM_ULOG_IN_SYNC corresponds to (found in dm-dirty-log.h): 183*7c604eeaShaad * int (*in_sync)(struct dm_dirty_log *log, region_t region, 184*7c604eeaShaad * int can_block); 185*7c604eeaShaad * 186*7c604eeaShaad * Payload-to-userspace: 187*7c604eeaShaad * uint64_t - the region to get sync status on 188*7c604eeaShaad * Payload-to-kernel: 189*7c604eeaShaad * int64_t - 1 if in-sync, 0 otherwise 190*7c604eeaShaad * 191*7c604eeaShaad * Exactly the same as 'is_clean' above, except this time asking "has the 192*7c604eeaShaad * region been recovered?" vs. "is the region not being modified?" 193*7c604eeaShaad */ 194*7c604eeaShaad #define DM_ULOG_IN_SYNC 8 195*7c604eeaShaad 196*7c604eeaShaad /* 197*7c604eeaShaad * DM_ULOG_FLUSH corresponds to (found in dm-dirty-log.h): 198*7c604eeaShaad * int (*flush)(struct dm_dirty_log *log); 199*7c604eeaShaad * 200*7c604eeaShaad * Payload-to-userspace: 201*7c604eeaShaad * None. 202*7c604eeaShaad * Payload-to-kernel: 203*7c604eeaShaad * None. 204*7c604eeaShaad * 205*7c604eeaShaad * No incoming or outgoing payload. Simply flush log state to disk. 206*7c604eeaShaad * 207*7c604eeaShaad * When the request has been processed, user-space must return the 208*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and clearing 209*7c604eeaShaad * 'data_size' appropriately. 210*7c604eeaShaad */ 211*7c604eeaShaad #define DM_ULOG_FLUSH 9 212*7c604eeaShaad 213*7c604eeaShaad /* 214*7c604eeaShaad * DM_ULOG_MARK_REGION corresponds to (found in dm-dirty-log.h): 215*7c604eeaShaad * void (*mark_region)(struct dm_dirty_log *log, region_t region); 216*7c604eeaShaad * 217*7c604eeaShaad * Payload-to-userspace: 218*7c604eeaShaad * uint64_t [] - region(s) to mark 219*7c604eeaShaad * Payload-to-kernel: 220*7c604eeaShaad * None. 221*7c604eeaShaad * 222*7c604eeaShaad * Incoming payload contains the one or more regions to mark dirty. 223*7c604eeaShaad * The number of regions contained in the payload can be determined from 224*7c604eeaShaad * 'data_size/sizeof(uint64_t)'. 225*7c604eeaShaad * 226*7c604eeaShaad * When the request has been processed, user-space must return the 227*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and clearing 228*7c604eeaShaad * 'data_size' appropriately. 229*7c604eeaShaad */ 230*7c604eeaShaad #define DM_ULOG_MARK_REGION 10 231*7c604eeaShaad 232*7c604eeaShaad /* 233*7c604eeaShaad * DM_ULOG_CLEAR_REGION corresponds to (found in dm-dirty-log.h): 234*7c604eeaShaad * void (*clear_region)(struct dm_dirty_log *log, region_t region); 235*7c604eeaShaad * 236*7c604eeaShaad * Payload-to-userspace: 237*7c604eeaShaad * uint64_t [] - region(s) to clear 238*7c604eeaShaad * Payload-to-kernel: 239*7c604eeaShaad * None. 240*7c604eeaShaad * 241*7c604eeaShaad * Incoming payload contains the one or more regions to mark clean. 242*7c604eeaShaad * The number of regions contained in the payload can be determined from 243*7c604eeaShaad * 'data_size/sizeof(uint64_t)'. 244*7c604eeaShaad * 245*7c604eeaShaad * When the request has been processed, user-space must return the 246*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and clearing 247*7c604eeaShaad * 'data_size' appropriately. 248*7c604eeaShaad */ 249*7c604eeaShaad #define DM_ULOG_CLEAR_REGION 11 250*7c604eeaShaad 251*7c604eeaShaad /* 252*7c604eeaShaad * DM_ULOG_GET_RESYNC_WORK corresponds to (found in dm-dirty-log.h): 253*7c604eeaShaad * int (*get_resync_work)(struct dm_dirty_log *log, region_t *region); 254*7c604eeaShaad * 255*7c604eeaShaad * Payload-to-userspace: 256*7c604eeaShaad * None. 257*7c604eeaShaad * Payload-to-kernel: 258*7c604eeaShaad * { 259*7c604eeaShaad * int64_t i; -- 1 if recovery necessary, 0 otherwise 260*7c604eeaShaad * uint64_t r; -- The region to recover if i=1 261*7c604eeaShaad * } 262*7c604eeaShaad * 'data_size' should be set appropriately. 263*7c604eeaShaad * 264*7c604eeaShaad * When the request has been processed, user-space must return the 265*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field appropriately. 266*7c604eeaShaad */ 267*7c604eeaShaad #define DM_ULOG_GET_RESYNC_WORK 12 268*7c604eeaShaad 269*7c604eeaShaad /* 270*7c604eeaShaad * DM_ULOG_SET_REGION_SYNC corresponds to (found in dm-dirty-log.h): 271*7c604eeaShaad * void (*set_region_sync)(struct dm_dirty_log *log, 272*7c604eeaShaad * region_t region, int in_sync); 273*7c604eeaShaad * 274*7c604eeaShaad * Payload-to-userspace: 275*7c604eeaShaad * { 276*7c604eeaShaad * uint64_t - region to set sync state on 277*7c604eeaShaad * int64_t - 0 if not-in-sync, 1 if in-sync 278*7c604eeaShaad * } 279*7c604eeaShaad * Payload-to-kernel: 280*7c604eeaShaad * None. 281*7c604eeaShaad * 282*7c604eeaShaad * When the request has been processed, user-space must return the 283*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and clearing 284*7c604eeaShaad * 'data_size' appropriately. 285*7c604eeaShaad */ 286*7c604eeaShaad #define DM_ULOG_SET_REGION_SYNC 13 287*7c604eeaShaad 288*7c604eeaShaad /* 289*7c604eeaShaad * DM_ULOG_GET_SYNC_COUNT corresponds to (found in dm-dirty-log.h): 290*7c604eeaShaad * region_t (*get_sync_count)(struct dm_dirty_log *log); 291*7c604eeaShaad * 292*7c604eeaShaad * Payload-to-userspace: 293*7c604eeaShaad * None. 294*7c604eeaShaad * Payload-to-kernel: 295*7c604eeaShaad * uint64_t - the number of in-sync regions 296*7c604eeaShaad * 297*7c604eeaShaad * No incoming payload. Kernel-bound payload contains the number of 298*7c604eeaShaad * regions that are in-sync (in a size_t). 299*7c604eeaShaad * 300*7c604eeaShaad * When the request has been processed, user-space must return the 301*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and 302*7c604eeaShaad * 'data_size' appropriately. 303*7c604eeaShaad */ 304*7c604eeaShaad #define DM_ULOG_GET_SYNC_COUNT 14 305*7c604eeaShaad 306*7c604eeaShaad /* 307*7c604eeaShaad * DM_ULOG_STATUS_INFO corresponds to (found in dm-dirty-log.h): 308*7c604eeaShaad * int (*status)(struct dm_dirty_log *log, STATUSTYPE_INFO, 309*7c604eeaShaad * char *result, unsigned maxlen); 310*7c604eeaShaad * 311*7c604eeaShaad * Payload-to-userspace: 312*7c604eeaShaad * None. 313*7c604eeaShaad * Payload-to-kernel: 314*7c604eeaShaad * Character string containing STATUSTYPE_INFO 315*7c604eeaShaad * 316*7c604eeaShaad * When the request has been processed, user-space must return the 317*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and 318*7c604eeaShaad * 'data_size' appropriately. 319*7c604eeaShaad */ 320*7c604eeaShaad #define DM_ULOG_STATUS_INFO 15 321*7c604eeaShaad 322*7c604eeaShaad /* 323*7c604eeaShaad * DM_ULOG_STATUS_TABLE corresponds to (found in dm-dirty-log.h): 324*7c604eeaShaad * int (*status)(struct dm_dirty_log *log, STATUSTYPE_TABLE, 325*7c604eeaShaad * char *result, unsigned maxlen); 326*7c604eeaShaad * 327*7c604eeaShaad * Payload-to-userspace: 328*7c604eeaShaad * None. 329*7c604eeaShaad * Payload-to-kernel: 330*7c604eeaShaad * Character string containing STATUSTYPE_TABLE 331*7c604eeaShaad * 332*7c604eeaShaad * When the request has been processed, user-space must return the 333*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and 334*7c604eeaShaad * 'data_size' appropriately. 335*7c604eeaShaad */ 336*7c604eeaShaad #define DM_ULOG_STATUS_TABLE 16 337*7c604eeaShaad 338*7c604eeaShaad /* 339*7c604eeaShaad * DM_ULOG_IS_REMOTE_RECOVERING corresponds to (found in dm-dirty-log.h): 340*7c604eeaShaad * int (*is_remote_recovering)(struct dm_dirty_log *log, region_t region); 341*7c604eeaShaad * 342*7c604eeaShaad * Payload-to-userspace: 343*7c604eeaShaad * uint64_t - region to determine recovery status on 344*7c604eeaShaad * Payload-to-kernel: 345*7c604eeaShaad * { 346*7c604eeaShaad * int64_t is_recovering; -- 0 if no, 1 if yes 347*7c604eeaShaad * uint64_t in_sync_hint; -- lowest region still needing resync 348*7c604eeaShaad * } 349*7c604eeaShaad * 350*7c604eeaShaad * When the request has been processed, user-space must return the 351*7c604eeaShaad * dm_ulog_request to the kernel - setting the 'error' field and 352*7c604eeaShaad * 'data_size' appropriately. 353*7c604eeaShaad */ 354*7c604eeaShaad #define DM_ULOG_IS_REMOTE_RECOVERING 17 355*7c604eeaShaad 356*7c604eeaShaad /* 357*7c604eeaShaad * (DM_ULOG_REQUEST_MASK & request_type) to get the request type 358*7c604eeaShaad * 359*7c604eeaShaad * Payload-to-userspace: 360*7c604eeaShaad * A single string containing all the argv arguments separated by ' 's 361*7c604eeaShaad * Payload-to-kernel: 362*7c604eeaShaad * None. ('data_size' in the dm_ulog_request struct should be 0.) 363*7c604eeaShaad * 364*7c604eeaShaad * We are reserving 8 bits of the 32-bit 'request_type' field for the 365*7c604eeaShaad * various request types above. The remaining 24-bits are currently 366*7c604eeaShaad * set to zero and are reserved for future use and compatibility concerns. 367*7c604eeaShaad * 368*7c604eeaShaad * User-space should always use DM_ULOG_REQUEST_TYPE to aquire the 369*7c604eeaShaad * request type from the 'request_type' field to maintain forward compatibility. 370*7c604eeaShaad */ 371*7c604eeaShaad #define DM_ULOG_REQUEST_MASK 0xFF 372*7c604eeaShaad #define DM_ULOG_REQUEST_TYPE(request_type) \ 373*7c604eeaShaad (DM_ULOG_REQUEST_MASK & (request_type)) 374*7c604eeaShaad 375*7c604eeaShaad struct dm_ulog_request { 376*7c604eeaShaad /* 377*7c604eeaShaad * The local unique identifier (luid) and the universally unique 378*7c604eeaShaad * identifier (uuid) are used to tie a request to a specific 379*7c604eeaShaad * mirror log. A single machine log could probably make due with 380*7c604eeaShaad * just the 'luid', but a cluster-aware log must use the 'uuid' and 381*7c604eeaShaad * the 'luid'. The uuid is what is required for node to node 382*7c604eeaShaad * communication concerning a particular log, but the 'luid' helps 383*7c604eeaShaad * differentiate between logs that are being swapped and have the 384*7c604eeaShaad * same 'uuid'. (Think "live" and "inactive" device-mapper tables.) 385*7c604eeaShaad */ 386*7c604eeaShaad uint64_t luid; 387*7c604eeaShaad char uuid[DM_UUID_LEN]; 388*7c604eeaShaad char padding[7]; /* Padding because DM_UUID_LEN = 129 */ 389*7c604eeaShaad 390*7c604eeaShaad int32_t error; /* Used to report back processing errors */ 391*7c604eeaShaad 392*7c604eeaShaad uint32_t seq; /* Sequence number for request */ 393*7c604eeaShaad uint32_t request_type; /* DM_ULOG_* defined above */ 394*7c604eeaShaad uint32_t data_size; /* How much data (not including this struct) */ 395*7c604eeaShaad 396*7c604eeaShaad char data[0]; 397*7c604eeaShaad }; 398*7c604eeaShaad 399*7c604eeaShaad #endif /* __DM_LOG_USERSPACE_H__ */ 400