1 // SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 2 3 #include <net/netlink.h> 4 #include <net/genetlink.h> 5 6 #include <linux/kernel.h> 7 #include <linux/slab.h> 8 #include "drbd_nl_gen.h" 9 10 #include <uapi/linux/drbd_genl.h> 11 #include <linux/drbd.h> 12 #include <linux/drbd_limits.h> 13 14 /* Common nested types */ 15 const struct nla_policy drbd_connection_info_nl_policy[DRBD_A_CONNECTION_INFO_CONN_ROLE + 1] = { 16 [DRBD_A_CONNECTION_INFO_CONN_CONNECTION_STATE] = { .type = NLA_U32, }, 17 [DRBD_A_CONNECTION_INFO_CONN_ROLE] = { .type = NLA_U32, }, 18 }; 19 20 const struct nla_policy drbd_connection_statistics_nl_policy[DRBD_A_CONNECTION_STATISTICS_CONN_CONGESTED + 1] = { 21 [DRBD_A_CONNECTION_STATISTICS_CONN_CONGESTED] = { .type = NLA_U8, }, 22 }; 23 24 const struct nla_policy drbd_detach_parms_nl_policy[DRBD_A_DETACH_PARMS_FORCE_DETACH + 1] = { 25 [DRBD_A_DETACH_PARMS_FORCE_DETACH] = { .type = NLA_U8, }, 26 }; 27 28 const struct nla_policy drbd_device_info_nl_policy[DRBD_A_DEVICE_INFO_DEV_DISK_STATE + 1] = { 29 [DRBD_A_DEVICE_INFO_DEV_DISK_STATE] = { .type = NLA_U32, }, 30 }; 31 32 const struct nla_policy drbd_device_statistics_nl_policy[DRBD_A_DEVICE_STATISTICS_HISTORY_UUIDS + 1] = { 33 [DRBD_A_DEVICE_STATISTICS_DEV_SIZE] = { .type = NLA_U64, }, 34 [DRBD_A_DEVICE_STATISTICS_DEV_READ] = { .type = NLA_U64, }, 35 [DRBD_A_DEVICE_STATISTICS_DEV_WRITE] = { .type = NLA_U64, }, 36 [DRBD_A_DEVICE_STATISTICS_DEV_AL_WRITES] = { .type = NLA_U64, }, 37 [DRBD_A_DEVICE_STATISTICS_DEV_BM_WRITES] = { .type = NLA_U64, }, 38 [DRBD_A_DEVICE_STATISTICS_DEV_UPPER_PENDING] = { .type = NLA_U32, }, 39 [DRBD_A_DEVICE_STATISTICS_DEV_LOWER_PENDING] = { .type = NLA_U32, }, 40 [DRBD_A_DEVICE_STATISTICS_DEV_UPPER_BLOCKED] = { .type = NLA_U8, }, 41 [DRBD_A_DEVICE_STATISTICS_DEV_LOWER_BLOCKED] = { .type = NLA_U8, }, 42 [DRBD_A_DEVICE_STATISTICS_DEV_AL_SUSPENDED] = { .type = NLA_U8, }, 43 [DRBD_A_DEVICE_STATISTICS_DEV_EXPOSED_DATA_UUID] = { .type = NLA_U64, }, 44 [DRBD_A_DEVICE_STATISTICS_DEV_CURRENT_UUID] = { .type = NLA_U64, }, 45 [DRBD_A_DEVICE_STATISTICS_DEV_DISK_FLAGS] = { .type = NLA_U32, }, 46 [DRBD_A_DEVICE_STATISTICS_HISTORY_UUIDS] = NLA_POLICY_MAX_LEN(DRBD_NL_HISTORY_UUIDS_SIZE), 47 }; 48 49 const struct nla_policy drbd_disconnect_parms_nl_policy[DRBD_A_DISCONNECT_PARMS_FORCE_DISCONNECT + 1] = { 50 [DRBD_A_DISCONNECT_PARMS_FORCE_DISCONNECT] = { .type = NLA_U8, }, 51 }; 52 53 const struct nla_policy drbd_disk_conf_nl_policy[DRBD_A_DISK_CONF_DISABLE_WRITE_SAME + 1] = { 54 [DRBD_A_DISK_CONF_BACKING_DEV] = { .type = NLA_NUL_STRING, .len = 128, }, 55 [DRBD_A_DISK_CONF_META_DEV] = { .type = NLA_NUL_STRING, .len = 128, }, 56 [DRBD_A_DISK_CONF_META_DEV_IDX] = { .type = NLA_U32, }, 57 [DRBD_A_DISK_CONF_DISK_SIZE] = { .type = NLA_U64, }, 58 [DRBD_A_DISK_CONF_MAX_BIO_BVECS] = { .type = NLA_U32, }, 59 [DRBD_A_DISK_CONF_ON_IO_ERROR] = { .type = NLA_U32, }, 60 [DRBD_A_DISK_CONF_FENCING] = { .type = NLA_U32, }, 61 [DRBD_A_DISK_CONF_RESYNC_RATE] = { .type = NLA_U32, }, 62 [DRBD_A_DISK_CONF_RESYNC_AFTER] = { .type = NLA_U32, }, 63 [DRBD_A_DISK_CONF_AL_EXTENTS] = { .type = NLA_U32, }, 64 [DRBD_A_DISK_CONF_C_PLAN_AHEAD] = { .type = NLA_U32, }, 65 [DRBD_A_DISK_CONF_C_DELAY_TARGET] = { .type = NLA_U32, }, 66 [DRBD_A_DISK_CONF_C_FILL_TARGET] = { .type = NLA_U32, }, 67 [DRBD_A_DISK_CONF_C_MAX_RATE] = { .type = NLA_U32, }, 68 [DRBD_A_DISK_CONF_C_MIN_RATE] = { .type = NLA_U32, }, 69 [DRBD_A_DISK_CONF_DISK_BARRIER] = { .type = NLA_U8, }, 70 [DRBD_A_DISK_CONF_DISK_FLUSHES] = { .type = NLA_U8, }, 71 [DRBD_A_DISK_CONF_DISK_DRAIN] = { .type = NLA_U8, }, 72 [DRBD_A_DISK_CONF_MD_FLUSHES] = { .type = NLA_U8, }, 73 [DRBD_A_DISK_CONF_DISK_TIMEOUT] = { .type = NLA_U32, }, 74 [DRBD_A_DISK_CONF_READ_BALANCING] = { .type = NLA_U32, }, 75 [DRBD_A_DISK_CONF_AL_UPDATES] = { .type = NLA_U8, }, 76 [DRBD_A_DISK_CONF_DISCARD_ZEROES_IF_ALIGNED] = { .type = NLA_U8, }, 77 [DRBD_A_DISK_CONF_RS_DISCARD_GRANULARITY] = { .type = NLA_U32, }, 78 [DRBD_A_DISK_CONF_DISABLE_WRITE_SAME] = { .type = NLA_U8, }, 79 }; 80 81 const struct nla_policy drbd_drbd_cfg_context_nl_policy[DRBD_A_DRBD_CFG_CONTEXT_CTX_PEER_ADDR + 1] = { 82 [DRBD_A_DRBD_CFG_CONTEXT_CTX_VOLUME] = { .type = NLA_U32, }, 83 [DRBD_A_DRBD_CFG_CONTEXT_CTX_RESOURCE_NAME] = { .type = NLA_NUL_STRING, .len = 128, }, 84 [DRBD_A_DRBD_CFG_CONTEXT_CTX_MY_ADDR] = NLA_POLICY_MAX_LEN(128), 85 [DRBD_A_DRBD_CFG_CONTEXT_CTX_PEER_ADDR] = NLA_POLICY_MAX_LEN(128), 86 }; 87 88 const struct nla_policy drbd_net_conf_nl_policy[DRBD_A_NET_CONF_SOCK_CHECK_TIMEO + 1] = { 89 [DRBD_A_NET_CONF_SHARED_SECRET] = { .type = NLA_NUL_STRING, .len = SHARED_SECRET_MAX, }, 90 [DRBD_A_NET_CONF_CRAM_HMAC_ALG] = { .type = NLA_NUL_STRING, .len = SHARED_SECRET_MAX, }, 91 [DRBD_A_NET_CONF_INTEGRITY_ALG] = { .type = NLA_NUL_STRING, .len = SHARED_SECRET_MAX, }, 92 [DRBD_A_NET_CONF_VERIFY_ALG] = { .type = NLA_NUL_STRING, .len = SHARED_SECRET_MAX, }, 93 [DRBD_A_NET_CONF_CSUMS_ALG] = { .type = NLA_NUL_STRING, .len = SHARED_SECRET_MAX, }, 94 [DRBD_A_NET_CONF_WIRE_PROTOCOL] = { .type = NLA_U32, }, 95 [DRBD_A_NET_CONF_CONNECT_INT] = { .type = NLA_U32, }, 96 [DRBD_A_NET_CONF_TIMEOUT] = { .type = NLA_U32, }, 97 [DRBD_A_NET_CONF_PING_INT] = { .type = NLA_U32, }, 98 [DRBD_A_NET_CONF_PING_TIMEO] = { .type = NLA_U32, }, 99 [DRBD_A_NET_CONF_SNDBUF_SIZE] = { .type = NLA_U32, }, 100 [DRBD_A_NET_CONF_RCVBUF_SIZE] = { .type = NLA_U32, }, 101 [DRBD_A_NET_CONF_KO_COUNT] = { .type = NLA_U32, }, 102 [DRBD_A_NET_CONF_MAX_BUFFERS] = { .type = NLA_U32, }, 103 [DRBD_A_NET_CONF_MAX_EPOCH_SIZE] = { .type = NLA_U32, }, 104 [DRBD_A_NET_CONF_UNPLUG_WATERMARK] = { .type = NLA_U32, }, 105 [DRBD_A_NET_CONF_AFTER_SB_0P] = { .type = NLA_U32, }, 106 [DRBD_A_NET_CONF_AFTER_SB_1P] = { .type = NLA_U32, }, 107 [DRBD_A_NET_CONF_AFTER_SB_2P] = { .type = NLA_U32, }, 108 [DRBD_A_NET_CONF_RR_CONFLICT] = { .type = NLA_U32, }, 109 [DRBD_A_NET_CONF_ON_CONGESTION] = { .type = NLA_U32, }, 110 [DRBD_A_NET_CONF_CONG_FILL] = { .type = NLA_U32, }, 111 [DRBD_A_NET_CONF_CONG_EXTENTS] = { .type = NLA_U32, }, 112 [DRBD_A_NET_CONF_TWO_PRIMARIES] = { .type = NLA_U8, }, 113 [DRBD_A_NET_CONF_DISCARD_MY_DATA] = { .type = NLA_U8, }, 114 [DRBD_A_NET_CONF_TCP_CORK] = { .type = NLA_U8, }, 115 [DRBD_A_NET_CONF_ALWAYS_ASBP] = { .type = NLA_U8, }, 116 [DRBD_A_NET_CONF_TENTATIVE] = { .type = NLA_U8, }, 117 [DRBD_A_NET_CONF_USE_RLE] = { .type = NLA_U8, }, 118 [DRBD_A_NET_CONF_CSUMS_AFTER_CRASH_ONLY] = { .type = NLA_U8, }, 119 [DRBD_A_NET_CONF_SOCK_CHECK_TIMEO] = { .type = NLA_U32, }, 120 }; 121 122 const struct nla_policy drbd_new_c_uuid_parms_nl_policy[DRBD_A_NEW_C_UUID_PARMS_CLEAR_BM + 1] = { 123 [DRBD_A_NEW_C_UUID_PARMS_CLEAR_BM] = { .type = NLA_U8, }, 124 }; 125 126 const struct nla_policy drbd_peer_device_info_nl_policy[DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_DEPENDENCY + 1] = { 127 [DRBD_A_PEER_DEVICE_INFO_PEER_REPL_STATE] = { .type = NLA_U32, }, 128 [DRBD_A_PEER_DEVICE_INFO_PEER_DISK_STATE] = { .type = NLA_U32, }, 129 [DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_USER] = { .type = NLA_U32, }, 130 [DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_PEER] = { .type = NLA_U32, }, 131 [DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_DEPENDENCY] = { .type = NLA_U32, }, 132 }; 133 134 const struct nla_policy drbd_peer_device_statistics_nl_policy[DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_FLAGS + 1] = { 135 [DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_RECEIVED] = { .type = NLA_U64, }, 136 [DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_SENT] = { .type = NLA_U64, }, 137 [DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_PENDING] = { .type = NLA_U32, }, 138 [DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_UNACKED] = { .type = NLA_U32, }, 139 [DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_OUT_OF_SYNC] = { .type = NLA_U64, }, 140 [DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_RESYNC_FAILED] = { .type = NLA_U64, }, 141 [DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_BITMAP_UUID] = { .type = NLA_U64, }, 142 [DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_FLAGS] = { .type = NLA_U32, }, 143 }; 144 145 const struct nla_policy drbd_res_opts_nl_policy[DRBD_A_RES_OPTS_ON_NO_DATA + 1] = { 146 [DRBD_A_RES_OPTS_CPU_MASK] = { .type = NLA_NUL_STRING, .len = DRBD_CPU_MASK_SIZE, }, 147 [DRBD_A_RES_OPTS_ON_NO_DATA] = { .type = NLA_U32, }, 148 }; 149 150 const struct nla_policy drbd_resize_parms_nl_policy[DRBD_A_RESIZE_PARMS_AL_STRIPE_SIZE + 1] = { 151 [DRBD_A_RESIZE_PARMS_RESIZE_SIZE] = { .type = NLA_U64, }, 152 [DRBD_A_RESIZE_PARMS_RESIZE_FORCE] = { .type = NLA_U8, }, 153 [DRBD_A_RESIZE_PARMS_NO_RESYNC] = { .type = NLA_U8, }, 154 [DRBD_A_RESIZE_PARMS_AL_STRIPES] = { .type = NLA_U32, }, 155 [DRBD_A_RESIZE_PARMS_AL_STRIPE_SIZE] = { .type = NLA_U32, }, 156 }; 157 158 const struct nla_policy drbd_resource_info_nl_policy[DRBD_A_RESOURCE_INFO_RES_SUSP_FEN + 1] = { 159 [DRBD_A_RESOURCE_INFO_RES_ROLE] = { .type = NLA_U32, }, 160 [DRBD_A_RESOURCE_INFO_RES_SUSP] = { .type = NLA_U8, }, 161 [DRBD_A_RESOURCE_INFO_RES_SUSP_NOD] = { .type = NLA_U8, }, 162 [DRBD_A_RESOURCE_INFO_RES_SUSP_FEN] = { .type = NLA_U8, }, 163 }; 164 165 const struct nla_policy drbd_resource_statistics_nl_policy[DRBD_A_RESOURCE_STATISTICS_RES_STAT_WRITE_ORDERING + 1] = { 166 [DRBD_A_RESOURCE_STATISTICS_RES_STAT_WRITE_ORDERING] = { .type = NLA_U32, }, 167 }; 168 169 const struct nla_policy drbd_set_role_parms_nl_policy[DRBD_A_SET_ROLE_PARMS_ASSUME_UPTODATE + 1] = { 170 [DRBD_A_SET_ROLE_PARMS_ASSUME_UPTODATE] = { .type = NLA_U8, }, 171 }; 172 173 const struct nla_policy drbd_start_ov_parms_nl_policy[DRBD_A_START_OV_PARMS_OV_STOP_SECTOR + 1] = { 174 [DRBD_A_START_OV_PARMS_OV_START_SECTOR] = { .type = NLA_U64, }, 175 [DRBD_A_START_OV_PARMS_OV_STOP_SECTOR] = { .type = NLA_U64, }, 176 }; 177 178 /* DRBD_ADM_GET_STATUS - do */ 179 static const struct nla_policy drbd_get_status_do_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 180 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 181 }; 182 183 /* DRBD_ADM_GET_STATUS - dump */ 184 static const struct nla_policy drbd_get_status_dump_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 185 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 186 }; 187 188 /* DRBD_ADM_NEW_MINOR - do */ 189 static const struct nla_policy drbd_new_minor_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 190 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 191 }; 192 193 /* DRBD_ADM_DEL_MINOR - do */ 194 static const struct nla_policy drbd_del_minor_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 195 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 196 }; 197 198 /* DRBD_ADM_NEW_RESOURCE - do */ 199 static const struct nla_policy drbd_new_resource_nl_policy[DRBD_NLA_RESOURCE_OPTS + 1] = { 200 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 201 [DRBD_NLA_RESOURCE_OPTS] = NLA_POLICY_NESTED(drbd_res_opts_nl_policy), 202 }; 203 204 /* DRBD_ADM_DEL_RESOURCE - do */ 205 static const struct nla_policy drbd_del_resource_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 206 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 207 }; 208 209 /* DRBD_ADM_RESOURCE_OPTS - do */ 210 static const struct nla_policy drbd_resource_opts_nl_policy[DRBD_NLA_RESOURCE_OPTS + 1] = { 211 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 212 [DRBD_NLA_RESOURCE_OPTS] = NLA_POLICY_NESTED(drbd_res_opts_nl_policy), 213 }; 214 215 /* DRBD_ADM_CONNECT - do */ 216 static const struct nla_policy drbd_connect_nl_policy[DRBD_NLA_NET_CONF + 1] = { 217 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 218 [DRBD_NLA_NET_CONF] = NLA_POLICY_NESTED(drbd_net_conf_nl_policy), 219 }; 220 221 /* DRBD_ADM_DISCONNECT - do */ 222 static const struct nla_policy drbd_disconnect_nl_policy[DRBD_NLA_DISCONNECT_PARMS + 1] = { 223 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 224 [DRBD_NLA_DISCONNECT_PARMS] = NLA_POLICY_NESTED(drbd_disconnect_parms_nl_policy), 225 }; 226 227 /* DRBD_ADM_ATTACH - do */ 228 static const struct nla_policy drbd_attach_nl_policy[DRBD_NLA_DISK_CONF + 1] = { 229 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 230 [DRBD_NLA_DISK_CONF] = NLA_POLICY_NESTED(drbd_disk_conf_nl_policy), 231 }; 232 233 /* DRBD_ADM_RESIZE - do */ 234 static const struct nla_policy drbd_resize_nl_policy[DRBD_NLA_RESIZE_PARMS + 1] = { 235 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 236 [DRBD_NLA_RESIZE_PARMS] = NLA_POLICY_NESTED(drbd_resize_parms_nl_policy), 237 }; 238 239 /* DRBD_ADM_PRIMARY - do */ 240 static const struct nla_policy drbd_primary_nl_policy[DRBD_NLA_SET_ROLE_PARMS + 1] = { 241 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 242 [DRBD_NLA_SET_ROLE_PARMS] = NLA_POLICY_NESTED(drbd_set_role_parms_nl_policy), 243 }; 244 245 /* DRBD_ADM_SECONDARY - do */ 246 static const struct nla_policy drbd_secondary_nl_policy[DRBD_NLA_SET_ROLE_PARMS + 1] = { 247 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 248 [DRBD_NLA_SET_ROLE_PARMS] = NLA_POLICY_NESTED(drbd_set_role_parms_nl_policy), 249 }; 250 251 /* DRBD_ADM_NEW_C_UUID - do */ 252 static const struct nla_policy drbd_new_c_uuid_nl_policy[DRBD_NLA_NEW_C_UUID_PARMS + 1] = { 253 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 254 [DRBD_NLA_NEW_C_UUID_PARMS] = NLA_POLICY_NESTED(drbd_new_c_uuid_parms_nl_policy), 255 }; 256 257 /* DRBD_ADM_START_OV - do */ 258 static const struct nla_policy drbd_start_ov_nl_policy[DRBD_NLA_START_OV_PARMS + 1] = { 259 [DRBD_NLA_START_OV_PARMS] = NLA_POLICY_NESTED(drbd_start_ov_parms_nl_policy), 260 }; 261 262 /* DRBD_ADM_DETACH - do */ 263 static const struct nla_policy drbd_detach_nl_policy[DRBD_NLA_DETACH_PARMS + 1] = { 264 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 265 [DRBD_NLA_DETACH_PARMS] = NLA_POLICY_NESTED(drbd_detach_parms_nl_policy), 266 }; 267 268 /* DRBD_ADM_INVALIDATE - do */ 269 static const struct nla_policy drbd_invalidate_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 270 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 271 }; 272 273 /* DRBD_ADM_INVAL_PEER - do */ 274 static const struct nla_policy drbd_inval_peer_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 275 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 276 }; 277 278 /* DRBD_ADM_PAUSE_SYNC - do */ 279 static const struct nla_policy drbd_pause_sync_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 280 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 281 }; 282 283 /* DRBD_ADM_RESUME_SYNC - do */ 284 static const struct nla_policy drbd_resume_sync_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 285 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 286 }; 287 288 /* DRBD_ADM_SUSPEND_IO - do */ 289 static const struct nla_policy drbd_suspend_io_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 290 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 291 }; 292 293 /* DRBD_ADM_RESUME_IO - do */ 294 static const struct nla_policy drbd_resume_io_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 295 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 296 }; 297 298 /* DRBD_ADM_OUTDATE - do */ 299 static const struct nla_policy drbd_outdate_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 300 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 301 }; 302 303 /* DRBD_ADM_GET_TIMEOUT_TYPE - do */ 304 static const struct nla_policy drbd_get_timeout_type_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 305 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 306 }; 307 308 /* DRBD_ADM_DOWN - do */ 309 static const struct nla_policy drbd_down_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 310 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 311 }; 312 313 /* DRBD_ADM_CHG_DISK_OPTS - do */ 314 static const struct nla_policy drbd_chg_disk_opts_nl_policy[DRBD_NLA_DISK_CONF + 1] = { 315 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 316 [DRBD_NLA_DISK_CONF] = NLA_POLICY_NESTED(drbd_disk_conf_nl_policy), 317 }; 318 319 /* DRBD_ADM_CHG_NET_OPTS - do */ 320 static const struct nla_policy drbd_chg_net_opts_nl_policy[DRBD_NLA_NET_CONF + 1] = { 321 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 322 [DRBD_NLA_NET_CONF] = NLA_POLICY_NESTED(drbd_net_conf_nl_policy), 323 }; 324 325 /* DRBD_ADM_GET_RESOURCES - dump */ 326 static const struct nla_policy drbd_get_resources_nl_policy[DRBD_NLA_RESOURCE_STATISTICS + 1] = { 327 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 328 [DRBD_NLA_RESOURCE_INFO] = NLA_POLICY_NESTED(drbd_resource_info_nl_policy), 329 [DRBD_NLA_RESOURCE_STATISTICS] = NLA_POLICY_NESTED(drbd_resource_statistics_nl_policy), 330 }; 331 332 /* DRBD_ADM_GET_DEVICES - dump */ 333 static const struct nla_policy drbd_get_devices_nl_policy[DRBD_NLA_DEVICE_STATISTICS + 1] = { 334 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 335 [DRBD_NLA_DEVICE_INFO] = NLA_POLICY_NESTED(drbd_device_info_nl_policy), 336 [DRBD_NLA_DEVICE_STATISTICS] = NLA_POLICY_NESTED(drbd_device_statistics_nl_policy), 337 }; 338 339 /* DRBD_ADM_GET_CONNECTIONS - dump */ 340 static const struct nla_policy drbd_get_connections_nl_policy[DRBD_NLA_CONNECTION_STATISTICS + 1] = { 341 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 342 [DRBD_NLA_CONNECTION_INFO] = NLA_POLICY_NESTED(drbd_connection_info_nl_policy), 343 [DRBD_NLA_CONNECTION_STATISTICS] = NLA_POLICY_NESTED(drbd_connection_statistics_nl_policy), 344 }; 345 346 /* DRBD_ADM_GET_PEER_DEVICES - dump */ 347 static const struct nla_policy drbd_get_peer_devices_nl_policy[DRBD_NLA_PEER_DEVICE_STATISTICS + 1] = { 348 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 349 [DRBD_NLA_PEER_DEVICE_INFO] = NLA_POLICY_NESTED(drbd_peer_device_info_nl_policy), 350 [DRBD_NLA_PEER_DEVICE_STATISTICS] = NLA_POLICY_NESTED(drbd_peer_device_statistics_nl_policy), 351 }; 352 353 /* DRBD_ADM_GET_INITIAL_STATE - dump */ 354 static const struct nla_policy drbd_get_initial_state_nl_policy[DRBD_NLA_CFG_CONTEXT + 1] = { 355 [DRBD_NLA_CFG_CONTEXT] = NLA_POLICY_NESTED(drbd_drbd_cfg_context_nl_policy), 356 }; 357 358 /* Ops table for drbd */ 359 const struct genl_split_ops drbd_nl_ops[32] = { 360 { 361 .cmd = DRBD_ADM_GET_STATUS, 362 .pre_doit = drbd_pre_doit, 363 .doit = drbd_nl_get_status_doit, 364 .post_doit = drbd_post_doit, 365 .policy = drbd_get_status_do_nl_policy, 366 .maxattr = DRBD_NLA_CFG_CONTEXT, 367 .flags = GENL_CMD_CAP_DO, 368 }, 369 { 370 .cmd = DRBD_ADM_GET_STATUS, 371 .dumpit = drbd_nl_get_status_dumpit, 372 .policy = drbd_get_status_dump_nl_policy, 373 .maxattr = DRBD_NLA_CFG_CONTEXT, 374 .flags = GENL_CMD_CAP_DUMP, 375 }, 376 { 377 .cmd = DRBD_ADM_NEW_MINOR, 378 .pre_doit = drbd_pre_doit, 379 .doit = drbd_nl_new_minor_doit, 380 .post_doit = drbd_post_doit, 381 .policy = drbd_new_minor_nl_policy, 382 .maxattr = DRBD_NLA_CFG_CONTEXT, 383 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 384 }, 385 { 386 .cmd = DRBD_ADM_DEL_MINOR, 387 .pre_doit = drbd_pre_doit, 388 .doit = drbd_nl_del_minor_doit, 389 .post_doit = drbd_post_doit, 390 .policy = drbd_del_minor_nl_policy, 391 .maxattr = DRBD_NLA_CFG_CONTEXT, 392 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 393 }, 394 { 395 .cmd = DRBD_ADM_NEW_RESOURCE, 396 .pre_doit = drbd_pre_doit, 397 .doit = drbd_nl_new_resource_doit, 398 .post_doit = drbd_post_doit, 399 .policy = drbd_new_resource_nl_policy, 400 .maxattr = DRBD_NLA_RESOURCE_OPTS, 401 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 402 }, 403 { 404 .cmd = DRBD_ADM_DEL_RESOURCE, 405 .pre_doit = drbd_pre_doit, 406 .doit = drbd_nl_del_resource_doit, 407 .post_doit = drbd_post_doit, 408 .policy = drbd_del_resource_nl_policy, 409 .maxattr = DRBD_NLA_CFG_CONTEXT, 410 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 411 }, 412 { 413 .cmd = DRBD_ADM_RESOURCE_OPTS, 414 .pre_doit = drbd_pre_doit, 415 .doit = drbd_nl_resource_opts_doit, 416 .post_doit = drbd_post_doit, 417 .policy = drbd_resource_opts_nl_policy, 418 .maxattr = DRBD_NLA_RESOURCE_OPTS, 419 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 420 }, 421 { 422 .cmd = DRBD_ADM_CONNECT, 423 .pre_doit = drbd_pre_doit, 424 .doit = drbd_nl_connect_doit, 425 .post_doit = drbd_post_doit, 426 .policy = drbd_connect_nl_policy, 427 .maxattr = DRBD_NLA_NET_CONF, 428 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 429 }, 430 { 431 .cmd = DRBD_ADM_DISCONNECT, 432 .pre_doit = drbd_pre_doit, 433 .doit = drbd_nl_disconnect_doit, 434 .post_doit = drbd_post_doit, 435 .policy = drbd_disconnect_nl_policy, 436 .maxattr = DRBD_NLA_DISCONNECT_PARMS, 437 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 438 }, 439 { 440 .cmd = DRBD_ADM_ATTACH, 441 .pre_doit = drbd_pre_doit, 442 .doit = drbd_nl_attach_doit, 443 .post_doit = drbd_post_doit, 444 .policy = drbd_attach_nl_policy, 445 .maxattr = DRBD_NLA_DISK_CONF, 446 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 447 }, 448 { 449 .cmd = DRBD_ADM_RESIZE, 450 .pre_doit = drbd_pre_doit, 451 .doit = drbd_nl_resize_doit, 452 .post_doit = drbd_post_doit, 453 .policy = drbd_resize_nl_policy, 454 .maxattr = DRBD_NLA_RESIZE_PARMS, 455 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 456 }, 457 { 458 .cmd = DRBD_ADM_PRIMARY, 459 .pre_doit = drbd_pre_doit, 460 .doit = drbd_nl_primary_doit, 461 .post_doit = drbd_post_doit, 462 .policy = drbd_primary_nl_policy, 463 .maxattr = DRBD_NLA_SET_ROLE_PARMS, 464 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 465 }, 466 { 467 .cmd = DRBD_ADM_SECONDARY, 468 .pre_doit = drbd_pre_doit, 469 .doit = drbd_nl_secondary_doit, 470 .post_doit = drbd_post_doit, 471 .policy = drbd_secondary_nl_policy, 472 .maxattr = DRBD_NLA_SET_ROLE_PARMS, 473 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 474 }, 475 { 476 .cmd = DRBD_ADM_NEW_C_UUID, 477 .pre_doit = drbd_pre_doit, 478 .doit = drbd_nl_new_c_uuid_doit, 479 .post_doit = drbd_post_doit, 480 .policy = drbd_new_c_uuid_nl_policy, 481 .maxattr = DRBD_NLA_NEW_C_UUID_PARMS, 482 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 483 }, 484 { 485 .cmd = DRBD_ADM_START_OV, 486 .pre_doit = drbd_pre_doit, 487 .doit = drbd_nl_start_ov_doit, 488 .post_doit = drbd_post_doit, 489 .policy = drbd_start_ov_nl_policy, 490 .maxattr = DRBD_NLA_START_OV_PARMS, 491 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 492 }, 493 { 494 .cmd = DRBD_ADM_DETACH, 495 .pre_doit = drbd_pre_doit, 496 .doit = drbd_nl_detach_doit, 497 .post_doit = drbd_post_doit, 498 .policy = drbd_detach_nl_policy, 499 .maxattr = DRBD_NLA_DETACH_PARMS, 500 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 501 }, 502 { 503 .cmd = DRBD_ADM_INVALIDATE, 504 .pre_doit = drbd_pre_doit, 505 .doit = drbd_nl_invalidate_doit, 506 .post_doit = drbd_post_doit, 507 .policy = drbd_invalidate_nl_policy, 508 .maxattr = DRBD_NLA_CFG_CONTEXT, 509 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 510 }, 511 { 512 .cmd = DRBD_ADM_INVAL_PEER, 513 .pre_doit = drbd_pre_doit, 514 .doit = drbd_nl_inval_peer_doit, 515 .post_doit = drbd_post_doit, 516 .policy = drbd_inval_peer_nl_policy, 517 .maxattr = DRBD_NLA_CFG_CONTEXT, 518 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 519 }, 520 { 521 .cmd = DRBD_ADM_PAUSE_SYNC, 522 .pre_doit = drbd_pre_doit, 523 .doit = drbd_nl_pause_sync_doit, 524 .post_doit = drbd_post_doit, 525 .policy = drbd_pause_sync_nl_policy, 526 .maxattr = DRBD_NLA_CFG_CONTEXT, 527 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 528 }, 529 { 530 .cmd = DRBD_ADM_RESUME_SYNC, 531 .pre_doit = drbd_pre_doit, 532 .doit = drbd_nl_resume_sync_doit, 533 .post_doit = drbd_post_doit, 534 .policy = drbd_resume_sync_nl_policy, 535 .maxattr = DRBD_NLA_CFG_CONTEXT, 536 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 537 }, 538 { 539 .cmd = DRBD_ADM_SUSPEND_IO, 540 .pre_doit = drbd_pre_doit, 541 .doit = drbd_nl_suspend_io_doit, 542 .post_doit = drbd_post_doit, 543 .policy = drbd_suspend_io_nl_policy, 544 .maxattr = DRBD_NLA_CFG_CONTEXT, 545 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 546 }, 547 { 548 .cmd = DRBD_ADM_RESUME_IO, 549 .pre_doit = drbd_pre_doit, 550 .doit = drbd_nl_resume_io_doit, 551 .post_doit = drbd_post_doit, 552 .policy = drbd_resume_io_nl_policy, 553 .maxattr = DRBD_NLA_CFG_CONTEXT, 554 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 555 }, 556 { 557 .cmd = DRBD_ADM_OUTDATE, 558 .pre_doit = drbd_pre_doit, 559 .doit = drbd_nl_outdate_doit, 560 .post_doit = drbd_post_doit, 561 .policy = drbd_outdate_nl_policy, 562 .maxattr = DRBD_NLA_CFG_CONTEXT, 563 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 564 }, 565 { 566 .cmd = DRBD_ADM_GET_TIMEOUT_TYPE, 567 .pre_doit = drbd_pre_doit, 568 .doit = drbd_nl_get_timeout_type_doit, 569 .post_doit = drbd_post_doit, 570 .policy = drbd_get_timeout_type_nl_policy, 571 .maxattr = DRBD_NLA_CFG_CONTEXT, 572 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 573 }, 574 { 575 .cmd = DRBD_ADM_DOWN, 576 .pre_doit = drbd_pre_doit, 577 .doit = drbd_nl_down_doit, 578 .post_doit = drbd_post_doit, 579 .policy = drbd_down_nl_policy, 580 .maxattr = DRBD_NLA_CFG_CONTEXT, 581 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 582 }, 583 { 584 .cmd = DRBD_ADM_CHG_DISK_OPTS, 585 .pre_doit = drbd_pre_doit, 586 .doit = drbd_nl_chg_disk_opts_doit, 587 .post_doit = drbd_post_doit, 588 .policy = drbd_chg_disk_opts_nl_policy, 589 .maxattr = DRBD_NLA_DISK_CONF, 590 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 591 }, 592 { 593 .cmd = DRBD_ADM_CHG_NET_OPTS, 594 .pre_doit = drbd_pre_doit, 595 .doit = drbd_nl_chg_net_opts_doit, 596 .post_doit = drbd_post_doit, 597 .policy = drbd_chg_net_opts_nl_policy, 598 .maxattr = DRBD_NLA_NET_CONF, 599 .flags = GENL_ADMIN_PERM | GENL_CMD_CAP_DO, 600 }, 601 { 602 .cmd = DRBD_ADM_GET_RESOURCES, 603 .dumpit = drbd_nl_get_resources_dumpit, 604 .policy = drbd_get_resources_nl_policy, 605 .maxattr = DRBD_NLA_RESOURCE_STATISTICS, 606 .flags = GENL_CMD_CAP_DUMP, 607 }, 608 { 609 .cmd = DRBD_ADM_GET_DEVICES, 610 .dumpit = drbd_nl_get_devices_dumpit, 611 .done = drbd_adm_dump_devices_done, 612 .policy = drbd_get_devices_nl_policy, 613 .maxattr = DRBD_NLA_DEVICE_STATISTICS, 614 .flags = GENL_CMD_CAP_DUMP, 615 }, 616 { 617 .cmd = DRBD_ADM_GET_CONNECTIONS, 618 .dumpit = drbd_nl_get_connections_dumpit, 619 .done = drbd_adm_dump_connections_done, 620 .policy = drbd_get_connections_nl_policy, 621 .maxattr = DRBD_NLA_CONNECTION_STATISTICS, 622 .flags = GENL_CMD_CAP_DUMP, 623 }, 624 { 625 .cmd = DRBD_ADM_GET_PEER_DEVICES, 626 .dumpit = drbd_nl_get_peer_devices_dumpit, 627 .done = drbd_adm_dump_peer_devices_done, 628 .policy = drbd_get_peer_devices_nl_policy, 629 .maxattr = DRBD_NLA_PEER_DEVICE_STATISTICS, 630 .flags = GENL_CMD_CAP_DUMP, 631 }, 632 { 633 .cmd = DRBD_ADM_GET_INITIAL_STATE, 634 .dumpit = drbd_nl_get_initial_state_dumpit, 635 .policy = drbd_get_initial_state_nl_policy, 636 .maxattr = DRBD_NLA_CFG_CONTEXT, 637 .flags = GENL_CMD_CAP_DUMP, 638 }, 639 }; 640 641 static int __drbd_cfg_context_from_attrs(struct drbd_cfg_context *s, 642 struct nlattr ***ret_nested_attribute_table, 643 struct genl_info *info) 644 { 645 const int maxtype = DRBD_A_DRBD_CFG_CONTEXT_CTX_PEER_ADDR; 646 struct nlattr *tla = info->attrs[DRBD_NLA_CFG_CONTEXT]; 647 struct nlattr **ntb; 648 struct nlattr *nla; 649 int err = 0; 650 651 if (ret_nested_attribute_table) 652 *ret_nested_attribute_table = NULL; 653 if (!tla) 654 return -ENOMSG; 655 ntb = kzalloc_objs(*ntb, DRBD_A_DRBD_CFG_CONTEXT_CTX_PEER_ADDR + 1); 656 if (!ntb) 657 return -ENOMEM; 658 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_drbd_cfg_context_nl_policy, NULL); 659 if (err) 660 goto out; 661 662 nla = ntb[DRBD_A_DRBD_CFG_CONTEXT_CTX_VOLUME]; 663 if (nla && s) 664 s->ctx_volume = nla_get_u32(nla); 665 666 nla = ntb[DRBD_A_DRBD_CFG_CONTEXT_CTX_RESOURCE_NAME]; 667 if (nla && s) 668 s->ctx_resource_name_len = nla_strscpy(s->ctx_resource_name, nla, 128); 669 670 nla = ntb[DRBD_A_DRBD_CFG_CONTEXT_CTX_MY_ADDR]; 671 if (nla && s) 672 s->ctx_my_addr_len = nla_memcpy(s->ctx_my_addr, nla, 128); 673 674 nla = ntb[DRBD_A_DRBD_CFG_CONTEXT_CTX_PEER_ADDR]; 675 if (nla && s) 676 s->ctx_peer_addr_len = nla_memcpy(s->ctx_peer_addr, nla, 128); 677 678 out: 679 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 680 *ret_nested_attribute_table = ntb; 681 else 682 kfree(ntb); 683 return err; 684 } 685 686 int drbd_cfg_context_from_attrs(struct drbd_cfg_context *s, 687 struct genl_info *info) 688 { 689 return __drbd_cfg_context_from_attrs(s, NULL, info); 690 } 691 692 int drbd_cfg_context_ntb_from_attrs( 693 struct nlattr ***ret_nested_attribute_table, 694 struct genl_info *info) 695 { 696 return __drbd_cfg_context_from_attrs(NULL, ret_nested_attribute_table, info); 697 } 698 699 static int __disk_conf_from_attrs(struct disk_conf *s, 700 struct nlattr ***ret_nested_attribute_table, 701 struct genl_info *info) 702 { 703 const int maxtype = DRBD_A_DISK_CONF_DISABLE_WRITE_SAME; 704 struct nlattr *tla = info->attrs[DRBD_NLA_DISK_CONF]; 705 struct nlattr **ntb; 706 struct nlattr *nla; 707 int err = 0; 708 709 if (ret_nested_attribute_table) 710 *ret_nested_attribute_table = NULL; 711 if (!tla) 712 return -ENOMSG; 713 ntb = kzalloc_objs(*ntb, DRBD_A_DISK_CONF_DISABLE_WRITE_SAME + 1); 714 if (!ntb) 715 return -ENOMEM; 716 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_disk_conf_nl_policy, NULL); 717 if (err) 718 goto out; 719 720 nla = ntb[DRBD_A_DISK_CONF_BACKING_DEV]; 721 if (nla) { 722 if (s) 723 s->backing_dev_len = nla_strscpy(s->backing_dev, nla, 128); 724 } else { 725 pr_info("<< missing required attr: backing_dev\n"); 726 err = -ENOMSG; 727 } 728 729 nla = ntb[DRBD_A_DISK_CONF_META_DEV]; 730 if (nla) { 731 if (s) 732 s->meta_dev_len = nla_strscpy(s->meta_dev, nla, 128); 733 } else { 734 pr_info("<< missing required attr: meta_dev\n"); 735 err = -ENOMSG; 736 } 737 738 nla = ntb[DRBD_A_DISK_CONF_META_DEV_IDX]; 739 if (nla) { 740 if (s) 741 s->meta_dev_idx = nla_get_s32(nla); 742 } else { 743 pr_info("<< missing required attr: meta_dev_idx\n"); 744 err = -ENOMSG; 745 } 746 747 nla = ntb[DRBD_A_DISK_CONF_DISK_SIZE]; 748 if (nla && s) 749 s->disk_size = nla_get_u64(nla); 750 751 nla = ntb[DRBD_A_DISK_CONF_MAX_BIO_BVECS]; 752 if (nla && s) 753 s->max_bio_bvecs = nla_get_u32(nla); 754 755 nla = ntb[DRBD_A_DISK_CONF_ON_IO_ERROR]; 756 if (nla && s) 757 s->on_io_error = nla_get_u32(nla); 758 759 nla = ntb[DRBD_A_DISK_CONF_FENCING]; 760 if (nla && s) 761 s->fencing = nla_get_u32(nla); 762 763 nla = ntb[DRBD_A_DISK_CONF_RESYNC_RATE]; 764 if (nla && s) 765 s->resync_rate = nla_get_u32(nla); 766 767 nla = ntb[DRBD_A_DISK_CONF_RESYNC_AFTER]; 768 if (nla && s) 769 s->resync_after = nla_get_s32(nla); 770 771 nla = ntb[DRBD_A_DISK_CONF_AL_EXTENTS]; 772 if (nla && s) 773 s->al_extents = nla_get_u32(nla); 774 775 nla = ntb[DRBD_A_DISK_CONF_C_PLAN_AHEAD]; 776 if (nla && s) 777 s->c_plan_ahead = nla_get_u32(nla); 778 779 nla = ntb[DRBD_A_DISK_CONF_C_DELAY_TARGET]; 780 if (nla && s) 781 s->c_delay_target = nla_get_u32(nla); 782 783 nla = ntb[DRBD_A_DISK_CONF_C_FILL_TARGET]; 784 if (nla && s) 785 s->c_fill_target = nla_get_u32(nla); 786 787 nla = ntb[DRBD_A_DISK_CONF_C_MAX_RATE]; 788 if (nla && s) 789 s->c_max_rate = nla_get_u32(nla); 790 791 nla = ntb[DRBD_A_DISK_CONF_C_MIN_RATE]; 792 if (nla && s) 793 s->c_min_rate = nla_get_u32(nla); 794 795 nla = ntb[DRBD_A_DISK_CONF_DISK_BARRIER]; 796 if (nla && s) 797 s->disk_barrier = nla_get_u8(nla); 798 799 nla = ntb[DRBD_A_DISK_CONF_DISK_FLUSHES]; 800 if (nla && s) 801 s->disk_flushes = nla_get_u8(nla); 802 803 nla = ntb[DRBD_A_DISK_CONF_DISK_DRAIN]; 804 if (nla && s) 805 s->disk_drain = nla_get_u8(nla); 806 807 nla = ntb[DRBD_A_DISK_CONF_MD_FLUSHES]; 808 if (nla && s) 809 s->md_flushes = nla_get_u8(nla); 810 811 nla = ntb[DRBD_A_DISK_CONF_DISK_TIMEOUT]; 812 if (nla && s) 813 s->disk_timeout = nla_get_u32(nla); 814 815 nla = ntb[DRBD_A_DISK_CONF_READ_BALANCING]; 816 if (nla && s) 817 s->read_balancing = nla_get_u32(nla); 818 819 nla = ntb[DRBD_A_DISK_CONF_AL_UPDATES]; 820 if (nla && s) 821 s->al_updates = nla_get_u8(nla); 822 823 nla = ntb[DRBD_A_DISK_CONF_DISCARD_ZEROES_IF_ALIGNED]; 824 if (nla && s) 825 s->discard_zeroes_if_aligned = nla_get_u8(nla); 826 827 nla = ntb[DRBD_A_DISK_CONF_RS_DISCARD_GRANULARITY]; 828 if (nla && s) 829 s->rs_discard_granularity = nla_get_u32(nla); 830 831 nla = ntb[DRBD_A_DISK_CONF_DISABLE_WRITE_SAME]; 832 if (nla && s) 833 s->disable_write_same = nla_get_u8(nla); 834 835 out: 836 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 837 *ret_nested_attribute_table = ntb; 838 else 839 kfree(ntb); 840 return err; 841 } 842 843 int disk_conf_from_attrs(struct disk_conf *s, 844 struct genl_info *info) 845 { 846 return __disk_conf_from_attrs(s, NULL, info); 847 } 848 849 int disk_conf_ntb_from_attrs( 850 struct nlattr ***ret_nested_attribute_table, 851 struct genl_info *info) 852 { 853 return __disk_conf_from_attrs(NULL, ret_nested_attribute_table, info); 854 } 855 856 static int __res_opts_from_attrs(struct res_opts *s, 857 struct nlattr ***ret_nested_attribute_table, 858 struct genl_info *info) 859 { 860 const int maxtype = DRBD_A_RES_OPTS_ON_NO_DATA; 861 struct nlattr *tla = info->attrs[DRBD_NLA_RESOURCE_OPTS]; 862 struct nlattr **ntb; 863 struct nlattr *nla; 864 int err = 0; 865 866 if (ret_nested_attribute_table) 867 *ret_nested_attribute_table = NULL; 868 if (!tla) 869 return -ENOMSG; 870 ntb = kzalloc_objs(*ntb, DRBD_A_RES_OPTS_ON_NO_DATA + 1); 871 if (!ntb) 872 return -ENOMEM; 873 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_res_opts_nl_policy, NULL); 874 if (err) 875 goto out; 876 877 nla = ntb[DRBD_A_RES_OPTS_CPU_MASK]; 878 if (nla && s) 879 s->cpu_mask_len = nla_strscpy(s->cpu_mask, nla, DRBD_CPU_MASK_SIZE); 880 881 nla = ntb[DRBD_A_RES_OPTS_ON_NO_DATA]; 882 if (nla && s) 883 s->on_no_data = nla_get_u32(nla); 884 885 out: 886 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 887 *ret_nested_attribute_table = ntb; 888 else 889 kfree(ntb); 890 return err; 891 } 892 893 int res_opts_from_attrs(struct res_opts *s, 894 struct genl_info *info) 895 { 896 return __res_opts_from_attrs(s, NULL, info); 897 } 898 899 int res_opts_ntb_from_attrs( 900 struct nlattr ***ret_nested_attribute_table, 901 struct genl_info *info) 902 { 903 return __res_opts_from_attrs(NULL, ret_nested_attribute_table, info); 904 } 905 906 static int __net_conf_from_attrs(struct net_conf *s, 907 struct nlattr ***ret_nested_attribute_table, 908 struct genl_info *info) 909 { 910 const int maxtype = DRBD_A_NET_CONF_SOCK_CHECK_TIMEO; 911 struct nlattr *tla = info->attrs[DRBD_NLA_NET_CONF]; 912 struct nlattr **ntb; 913 struct nlattr *nla; 914 int err = 0; 915 916 if (ret_nested_attribute_table) 917 *ret_nested_attribute_table = NULL; 918 if (!tla) 919 return -ENOMSG; 920 ntb = kzalloc_objs(*ntb, DRBD_A_NET_CONF_SOCK_CHECK_TIMEO + 1); 921 if (!ntb) 922 return -ENOMEM; 923 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_net_conf_nl_policy, NULL); 924 if (err) 925 goto out; 926 927 nla = ntb[DRBD_A_NET_CONF_SHARED_SECRET]; 928 if (nla && s) 929 s->shared_secret_len = nla_strscpy(s->shared_secret, nla, SHARED_SECRET_MAX); 930 931 nla = ntb[DRBD_A_NET_CONF_CRAM_HMAC_ALG]; 932 if (nla && s) 933 s->cram_hmac_alg_len = nla_strscpy(s->cram_hmac_alg, nla, SHARED_SECRET_MAX); 934 935 nla = ntb[DRBD_A_NET_CONF_INTEGRITY_ALG]; 936 if (nla && s) 937 s->integrity_alg_len = nla_strscpy(s->integrity_alg, nla, SHARED_SECRET_MAX); 938 939 nla = ntb[DRBD_A_NET_CONF_VERIFY_ALG]; 940 if (nla && s) 941 s->verify_alg_len = nla_strscpy(s->verify_alg, nla, SHARED_SECRET_MAX); 942 943 nla = ntb[DRBD_A_NET_CONF_CSUMS_ALG]; 944 if (nla && s) 945 s->csums_alg_len = nla_strscpy(s->csums_alg, nla, SHARED_SECRET_MAX); 946 947 nla = ntb[DRBD_A_NET_CONF_WIRE_PROTOCOL]; 948 if (nla && s) 949 s->wire_protocol = nla_get_u32(nla); 950 951 nla = ntb[DRBD_A_NET_CONF_CONNECT_INT]; 952 if (nla && s) 953 s->connect_int = nla_get_u32(nla); 954 955 nla = ntb[DRBD_A_NET_CONF_TIMEOUT]; 956 if (nla && s) 957 s->timeout = nla_get_u32(nla); 958 959 nla = ntb[DRBD_A_NET_CONF_PING_INT]; 960 if (nla && s) 961 s->ping_int = nla_get_u32(nla); 962 963 nla = ntb[DRBD_A_NET_CONF_PING_TIMEO]; 964 if (nla && s) 965 s->ping_timeo = nla_get_u32(nla); 966 967 nla = ntb[DRBD_A_NET_CONF_SNDBUF_SIZE]; 968 if (nla && s) 969 s->sndbuf_size = nla_get_u32(nla); 970 971 nla = ntb[DRBD_A_NET_CONF_RCVBUF_SIZE]; 972 if (nla && s) 973 s->rcvbuf_size = nla_get_u32(nla); 974 975 nla = ntb[DRBD_A_NET_CONF_KO_COUNT]; 976 if (nla && s) 977 s->ko_count = nla_get_u32(nla); 978 979 nla = ntb[DRBD_A_NET_CONF_MAX_BUFFERS]; 980 if (nla && s) 981 s->max_buffers = nla_get_u32(nla); 982 983 nla = ntb[DRBD_A_NET_CONF_MAX_EPOCH_SIZE]; 984 if (nla && s) 985 s->max_epoch_size = nla_get_u32(nla); 986 987 nla = ntb[DRBD_A_NET_CONF_UNPLUG_WATERMARK]; 988 if (nla && s) 989 s->unplug_watermark = nla_get_u32(nla); 990 991 nla = ntb[DRBD_A_NET_CONF_AFTER_SB_0P]; 992 if (nla && s) 993 s->after_sb_0p = nla_get_u32(nla); 994 995 nla = ntb[DRBD_A_NET_CONF_AFTER_SB_1P]; 996 if (nla && s) 997 s->after_sb_1p = nla_get_u32(nla); 998 999 nla = ntb[DRBD_A_NET_CONF_AFTER_SB_2P]; 1000 if (nla && s) 1001 s->after_sb_2p = nla_get_u32(nla); 1002 1003 nla = ntb[DRBD_A_NET_CONF_RR_CONFLICT]; 1004 if (nla && s) 1005 s->rr_conflict = nla_get_u32(nla); 1006 1007 nla = ntb[DRBD_A_NET_CONF_ON_CONGESTION]; 1008 if (nla && s) 1009 s->on_congestion = nla_get_u32(nla); 1010 1011 nla = ntb[DRBD_A_NET_CONF_CONG_FILL]; 1012 if (nla && s) 1013 s->cong_fill = nla_get_u32(nla); 1014 1015 nla = ntb[DRBD_A_NET_CONF_CONG_EXTENTS]; 1016 if (nla && s) 1017 s->cong_extents = nla_get_u32(nla); 1018 1019 nla = ntb[DRBD_A_NET_CONF_TWO_PRIMARIES]; 1020 if (nla && s) 1021 s->two_primaries = nla_get_u8(nla); 1022 1023 nla = ntb[DRBD_A_NET_CONF_DISCARD_MY_DATA]; 1024 if (nla && s) 1025 s->discard_my_data = nla_get_u8(nla); 1026 1027 nla = ntb[DRBD_A_NET_CONF_TCP_CORK]; 1028 if (nla && s) 1029 s->tcp_cork = nla_get_u8(nla); 1030 1031 nla = ntb[DRBD_A_NET_CONF_ALWAYS_ASBP]; 1032 if (nla && s) 1033 s->always_asbp = nla_get_u8(nla); 1034 1035 nla = ntb[DRBD_A_NET_CONF_TENTATIVE]; 1036 if (nla && s) 1037 s->tentative = nla_get_u8(nla); 1038 1039 nla = ntb[DRBD_A_NET_CONF_USE_RLE]; 1040 if (nla && s) 1041 s->use_rle = nla_get_u8(nla); 1042 1043 nla = ntb[DRBD_A_NET_CONF_CSUMS_AFTER_CRASH_ONLY]; 1044 if (nla && s) 1045 s->csums_after_crash_only = nla_get_u8(nla); 1046 1047 nla = ntb[DRBD_A_NET_CONF_SOCK_CHECK_TIMEO]; 1048 if (nla && s) 1049 s->sock_check_timeo = nla_get_u32(nla); 1050 1051 out: 1052 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1053 *ret_nested_attribute_table = ntb; 1054 else 1055 kfree(ntb); 1056 return err; 1057 } 1058 1059 int net_conf_from_attrs(struct net_conf *s, 1060 struct genl_info *info) 1061 { 1062 return __net_conf_from_attrs(s, NULL, info); 1063 } 1064 1065 int net_conf_ntb_from_attrs( 1066 struct nlattr ***ret_nested_attribute_table, 1067 struct genl_info *info) 1068 { 1069 return __net_conf_from_attrs(NULL, ret_nested_attribute_table, info); 1070 } 1071 1072 static int __set_role_parms_from_attrs(struct set_role_parms *s, 1073 struct nlattr ***ret_nested_attribute_table, 1074 struct genl_info *info) 1075 { 1076 const int maxtype = DRBD_A_SET_ROLE_PARMS_ASSUME_UPTODATE; 1077 struct nlattr *tla = info->attrs[DRBD_NLA_SET_ROLE_PARMS]; 1078 struct nlattr **ntb; 1079 struct nlattr *nla; 1080 int err = 0; 1081 1082 if (ret_nested_attribute_table) 1083 *ret_nested_attribute_table = NULL; 1084 if (!tla) 1085 return -ENOMSG; 1086 ntb = kzalloc_objs(*ntb, DRBD_A_SET_ROLE_PARMS_ASSUME_UPTODATE + 1); 1087 if (!ntb) 1088 return -ENOMEM; 1089 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_set_role_parms_nl_policy, NULL); 1090 if (err) 1091 goto out; 1092 1093 nla = ntb[DRBD_A_SET_ROLE_PARMS_ASSUME_UPTODATE]; 1094 if (nla && s) 1095 s->assume_uptodate = nla_get_u8(nla); 1096 1097 out: 1098 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1099 *ret_nested_attribute_table = ntb; 1100 else 1101 kfree(ntb); 1102 return err; 1103 } 1104 1105 int set_role_parms_from_attrs(struct set_role_parms *s, 1106 struct genl_info *info) 1107 { 1108 return __set_role_parms_from_attrs(s, NULL, info); 1109 } 1110 1111 int set_role_parms_ntb_from_attrs( 1112 struct nlattr ***ret_nested_attribute_table, 1113 struct genl_info *info) 1114 { 1115 return __set_role_parms_from_attrs(NULL, ret_nested_attribute_table, info); 1116 } 1117 1118 static int __resize_parms_from_attrs(struct resize_parms *s, 1119 struct nlattr ***ret_nested_attribute_table, 1120 struct genl_info *info) 1121 { 1122 const int maxtype = DRBD_A_RESIZE_PARMS_AL_STRIPE_SIZE; 1123 struct nlattr *tla = info->attrs[DRBD_NLA_RESIZE_PARMS]; 1124 struct nlattr **ntb; 1125 struct nlattr *nla; 1126 int err = 0; 1127 1128 if (ret_nested_attribute_table) 1129 *ret_nested_attribute_table = NULL; 1130 if (!tla) 1131 return -ENOMSG; 1132 ntb = kzalloc_objs(*ntb, DRBD_A_RESIZE_PARMS_AL_STRIPE_SIZE + 1); 1133 if (!ntb) 1134 return -ENOMEM; 1135 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_resize_parms_nl_policy, NULL); 1136 if (err) 1137 goto out; 1138 1139 nla = ntb[DRBD_A_RESIZE_PARMS_RESIZE_SIZE]; 1140 if (nla && s) 1141 s->resize_size = nla_get_u64(nla); 1142 1143 nla = ntb[DRBD_A_RESIZE_PARMS_RESIZE_FORCE]; 1144 if (nla && s) 1145 s->resize_force = nla_get_u8(nla); 1146 1147 nla = ntb[DRBD_A_RESIZE_PARMS_NO_RESYNC]; 1148 if (nla && s) 1149 s->no_resync = nla_get_u8(nla); 1150 1151 nla = ntb[DRBD_A_RESIZE_PARMS_AL_STRIPES]; 1152 if (nla && s) 1153 s->al_stripes = nla_get_u32(nla); 1154 1155 nla = ntb[DRBD_A_RESIZE_PARMS_AL_STRIPE_SIZE]; 1156 if (nla && s) 1157 s->al_stripe_size = nla_get_u32(nla); 1158 1159 out: 1160 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1161 *ret_nested_attribute_table = ntb; 1162 else 1163 kfree(ntb); 1164 return err; 1165 } 1166 1167 int resize_parms_from_attrs(struct resize_parms *s, 1168 struct genl_info *info) 1169 { 1170 return __resize_parms_from_attrs(s, NULL, info); 1171 } 1172 1173 int resize_parms_ntb_from_attrs( 1174 struct nlattr ***ret_nested_attribute_table, 1175 struct genl_info *info) 1176 { 1177 return __resize_parms_from_attrs(NULL, ret_nested_attribute_table, info); 1178 } 1179 1180 static int __start_ov_parms_from_attrs(struct start_ov_parms *s, 1181 struct nlattr ***ret_nested_attribute_table, 1182 struct genl_info *info) 1183 { 1184 const int maxtype = DRBD_A_START_OV_PARMS_OV_STOP_SECTOR; 1185 struct nlattr *tla = info->attrs[DRBD_NLA_START_OV_PARMS]; 1186 struct nlattr **ntb; 1187 struct nlattr *nla; 1188 int err = 0; 1189 1190 if (ret_nested_attribute_table) 1191 *ret_nested_attribute_table = NULL; 1192 if (!tla) 1193 return -ENOMSG; 1194 ntb = kzalloc_objs(*ntb, DRBD_A_START_OV_PARMS_OV_STOP_SECTOR + 1); 1195 if (!ntb) 1196 return -ENOMEM; 1197 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_start_ov_parms_nl_policy, NULL); 1198 if (err) 1199 goto out; 1200 1201 nla = ntb[DRBD_A_START_OV_PARMS_OV_START_SECTOR]; 1202 if (nla && s) 1203 s->ov_start_sector = nla_get_u64(nla); 1204 1205 nla = ntb[DRBD_A_START_OV_PARMS_OV_STOP_SECTOR]; 1206 if (nla && s) 1207 s->ov_stop_sector = nla_get_u64(nla); 1208 1209 out: 1210 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1211 *ret_nested_attribute_table = ntb; 1212 else 1213 kfree(ntb); 1214 return err; 1215 } 1216 1217 int start_ov_parms_from_attrs(struct start_ov_parms *s, 1218 struct genl_info *info) 1219 { 1220 return __start_ov_parms_from_attrs(s, NULL, info); 1221 } 1222 1223 int start_ov_parms_ntb_from_attrs( 1224 struct nlattr ***ret_nested_attribute_table, 1225 struct genl_info *info) 1226 { 1227 return __start_ov_parms_from_attrs(NULL, ret_nested_attribute_table, info); 1228 } 1229 1230 static int __new_c_uuid_parms_from_attrs(struct new_c_uuid_parms *s, 1231 struct nlattr ***ret_nested_attribute_table, 1232 struct genl_info *info) 1233 { 1234 const int maxtype = DRBD_A_NEW_C_UUID_PARMS_CLEAR_BM; 1235 struct nlattr *tla = info->attrs[DRBD_NLA_NEW_C_UUID_PARMS]; 1236 struct nlattr **ntb; 1237 struct nlattr *nla; 1238 int err = 0; 1239 1240 if (ret_nested_attribute_table) 1241 *ret_nested_attribute_table = NULL; 1242 if (!tla) 1243 return -ENOMSG; 1244 ntb = kzalloc_objs(*ntb, DRBD_A_NEW_C_UUID_PARMS_CLEAR_BM + 1); 1245 if (!ntb) 1246 return -ENOMEM; 1247 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_new_c_uuid_parms_nl_policy, NULL); 1248 if (err) 1249 goto out; 1250 1251 nla = ntb[DRBD_A_NEW_C_UUID_PARMS_CLEAR_BM]; 1252 if (nla && s) 1253 s->clear_bm = nla_get_u8(nla); 1254 1255 out: 1256 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1257 *ret_nested_attribute_table = ntb; 1258 else 1259 kfree(ntb); 1260 return err; 1261 } 1262 1263 int new_c_uuid_parms_from_attrs(struct new_c_uuid_parms *s, 1264 struct genl_info *info) 1265 { 1266 return __new_c_uuid_parms_from_attrs(s, NULL, info); 1267 } 1268 1269 int new_c_uuid_parms_ntb_from_attrs( 1270 struct nlattr ***ret_nested_attribute_table, 1271 struct genl_info *info) 1272 { 1273 return __new_c_uuid_parms_from_attrs(NULL, ret_nested_attribute_table, info); 1274 } 1275 1276 static int __disconnect_parms_from_attrs(struct disconnect_parms *s, 1277 struct nlattr ***ret_nested_attribute_table, 1278 struct genl_info *info) 1279 { 1280 const int maxtype = DRBD_A_DISCONNECT_PARMS_FORCE_DISCONNECT; 1281 struct nlattr *tla = info->attrs[DRBD_NLA_DISCONNECT_PARMS]; 1282 struct nlattr **ntb; 1283 struct nlattr *nla; 1284 int err = 0; 1285 1286 if (ret_nested_attribute_table) 1287 *ret_nested_attribute_table = NULL; 1288 if (!tla) 1289 return -ENOMSG; 1290 ntb = kzalloc_objs(*ntb, DRBD_A_DISCONNECT_PARMS_FORCE_DISCONNECT + 1); 1291 if (!ntb) 1292 return -ENOMEM; 1293 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_disconnect_parms_nl_policy, NULL); 1294 if (err) 1295 goto out; 1296 1297 nla = ntb[DRBD_A_DISCONNECT_PARMS_FORCE_DISCONNECT]; 1298 if (nla && s) 1299 s->force_disconnect = nla_get_u8(nla); 1300 1301 out: 1302 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1303 *ret_nested_attribute_table = ntb; 1304 else 1305 kfree(ntb); 1306 return err; 1307 } 1308 1309 int disconnect_parms_from_attrs(struct disconnect_parms *s, 1310 struct genl_info *info) 1311 { 1312 return __disconnect_parms_from_attrs(s, NULL, info); 1313 } 1314 1315 int disconnect_parms_ntb_from_attrs( 1316 struct nlattr ***ret_nested_attribute_table, 1317 struct genl_info *info) 1318 { 1319 return __disconnect_parms_from_attrs(NULL, ret_nested_attribute_table, info); 1320 } 1321 1322 static int __detach_parms_from_attrs(struct detach_parms *s, 1323 struct nlattr ***ret_nested_attribute_table, 1324 struct genl_info *info) 1325 { 1326 const int maxtype = DRBD_A_DETACH_PARMS_FORCE_DETACH; 1327 struct nlattr *tla = info->attrs[DRBD_NLA_DETACH_PARMS]; 1328 struct nlattr **ntb; 1329 struct nlattr *nla; 1330 int err = 0; 1331 1332 if (ret_nested_attribute_table) 1333 *ret_nested_attribute_table = NULL; 1334 if (!tla) 1335 return -ENOMSG; 1336 ntb = kzalloc_objs(*ntb, DRBD_A_DETACH_PARMS_FORCE_DETACH + 1); 1337 if (!ntb) 1338 return -ENOMEM; 1339 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_detach_parms_nl_policy, NULL); 1340 if (err) 1341 goto out; 1342 1343 nla = ntb[DRBD_A_DETACH_PARMS_FORCE_DETACH]; 1344 if (nla && s) 1345 s->force_detach = nla_get_u8(nla); 1346 1347 out: 1348 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1349 *ret_nested_attribute_table = ntb; 1350 else 1351 kfree(ntb); 1352 return err; 1353 } 1354 1355 int detach_parms_from_attrs(struct detach_parms *s, 1356 struct genl_info *info) 1357 { 1358 return __detach_parms_from_attrs(s, NULL, info); 1359 } 1360 1361 int detach_parms_ntb_from_attrs( 1362 struct nlattr ***ret_nested_attribute_table, 1363 struct genl_info *info) 1364 { 1365 return __detach_parms_from_attrs(NULL, ret_nested_attribute_table, info); 1366 } 1367 1368 static int __resource_info_from_attrs(struct resource_info *s, 1369 struct nlattr ***ret_nested_attribute_table, 1370 struct genl_info *info) 1371 { 1372 const int maxtype = DRBD_A_RESOURCE_INFO_RES_SUSP_FEN; 1373 struct nlattr *tla = info->attrs[DRBD_NLA_RESOURCE_INFO]; 1374 struct nlattr **ntb; 1375 struct nlattr *nla; 1376 int err = 0; 1377 1378 if (ret_nested_attribute_table) 1379 *ret_nested_attribute_table = NULL; 1380 if (!tla) 1381 return -ENOMSG; 1382 ntb = kzalloc_objs(*ntb, DRBD_A_RESOURCE_INFO_RES_SUSP_FEN + 1); 1383 if (!ntb) 1384 return -ENOMEM; 1385 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_resource_info_nl_policy, NULL); 1386 if (err) 1387 goto out; 1388 1389 nla = ntb[DRBD_A_RESOURCE_INFO_RES_ROLE]; 1390 if (nla && s) 1391 s->res_role = nla_get_u32(nla); 1392 1393 nla = ntb[DRBD_A_RESOURCE_INFO_RES_SUSP]; 1394 if (nla && s) 1395 s->res_susp = nla_get_u8(nla); 1396 1397 nla = ntb[DRBD_A_RESOURCE_INFO_RES_SUSP_NOD]; 1398 if (nla && s) 1399 s->res_susp_nod = nla_get_u8(nla); 1400 1401 nla = ntb[DRBD_A_RESOURCE_INFO_RES_SUSP_FEN]; 1402 if (nla && s) 1403 s->res_susp_fen = nla_get_u8(nla); 1404 1405 out: 1406 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1407 *ret_nested_attribute_table = ntb; 1408 else 1409 kfree(ntb); 1410 return err; 1411 } 1412 1413 int resource_info_from_attrs(struct resource_info *s, 1414 struct genl_info *info) 1415 { 1416 return __resource_info_from_attrs(s, NULL, info); 1417 } 1418 1419 int resource_info_ntb_from_attrs( 1420 struct nlattr ***ret_nested_attribute_table, 1421 struct genl_info *info) 1422 { 1423 return __resource_info_from_attrs(NULL, ret_nested_attribute_table, info); 1424 } 1425 1426 static int __device_info_from_attrs(struct device_info *s, 1427 struct nlattr ***ret_nested_attribute_table, 1428 struct genl_info *info) 1429 { 1430 const int maxtype = DRBD_A_DEVICE_INFO_DEV_DISK_STATE; 1431 struct nlattr *tla = info->attrs[DRBD_NLA_DEVICE_INFO]; 1432 struct nlattr **ntb; 1433 struct nlattr *nla; 1434 int err = 0; 1435 1436 if (ret_nested_attribute_table) 1437 *ret_nested_attribute_table = NULL; 1438 if (!tla) 1439 return -ENOMSG; 1440 ntb = kzalloc_objs(*ntb, DRBD_A_DEVICE_INFO_DEV_DISK_STATE + 1); 1441 if (!ntb) 1442 return -ENOMEM; 1443 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_device_info_nl_policy, NULL); 1444 if (err) 1445 goto out; 1446 1447 nla = ntb[DRBD_A_DEVICE_INFO_DEV_DISK_STATE]; 1448 if (nla && s) 1449 s->dev_disk_state = nla_get_u32(nla); 1450 1451 out: 1452 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1453 *ret_nested_attribute_table = ntb; 1454 else 1455 kfree(ntb); 1456 return err; 1457 } 1458 1459 int device_info_from_attrs(struct device_info *s, 1460 struct genl_info *info) 1461 { 1462 return __device_info_from_attrs(s, NULL, info); 1463 } 1464 1465 int device_info_ntb_from_attrs( 1466 struct nlattr ***ret_nested_attribute_table, 1467 struct genl_info *info) 1468 { 1469 return __device_info_from_attrs(NULL, ret_nested_attribute_table, info); 1470 } 1471 1472 static int __connection_info_from_attrs(struct connection_info *s, 1473 struct nlattr ***ret_nested_attribute_table, 1474 struct genl_info *info) 1475 { 1476 const int maxtype = DRBD_A_CONNECTION_INFO_CONN_ROLE; 1477 struct nlattr *tla = info->attrs[DRBD_NLA_CONNECTION_INFO]; 1478 struct nlattr **ntb; 1479 struct nlattr *nla; 1480 int err = 0; 1481 1482 if (ret_nested_attribute_table) 1483 *ret_nested_attribute_table = NULL; 1484 if (!tla) 1485 return -ENOMSG; 1486 ntb = kzalloc_objs(*ntb, DRBD_A_CONNECTION_INFO_CONN_ROLE + 1); 1487 if (!ntb) 1488 return -ENOMEM; 1489 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_connection_info_nl_policy, NULL); 1490 if (err) 1491 goto out; 1492 1493 nla = ntb[DRBD_A_CONNECTION_INFO_CONN_CONNECTION_STATE]; 1494 if (nla && s) 1495 s->conn_connection_state = nla_get_u32(nla); 1496 1497 nla = ntb[DRBD_A_CONNECTION_INFO_CONN_ROLE]; 1498 if (nla && s) 1499 s->conn_role = nla_get_u32(nla); 1500 1501 out: 1502 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1503 *ret_nested_attribute_table = ntb; 1504 else 1505 kfree(ntb); 1506 return err; 1507 } 1508 1509 int connection_info_from_attrs(struct connection_info *s, 1510 struct genl_info *info) 1511 { 1512 return __connection_info_from_attrs(s, NULL, info); 1513 } 1514 1515 int connection_info_ntb_from_attrs( 1516 struct nlattr ***ret_nested_attribute_table, 1517 struct genl_info *info) 1518 { 1519 return __connection_info_from_attrs(NULL, ret_nested_attribute_table, info); 1520 } 1521 1522 static int __peer_device_info_from_attrs(struct peer_device_info *s, 1523 struct nlattr ***ret_nested_attribute_table, 1524 struct genl_info *info) 1525 { 1526 const int maxtype = DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_DEPENDENCY; 1527 struct nlattr *tla = info->attrs[DRBD_NLA_PEER_DEVICE_INFO]; 1528 struct nlattr **ntb; 1529 struct nlattr *nla; 1530 int err = 0; 1531 1532 if (ret_nested_attribute_table) 1533 *ret_nested_attribute_table = NULL; 1534 if (!tla) 1535 return -ENOMSG; 1536 ntb = kzalloc_objs(*ntb, 1537 DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_DEPENDENCY + 1); 1538 if (!ntb) 1539 return -ENOMEM; 1540 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_peer_device_info_nl_policy, NULL); 1541 if (err) 1542 goto out; 1543 1544 nla = ntb[DRBD_A_PEER_DEVICE_INFO_PEER_REPL_STATE]; 1545 if (nla && s) 1546 s->peer_repl_state = nla_get_u32(nla); 1547 1548 nla = ntb[DRBD_A_PEER_DEVICE_INFO_PEER_DISK_STATE]; 1549 if (nla && s) 1550 s->peer_disk_state = nla_get_u32(nla); 1551 1552 nla = ntb[DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_USER]; 1553 if (nla && s) 1554 s->peer_resync_susp_user = nla_get_u32(nla); 1555 1556 nla = ntb[DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_PEER]; 1557 if (nla && s) 1558 s->peer_resync_susp_peer = nla_get_u32(nla); 1559 1560 nla = ntb[DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_DEPENDENCY]; 1561 if (nla && s) 1562 s->peer_resync_susp_dependency = nla_get_u32(nla); 1563 1564 out: 1565 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1566 *ret_nested_attribute_table = ntb; 1567 else 1568 kfree(ntb); 1569 return err; 1570 } 1571 1572 int peer_device_info_from_attrs(struct peer_device_info *s, 1573 struct genl_info *info) 1574 { 1575 return __peer_device_info_from_attrs(s, NULL, info); 1576 } 1577 1578 int peer_device_info_ntb_from_attrs( 1579 struct nlattr ***ret_nested_attribute_table, 1580 struct genl_info *info) 1581 { 1582 return __peer_device_info_from_attrs(NULL, ret_nested_attribute_table, info); 1583 } 1584 1585 static int __resource_statistics_from_attrs(struct resource_statistics *s, 1586 struct nlattr ***ret_nested_attribute_table, 1587 struct genl_info *info) 1588 { 1589 const int maxtype = DRBD_A_RESOURCE_STATISTICS_RES_STAT_WRITE_ORDERING; 1590 struct nlattr *tla = info->attrs[DRBD_NLA_RESOURCE_STATISTICS]; 1591 struct nlattr **ntb; 1592 struct nlattr *nla; 1593 int err = 0; 1594 1595 if (ret_nested_attribute_table) 1596 *ret_nested_attribute_table = NULL; 1597 if (!tla) 1598 return -ENOMSG; 1599 ntb = kzalloc_objs(*ntb, 1600 DRBD_A_RESOURCE_STATISTICS_RES_STAT_WRITE_ORDERING + 1); 1601 if (!ntb) 1602 return -ENOMEM; 1603 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_resource_statistics_nl_policy, NULL); 1604 if (err) 1605 goto out; 1606 1607 nla = ntb[DRBD_A_RESOURCE_STATISTICS_RES_STAT_WRITE_ORDERING]; 1608 if (nla && s) 1609 s->res_stat_write_ordering = nla_get_u32(nla); 1610 1611 out: 1612 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1613 *ret_nested_attribute_table = ntb; 1614 else 1615 kfree(ntb); 1616 return err; 1617 } 1618 1619 int resource_statistics_from_attrs(struct resource_statistics *s, 1620 struct genl_info *info) 1621 { 1622 return __resource_statistics_from_attrs(s, NULL, info); 1623 } 1624 1625 int resource_statistics_ntb_from_attrs( 1626 struct nlattr ***ret_nested_attribute_table, 1627 struct genl_info *info) 1628 { 1629 return __resource_statistics_from_attrs(NULL, ret_nested_attribute_table, info); 1630 } 1631 1632 static int __device_statistics_from_attrs(struct device_statistics *s, 1633 struct nlattr ***ret_nested_attribute_table, 1634 struct genl_info *info) 1635 { 1636 const int maxtype = DRBD_A_DEVICE_STATISTICS_HISTORY_UUIDS; 1637 struct nlattr *tla = info->attrs[DRBD_NLA_DEVICE_STATISTICS]; 1638 struct nlattr **ntb; 1639 struct nlattr *nla; 1640 int err = 0; 1641 1642 if (ret_nested_attribute_table) 1643 *ret_nested_attribute_table = NULL; 1644 if (!tla) 1645 return -ENOMSG; 1646 ntb = kzalloc_objs(*ntb, DRBD_A_DEVICE_STATISTICS_HISTORY_UUIDS + 1); 1647 if (!ntb) 1648 return -ENOMEM; 1649 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_device_statistics_nl_policy, NULL); 1650 if (err) 1651 goto out; 1652 1653 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_SIZE]; 1654 if (nla && s) 1655 s->dev_size = nla_get_u64(nla); 1656 1657 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_READ]; 1658 if (nla && s) 1659 s->dev_read = nla_get_u64(nla); 1660 1661 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_WRITE]; 1662 if (nla && s) 1663 s->dev_write = nla_get_u64(nla); 1664 1665 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_AL_WRITES]; 1666 if (nla && s) 1667 s->dev_al_writes = nla_get_u64(nla); 1668 1669 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_BM_WRITES]; 1670 if (nla && s) 1671 s->dev_bm_writes = nla_get_u64(nla); 1672 1673 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_UPPER_PENDING]; 1674 if (nla && s) 1675 s->dev_upper_pending = nla_get_u32(nla); 1676 1677 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_LOWER_PENDING]; 1678 if (nla && s) 1679 s->dev_lower_pending = nla_get_u32(nla); 1680 1681 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_UPPER_BLOCKED]; 1682 if (nla && s) 1683 s->dev_upper_blocked = nla_get_u8(nla); 1684 1685 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_LOWER_BLOCKED]; 1686 if (nla && s) 1687 s->dev_lower_blocked = nla_get_u8(nla); 1688 1689 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_AL_SUSPENDED]; 1690 if (nla && s) 1691 s->dev_al_suspended = nla_get_u8(nla); 1692 1693 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_EXPOSED_DATA_UUID]; 1694 if (nla && s) 1695 s->dev_exposed_data_uuid = nla_get_u64(nla); 1696 1697 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_CURRENT_UUID]; 1698 if (nla && s) 1699 s->dev_current_uuid = nla_get_u64(nla); 1700 1701 nla = ntb[DRBD_A_DEVICE_STATISTICS_DEV_DISK_FLAGS]; 1702 if (nla && s) 1703 s->dev_disk_flags = nla_get_u32(nla); 1704 1705 nla = ntb[DRBD_A_DEVICE_STATISTICS_HISTORY_UUIDS]; 1706 if (nla && s) 1707 s->history_uuids_len = nla_memcpy(s->history_uuids, nla, DRBD_NL_HISTORY_UUIDS_SIZE); 1708 1709 out: 1710 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1711 *ret_nested_attribute_table = ntb; 1712 else 1713 kfree(ntb); 1714 return err; 1715 } 1716 1717 int device_statistics_from_attrs(struct device_statistics *s, 1718 struct genl_info *info) 1719 { 1720 return __device_statistics_from_attrs(s, NULL, info); 1721 } 1722 1723 int device_statistics_ntb_from_attrs( 1724 struct nlattr ***ret_nested_attribute_table, 1725 struct genl_info *info) 1726 { 1727 return __device_statistics_from_attrs(NULL, ret_nested_attribute_table, info); 1728 } 1729 1730 static int __connection_statistics_from_attrs(struct connection_statistics *s, 1731 struct nlattr ***ret_nested_attribute_table, 1732 struct genl_info *info) 1733 { 1734 const int maxtype = DRBD_A_CONNECTION_STATISTICS_CONN_CONGESTED; 1735 struct nlattr *tla = info->attrs[DRBD_NLA_CONNECTION_STATISTICS]; 1736 struct nlattr **ntb; 1737 struct nlattr *nla; 1738 int err = 0; 1739 1740 if (ret_nested_attribute_table) 1741 *ret_nested_attribute_table = NULL; 1742 if (!tla) 1743 return -ENOMSG; 1744 ntb = kzalloc_objs(*ntb, 1745 DRBD_A_CONNECTION_STATISTICS_CONN_CONGESTED + 1); 1746 if (!ntb) 1747 return -ENOMEM; 1748 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_connection_statistics_nl_policy, NULL); 1749 if (err) 1750 goto out; 1751 1752 nla = ntb[DRBD_A_CONNECTION_STATISTICS_CONN_CONGESTED]; 1753 if (nla && s) 1754 s->conn_congested = nla_get_u8(nla); 1755 1756 out: 1757 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1758 *ret_nested_attribute_table = ntb; 1759 else 1760 kfree(ntb); 1761 return err; 1762 } 1763 1764 int connection_statistics_from_attrs(struct connection_statistics *s, 1765 struct genl_info *info) 1766 { 1767 return __connection_statistics_from_attrs(s, NULL, info); 1768 } 1769 1770 int connection_statistics_ntb_from_attrs( 1771 struct nlattr ***ret_nested_attribute_table, 1772 struct genl_info *info) 1773 { 1774 return __connection_statistics_from_attrs(NULL, ret_nested_attribute_table, info); 1775 } 1776 1777 static int __peer_device_statistics_from_attrs(struct peer_device_statistics *s, 1778 struct nlattr ***ret_nested_attribute_table, 1779 struct genl_info *info) 1780 { 1781 const int maxtype = DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_FLAGS; 1782 struct nlattr *tla = info->attrs[DRBD_NLA_PEER_DEVICE_STATISTICS]; 1783 struct nlattr **ntb; 1784 struct nlattr *nla; 1785 int err = 0; 1786 1787 if (ret_nested_attribute_table) 1788 *ret_nested_attribute_table = NULL; 1789 if (!tla) 1790 return -ENOMSG; 1791 ntb = kzalloc_objs(*ntb, 1792 DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_FLAGS + 1); 1793 if (!ntb) 1794 return -ENOMEM; 1795 err = nla_parse_nested_deprecated(ntb, maxtype, tla, drbd_peer_device_statistics_nl_policy, NULL); 1796 if (err) 1797 goto out; 1798 1799 nla = ntb[DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_RECEIVED]; 1800 if (nla && s) 1801 s->peer_dev_received = nla_get_u64(nla); 1802 1803 nla = ntb[DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_SENT]; 1804 if (nla && s) 1805 s->peer_dev_sent = nla_get_u64(nla); 1806 1807 nla = ntb[DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_PENDING]; 1808 if (nla && s) 1809 s->peer_dev_pending = nla_get_u32(nla); 1810 1811 nla = ntb[DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_UNACKED]; 1812 if (nla && s) 1813 s->peer_dev_unacked = nla_get_u32(nla); 1814 1815 nla = ntb[DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_OUT_OF_SYNC]; 1816 if (nla && s) 1817 s->peer_dev_out_of_sync = nla_get_u64(nla); 1818 1819 nla = ntb[DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_RESYNC_FAILED]; 1820 if (nla && s) 1821 s->peer_dev_resync_failed = nla_get_u64(nla); 1822 1823 nla = ntb[DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_BITMAP_UUID]; 1824 if (nla && s) 1825 s->peer_dev_bitmap_uuid = nla_get_u64(nla); 1826 1827 nla = ntb[DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_FLAGS]; 1828 if (nla && s) 1829 s->peer_dev_flags = nla_get_u32(nla); 1830 1831 out: 1832 if (ret_nested_attribute_table && (!err || err == -ENOMSG)) 1833 *ret_nested_attribute_table = ntb; 1834 else 1835 kfree(ntb); 1836 return err; 1837 } 1838 1839 int peer_device_statistics_from_attrs(struct peer_device_statistics *s, 1840 struct genl_info *info) 1841 { 1842 return __peer_device_statistics_from_attrs(s, NULL, info); 1843 } 1844 1845 int peer_device_statistics_ntb_from_attrs( 1846 struct nlattr ***ret_nested_attribute_table, 1847 struct genl_info *info) 1848 { 1849 return __peer_device_statistics_from_attrs(NULL, ret_nested_attribute_table, info); 1850 } 1851 1852 int drbd_cfg_reply_to_skb(struct sk_buff *skb, struct drbd_cfg_reply *s) 1853 { 1854 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_CFG_REPLY); 1855 1856 if (!tla) 1857 goto nla_put_failure; 1858 1859 if (nla_put(skb, DRBD_A_DRBD_CFG_REPLY_INFO_TEXT, min_t(int, 0, 1860 s->info_text_len + (s->info_text_len < 0)), s->info_text)) 1861 goto nla_put_failure; 1862 1863 nla_nest_end(skb, tla); 1864 return 0; 1865 1866 nla_put_failure: 1867 if (tla) 1868 nla_nest_cancel(skb, tla); 1869 return -EMSGSIZE; 1870 } 1871 1872 int drbd_cfg_context_to_skb(struct sk_buff *skb, struct drbd_cfg_context *s) 1873 { 1874 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_CFG_CONTEXT); 1875 1876 if (!tla) 1877 goto nla_put_failure; 1878 1879 if (nla_put_u32(skb, DRBD_A_DRBD_CFG_CONTEXT_CTX_VOLUME, s->ctx_volume)) 1880 goto nla_put_failure; 1881 if (nla_put(skb, DRBD_A_DRBD_CFG_CONTEXT_CTX_RESOURCE_NAME, min_t(int, 128, 1882 s->ctx_resource_name_len + (s->ctx_resource_name_len < 128)), s->ctx_resource_name)) 1883 goto nla_put_failure; 1884 if (nla_put(skb, DRBD_A_DRBD_CFG_CONTEXT_CTX_MY_ADDR, min_t(int, 128, 1885 s->ctx_my_addr_len), s->ctx_my_addr)) 1886 goto nla_put_failure; 1887 if (nla_put(skb, DRBD_A_DRBD_CFG_CONTEXT_CTX_PEER_ADDR, min_t(int, 128, 1888 s->ctx_peer_addr_len), s->ctx_peer_addr)) 1889 goto nla_put_failure; 1890 1891 nla_nest_end(skb, tla); 1892 return 0; 1893 1894 nla_put_failure: 1895 if (tla) 1896 nla_nest_cancel(skb, tla); 1897 return -EMSGSIZE; 1898 } 1899 1900 int disk_conf_to_skb(struct sk_buff *skb, struct disk_conf *s) 1901 { 1902 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_DISK_CONF); 1903 1904 if (!tla) 1905 goto nla_put_failure; 1906 1907 if (nla_put(skb, DRBD_A_DISK_CONF_BACKING_DEV, min_t(int, 128, 1908 s->backing_dev_len + (s->backing_dev_len < 128)), s->backing_dev)) 1909 goto nla_put_failure; 1910 if (nla_put(skb, DRBD_A_DISK_CONF_META_DEV, min_t(int, 128, 1911 s->meta_dev_len + (s->meta_dev_len < 128)), s->meta_dev)) 1912 goto nla_put_failure; 1913 if (nla_put_s32(skb, DRBD_A_DISK_CONF_META_DEV_IDX, s->meta_dev_idx)) 1914 goto nla_put_failure; 1915 if (nla_put_u64_64bit(skb, DRBD_A_DISK_CONF_DISK_SIZE, s->disk_size, 0)) 1916 goto nla_put_failure; 1917 if (nla_put_u32(skb, DRBD_A_DISK_CONF_MAX_BIO_BVECS, s->max_bio_bvecs)) 1918 goto nla_put_failure; 1919 if (nla_put_u32(skb, DRBD_A_DISK_CONF_ON_IO_ERROR, s->on_io_error)) 1920 goto nla_put_failure; 1921 if (nla_put_u32(skb, DRBD_A_DISK_CONF_FENCING, s->fencing)) 1922 goto nla_put_failure; 1923 if (nla_put_u32(skb, DRBD_A_DISK_CONF_RESYNC_RATE, s->resync_rate)) 1924 goto nla_put_failure; 1925 if (nla_put_s32(skb, DRBD_A_DISK_CONF_RESYNC_AFTER, s->resync_after)) 1926 goto nla_put_failure; 1927 if (nla_put_u32(skb, DRBD_A_DISK_CONF_AL_EXTENTS, s->al_extents)) 1928 goto nla_put_failure; 1929 if (nla_put_u32(skb, DRBD_A_DISK_CONF_C_PLAN_AHEAD, s->c_plan_ahead)) 1930 goto nla_put_failure; 1931 if (nla_put_u32(skb, DRBD_A_DISK_CONF_C_DELAY_TARGET, s->c_delay_target)) 1932 goto nla_put_failure; 1933 if (nla_put_u32(skb, DRBD_A_DISK_CONF_C_FILL_TARGET, s->c_fill_target)) 1934 goto nla_put_failure; 1935 if (nla_put_u32(skb, DRBD_A_DISK_CONF_C_MAX_RATE, s->c_max_rate)) 1936 goto nla_put_failure; 1937 if (nla_put_u32(skb, DRBD_A_DISK_CONF_C_MIN_RATE, s->c_min_rate)) 1938 goto nla_put_failure; 1939 if (nla_put_u8(skb, DRBD_A_DISK_CONF_DISK_BARRIER, s->disk_barrier)) 1940 goto nla_put_failure; 1941 if (nla_put_u8(skb, DRBD_A_DISK_CONF_DISK_FLUSHES, s->disk_flushes)) 1942 goto nla_put_failure; 1943 if (nla_put_u8(skb, DRBD_A_DISK_CONF_DISK_DRAIN, s->disk_drain)) 1944 goto nla_put_failure; 1945 if (nla_put_u8(skb, DRBD_A_DISK_CONF_MD_FLUSHES, s->md_flushes)) 1946 goto nla_put_failure; 1947 if (nla_put_u32(skb, DRBD_A_DISK_CONF_DISK_TIMEOUT, s->disk_timeout)) 1948 goto nla_put_failure; 1949 if (nla_put_u32(skb, DRBD_A_DISK_CONF_READ_BALANCING, s->read_balancing)) 1950 goto nla_put_failure; 1951 if (nla_put_u8(skb, DRBD_A_DISK_CONF_AL_UPDATES, s->al_updates)) 1952 goto nla_put_failure; 1953 if (nla_put_u8(skb, DRBD_A_DISK_CONF_DISCARD_ZEROES_IF_ALIGNED, s->discard_zeroes_if_aligned)) 1954 goto nla_put_failure; 1955 if (nla_put_u32(skb, DRBD_A_DISK_CONF_RS_DISCARD_GRANULARITY, s->rs_discard_granularity)) 1956 goto nla_put_failure; 1957 if (nla_put_u8(skb, DRBD_A_DISK_CONF_DISABLE_WRITE_SAME, s->disable_write_same)) 1958 goto nla_put_failure; 1959 1960 nla_nest_end(skb, tla); 1961 return 0; 1962 1963 nla_put_failure: 1964 if (tla) 1965 nla_nest_cancel(skb, tla); 1966 return -EMSGSIZE; 1967 } 1968 1969 int res_opts_to_skb(struct sk_buff *skb, struct res_opts *s) 1970 { 1971 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_RESOURCE_OPTS); 1972 1973 if (!tla) 1974 goto nla_put_failure; 1975 1976 if (nla_put(skb, DRBD_A_RES_OPTS_CPU_MASK, min_t(int, DRBD_CPU_MASK_SIZE, 1977 s->cpu_mask_len + (s->cpu_mask_len < DRBD_CPU_MASK_SIZE)), s->cpu_mask)) 1978 goto nla_put_failure; 1979 if (nla_put_u32(skb, DRBD_A_RES_OPTS_ON_NO_DATA, s->on_no_data)) 1980 goto nla_put_failure; 1981 1982 nla_nest_end(skb, tla); 1983 return 0; 1984 1985 nla_put_failure: 1986 if (tla) 1987 nla_nest_cancel(skb, tla); 1988 return -EMSGSIZE; 1989 } 1990 1991 int net_conf_to_skb(struct sk_buff *skb, struct net_conf *s) 1992 { 1993 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_NET_CONF); 1994 1995 if (!tla) 1996 goto nla_put_failure; 1997 1998 if (nla_put(skb, DRBD_A_NET_CONF_SHARED_SECRET, min_t(int, SHARED_SECRET_MAX, 1999 s->shared_secret_len + (s->shared_secret_len < SHARED_SECRET_MAX)), s->shared_secret)) 2000 goto nla_put_failure; 2001 if (nla_put(skb, DRBD_A_NET_CONF_CRAM_HMAC_ALG, min_t(int, SHARED_SECRET_MAX, 2002 s->cram_hmac_alg_len + (s->cram_hmac_alg_len < SHARED_SECRET_MAX)), s->cram_hmac_alg)) 2003 goto nla_put_failure; 2004 if (nla_put(skb, DRBD_A_NET_CONF_INTEGRITY_ALG, min_t(int, SHARED_SECRET_MAX, 2005 s->integrity_alg_len + (s->integrity_alg_len < SHARED_SECRET_MAX)), s->integrity_alg)) 2006 goto nla_put_failure; 2007 if (nla_put(skb, DRBD_A_NET_CONF_VERIFY_ALG, min_t(int, SHARED_SECRET_MAX, 2008 s->verify_alg_len + (s->verify_alg_len < SHARED_SECRET_MAX)), s->verify_alg)) 2009 goto nla_put_failure; 2010 if (nla_put(skb, DRBD_A_NET_CONF_CSUMS_ALG, min_t(int, SHARED_SECRET_MAX, 2011 s->csums_alg_len + (s->csums_alg_len < SHARED_SECRET_MAX)), s->csums_alg)) 2012 goto nla_put_failure; 2013 if (nla_put_u32(skb, DRBD_A_NET_CONF_WIRE_PROTOCOL, s->wire_protocol)) 2014 goto nla_put_failure; 2015 if (nla_put_u32(skb, DRBD_A_NET_CONF_CONNECT_INT, s->connect_int)) 2016 goto nla_put_failure; 2017 if (nla_put_u32(skb, DRBD_A_NET_CONF_TIMEOUT, s->timeout)) 2018 goto nla_put_failure; 2019 if (nla_put_u32(skb, DRBD_A_NET_CONF_PING_INT, s->ping_int)) 2020 goto nla_put_failure; 2021 if (nla_put_u32(skb, DRBD_A_NET_CONF_PING_TIMEO, s->ping_timeo)) 2022 goto nla_put_failure; 2023 if (nla_put_u32(skb, DRBD_A_NET_CONF_SNDBUF_SIZE, s->sndbuf_size)) 2024 goto nla_put_failure; 2025 if (nla_put_u32(skb, DRBD_A_NET_CONF_RCVBUF_SIZE, s->rcvbuf_size)) 2026 goto nla_put_failure; 2027 if (nla_put_u32(skb, DRBD_A_NET_CONF_KO_COUNT, s->ko_count)) 2028 goto nla_put_failure; 2029 if (nla_put_u32(skb, DRBD_A_NET_CONF_MAX_BUFFERS, s->max_buffers)) 2030 goto nla_put_failure; 2031 if (nla_put_u32(skb, DRBD_A_NET_CONF_MAX_EPOCH_SIZE, s->max_epoch_size)) 2032 goto nla_put_failure; 2033 if (nla_put_u32(skb, DRBD_A_NET_CONF_UNPLUG_WATERMARK, s->unplug_watermark)) 2034 goto nla_put_failure; 2035 if (nla_put_u32(skb, DRBD_A_NET_CONF_AFTER_SB_0P, s->after_sb_0p)) 2036 goto nla_put_failure; 2037 if (nla_put_u32(skb, DRBD_A_NET_CONF_AFTER_SB_1P, s->after_sb_1p)) 2038 goto nla_put_failure; 2039 if (nla_put_u32(skb, DRBD_A_NET_CONF_AFTER_SB_2P, s->after_sb_2p)) 2040 goto nla_put_failure; 2041 if (nla_put_u32(skb, DRBD_A_NET_CONF_RR_CONFLICT, s->rr_conflict)) 2042 goto nla_put_failure; 2043 if (nla_put_u32(skb, DRBD_A_NET_CONF_ON_CONGESTION, s->on_congestion)) 2044 goto nla_put_failure; 2045 if (nla_put_u32(skb, DRBD_A_NET_CONF_CONG_FILL, s->cong_fill)) 2046 goto nla_put_failure; 2047 if (nla_put_u32(skb, DRBD_A_NET_CONF_CONG_EXTENTS, s->cong_extents)) 2048 goto nla_put_failure; 2049 if (nla_put_u8(skb, DRBD_A_NET_CONF_TWO_PRIMARIES, s->two_primaries)) 2050 goto nla_put_failure; 2051 if (nla_put_u8(skb, DRBD_A_NET_CONF_DISCARD_MY_DATA, s->discard_my_data)) 2052 goto nla_put_failure; 2053 if (nla_put_u8(skb, DRBD_A_NET_CONF_TCP_CORK, s->tcp_cork)) 2054 goto nla_put_failure; 2055 if (nla_put_u8(skb, DRBD_A_NET_CONF_ALWAYS_ASBP, s->always_asbp)) 2056 goto nla_put_failure; 2057 if (nla_put_u8(skb, DRBD_A_NET_CONF_TENTATIVE, s->tentative)) 2058 goto nla_put_failure; 2059 if (nla_put_u8(skb, DRBD_A_NET_CONF_USE_RLE, s->use_rle)) 2060 goto nla_put_failure; 2061 if (nla_put_u8(skb, DRBD_A_NET_CONF_CSUMS_AFTER_CRASH_ONLY, s->csums_after_crash_only)) 2062 goto nla_put_failure; 2063 if (nla_put_u32(skb, DRBD_A_NET_CONF_SOCK_CHECK_TIMEO, s->sock_check_timeo)) 2064 goto nla_put_failure; 2065 2066 nla_nest_end(skb, tla); 2067 return 0; 2068 2069 nla_put_failure: 2070 if (tla) 2071 nla_nest_cancel(skb, tla); 2072 return -EMSGSIZE; 2073 } 2074 2075 int set_role_parms_to_skb(struct sk_buff *skb, struct set_role_parms *s) 2076 { 2077 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_SET_ROLE_PARMS); 2078 2079 if (!tla) 2080 goto nla_put_failure; 2081 2082 if (nla_put_u8(skb, DRBD_A_SET_ROLE_PARMS_ASSUME_UPTODATE, s->assume_uptodate)) 2083 goto nla_put_failure; 2084 2085 nla_nest_end(skb, tla); 2086 return 0; 2087 2088 nla_put_failure: 2089 if (tla) 2090 nla_nest_cancel(skb, tla); 2091 return -EMSGSIZE; 2092 } 2093 2094 int resize_parms_to_skb(struct sk_buff *skb, struct resize_parms *s) 2095 { 2096 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_RESIZE_PARMS); 2097 2098 if (!tla) 2099 goto nla_put_failure; 2100 2101 if (nla_put_u64_64bit(skb, DRBD_A_RESIZE_PARMS_RESIZE_SIZE, s->resize_size, 0)) 2102 goto nla_put_failure; 2103 if (nla_put_u8(skb, DRBD_A_RESIZE_PARMS_RESIZE_FORCE, s->resize_force)) 2104 goto nla_put_failure; 2105 if (nla_put_u8(skb, DRBD_A_RESIZE_PARMS_NO_RESYNC, s->no_resync)) 2106 goto nla_put_failure; 2107 if (nla_put_u32(skb, DRBD_A_RESIZE_PARMS_AL_STRIPES, s->al_stripes)) 2108 goto nla_put_failure; 2109 if (nla_put_u32(skb, DRBD_A_RESIZE_PARMS_AL_STRIPE_SIZE, s->al_stripe_size)) 2110 goto nla_put_failure; 2111 2112 nla_nest_end(skb, tla); 2113 return 0; 2114 2115 nla_put_failure: 2116 if (tla) 2117 nla_nest_cancel(skb, tla); 2118 return -EMSGSIZE; 2119 } 2120 2121 int state_info_to_skb(struct sk_buff *skb, struct state_info *s) 2122 { 2123 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_STATE_INFO); 2124 2125 if (!tla) 2126 goto nla_put_failure; 2127 2128 if (nla_put_u32(skb, DRBD_A_STATE_INFO_SIB_REASON, s->sib_reason)) 2129 goto nla_put_failure; 2130 if (nla_put_u32(skb, DRBD_A_STATE_INFO_CURRENT_STATE, s->current_state)) 2131 goto nla_put_failure; 2132 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_CAPACITY, s->capacity, 0)) 2133 goto nla_put_failure; 2134 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_ED_UUID, s->ed_uuid, 0)) 2135 goto nla_put_failure; 2136 if (nla_put_u32(skb, DRBD_A_STATE_INFO_PREV_STATE, s->prev_state)) 2137 goto nla_put_failure; 2138 if (nla_put_u32(skb, DRBD_A_STATE_INFO_NEW_STATE, s->new_state)) 2139 goto nla_put_failure; 2140 if (nla_put(skb, DRBD_A_STATE_INFO_UUIDS, min_t(int, DRBD_NL_UUIDS_SIZE, 2141 s->uuids_len), s->uuids)) 2142 goto nla_put_failure; 2143 if (nla_put_u32(skb, DRBD_A_STATE_INFO_DISK_FLAGS, s->disk_flags)) 2144 goto nla_put_failure; 2145 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_BITS_TOTAL, s->bits_total, 0)) 2146 goto nla_put_failure; 2147 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_BITS_OOS, s->bits_oos, 0)) 2148 goto nla_put_failure; 2149 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_BITS_RS_TOTAL, s->bits_rs_total, 0)) 2150 goto nla_put_failure; 2151 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_BITS_RS_FAILED, s->bits_rs_failed, 0)) 2152 goto nla_put_failure; 2153 if (nla_put(skb, DRBD_A_STATE_INFO_HELPER, min_t(int, 32, 2154 s->helper_len + (s->helper_len < 32)), s->helper)) 2155 goto nla_put_failure; 2156 if (nla_put_u32(skb, DRBD_A_STATE_INFO_HELPER_EXIT_CODE, s->helper_exit_code)) 2157 goto nla_put_failure; 2158 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_SEND_CNT, s->send_cnt, 0)) 2159 goto nla_put_failure; 2160 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_RECV_CNT, s->recv_cnt, 0)) 2161 goto nla_put_failure; 2162 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_READ_CNT, s->read_cnt, 0)) 2163 goto nla_put_failure; 2164 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_WRIT_CNT, s->writ_cnt, 0)) 2165 goto nla_put_failure; 2166 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_AL_WRIT_CNT, s->al_writ_cnt, 0)) 2167 goto nla_put_failure; 2168 if (nla_put_u64_64bit(skb, DRBD_A_STATE_INFO_BM_WRIT_CNT, s->bm_writ_cnt, 0)) 2169 goto nla_put_failure; 2170 if (nla_put_u32(skb, DRBD_A_STATE_INFO_AP_BIO_CNT, s->ap_bio_cnt)) 2171 goto nla_put_failure; 2172 if (nla_put_u32(skb, DRBD_A_STATE_INFO_AP_PENDING_CNT, s->ap_pending_cnt)) 2173 goto nla_put_failure; 2174 if (nla_put_u32(skb, DRBD_A_STATE_INFO_RS_PENDING_CNT, s->rs_pending_cnt)) 2175 goto nla_put_failure; 2176 2177 nla_nest_end(skb, tla); 2178 return 0; 2179 2180 nla_put_failure: 2181 if (tla) 2182 nla_nest_cancel(skb, tla); 2183 return -EMSGSIZE; 2184 } 2185 2186 int start_ov_parms_to_skb(struct sk_buff *skb, struct start_ov_parms *s) 2187 { 2188 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_START_OV_PARMS); 2189 2190 if (!tla) 2191 goto nla_put_failure; 2192 2193 if (nla_put_u64_64bit(skb, DRBD_A_START_OV_PARMS_OV_START_SECTOR, s->ov_start_sector, 0)) 2194 goto nla_put_failure; 2195 if (nla_put_u64_64bit(skb, DRBD_A_START_OV_PARMS_OV_STOP_SECTOR, s->ov_stop_sector, 0)) 2196 goto nla_put_failure; 2197 2198 nla_nest_end(skb, tla); 2199 return 0; 2200 2201 nla_put_failure: 2202 if (tla) 2203 nla_nest_cancel(skb, tla); 2204 return -EMSGSIZE; 2205 } 2206 2207 int new_c_uuid_parms_to_skb(struct sk_buff *skb, struct new_c_uuid_parms *s) 2208 { 2209 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_NEW_C_UUID_PARMS); 2210 2211 if (!tla) 2212 goto nla_put_failure; 2213 2214 if (nla_put_u8(skb, DRBD_A_NEW_C_UUID_PARMS_CLEAR_BM, s->clear_bm)) 2215 goto nla_put_failure; 2216 2217 nla_nest_end(skb, tla); 2218 return 0; 2219 2220 nla_put_failure: 2221 if (tla) 2222 nla_nest_cancel(skb, tla); 2223 return -EMSGSIZE; 2224 } 2225 2226 int timeout_parms_to_skb(struct sk_buff *skb, struct timeout_parms *s) 2227 { 2228 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_TIMEOUT_PARMS); 2229 2230 if (!tla) 2231 goto nla_put_failure; 2232 2233 if (nla_put_u32(skb, DRBD_A_TIMEOUT_PARMS_TIMEOUT_TYPE, s->timeout_type)) 2234 goto nla_put_failure; 2235 2236 nla_nest_end(skb, tla); 2237 return 0; 2238 2239 nla_put_failure: 2240 if (tla) 2241 nla_nest_cancel(skb, tla); 2242 return -EMSGSIZE; 2243 } 2244 2245 int disconnect_parms_to_skb(struct sk_buff *skb, struct disconnect_parms *s) 2246 { 2247 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_DISCONNECT_PARMS); 2248 2249 if (!tla) 2250 goto nla_put_failure; 2251 2252 if (nla_put_u8(skb, DRBD_A_DISCONNECT_PARMS_FORCE_DISCONNECT, s->force_disconnect)) 2253 goto nla_put_failure; 2254 2255 nla_nest_end(skb, tla); 2256 return 0; 2257 2258 nla_put_failure: 2259 if (tla) 2260 nla_nest_cancel(skb, tla); 2261 return -EMSGSIZE; 2262 } 2263 2264 int detach_parms_to_skb(struct sk_buff *skb, struct detach_parms *s) 2265 { 2266 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_DETACH_PARMS); 2267 2268 if (!tla) 2269 goto nla_put_failure; 2270 2271 if (nla_put_u8(skb, DRBD_A_DETACH_PARMS_FORCE_DETACH, s->force_detach)) 2272 goto nla_put_failure; 2273 2274 nla_nest_end(skb, tla); 2275 return 0; 2276 2277 nla_put_failure: 2278 if (tla) 2279 nla_nest_cancel(skb, tla); 2280 return -EMSGSIZE; 2281 } 2282 2283 int resource_info_to_skb(struct sk_buff *skb, struct resource_info *s) 2284 { 2285 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_RESOURCE_INFO); 2286 2287 if (!tla) 2288 goto nla_put_failure; 2289 2290 if (nla_put_u32(skb, DRBD_A_RESOURCE_INFO_RES_ROLE, s->res_role)) 2291 goto nla_put_failure; 2292 if (nla_put_u8(skb, DRBD_A_RESOURCE_INFO_RES_SUSP, s->res_susp)) 2293 goto nla_put_failure; 2294 if (nla_put_u8(skb, DRBD_A_RESOURCE_INFO_RES_SUSP_NOD, s->res_susp_nod)) 2295 goto nla_put_failure; 2296 if (nla_put_u8(skb, DRBD_A_RESOURCE_INFO_RES_SUSP_FEN, s->res_susp_fen)) 2297 goto nla_put_failure; 2298 2299 nla_nest_end(skb, tla); 2300 return 0; 2301 2302 nla_put_failure: 2303 if (tla) 2304 nla_nest_cancel(skb, tla); 2305 return -EMSGSIZE; 2306 } 2307 2308 int device_info_to_skb(struct sk_buff *skb, struct device_info *s) 2309 { 2310 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_DEVICE_INFO); 2311 2312 if (!tla) 2313 goto nla_put_failure; 2314 2315 if (nla_put_u32(skb, DRBD_A_DEVICE_INFO_DEV_DISK_STATE, s->dev_disk_state)) 2316 goto nla_put_failure; 2317 2318 nla_nest_end(skb, tla); 2319 return 0; 2320 2321 nla_put_failure: 2322 if (tla) 2323 nla_nest_cancel(skb, tla); 2324 return -EMSGSIZE; 2325 } 2326 2327 int connection_info_to_skb(struct sk_buff *skb, struct connection_info *s) 2328 { 2329 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_CONNECTION_INFO); 2330 2331 if (!tla) 2332 goto nla_put_failure; 2333 2334 if (nla_put_u32(skb, DRBD_A_CONNECTION_INFO_CONN_CONNECTION_STATE, s->conn_connection_state)) 2335 goto nla_put_failure; 2336 if (nla_put_u32(skb, DRBD_A_CONNECTION_INFO_CONN_ROLE, s->conn_role)) 2337 goto nla_put_failure; 2338 2339 nla_nest_end(skb, tla); 2340 return 0; 2341 2342 nla_put_failure: 2343 if (tla) 2344 nla_nest_cancel(skb, tla); 2345 return -EMSGSIZE; 2346 } 2347 2348 int peer_device_info_to_skb(struct sk_buff *skb, struct peer_device_info *s) 2349 { 2350 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_PEER_DEVICE_INFO); 2351 2352 if (!tla) 2353 goto nla_put_failure; 2354 2355 if (nla_put_u32(skb, DRBD_A_PEER_DEVICE_INFO_PEER_REPL_STATE, s->peer_repl_state)) 2356 goto nla_put_failure; 2357 if (nla_put_u32(skb, DRBD_A_PEER_DEVICE_INFO_PEER_DISK_STATE, s->peer_disk_state)) 2358 goto nla_put_failure; 2359 if (nla_put_u32(skb, DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_USER, s->peer_resync_susp_user)) 2360 goto nla_put_failure; 2361 if (nla_put_u32(skb, DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_PEER, s->peer_resync_susp_peer)) 2362 goto nla_put_failure; 2363 if (nla_put_u32(skb, DRBD_A_PEER_DEVICE_INFO_PEER_RESYNC_SUSP_DEPENDENCY, s->peer_resync_susp_dependency)) 2364 goto nla_put_failure; 2365 2366 nla_nest_end(skb, tla); 2367 return 0; 2368 2369 nla_put_failure: 2370 if (tla) 2371 nla_nest_cancel(skb, tla); 2372 return -EMSGSIZE; 2373 } 2374 2375 int resource_statistics_to_skb(struct sk_buff *skb, struct resource_statistics *s) 2376 { 2377 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_RESOURCE_STATISTICS); 2378 2379 if (!tla) 2380 goto nla_put_failure; 2381 2382 if (nla_put_u32(skb, DRBD_A_RESOURCE_STATISTICS_RES_STAT_WRITE_ORDERING, s->res_stat_write_ordering)) 2383 goto nla_put_failure; 2384 2385 nla_nest_end(skb, tla); 2386 return 0; 2387 2388 nla_put_failure: 2389 if (tla) 2390 nla_nest_cancel(skb, tla); 2391 return -EMSGSIZE; 2392 } 2393 2394 int device_statistics_to_skb(struct sk_buff *skb, struct device_statistics *s) 2395 { 2396 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_DEVICE_STATISTICS); 2397 2398 if (!tla) 2399 goto nla_put_failure; 2400 2401 if (nla_put_u64_64bit(skb, DRBD_A_DEVICE_STATISTICS_DEV_SIZE, s->dev_size, 0)) 2402 goto nla_put_failure; 2403 if (nla_put_u64_64bit(skb, DRBD_A_DEVICE_STATISTICS_DEV_READ, s->dev_read, 0)) 2404 goto nla_put_failure; 2405 if (nla_put_u64_64bit(skb, DRBD_A_DEVICE_STATISTICS_DEV_WRITE, s->dev_write, 0)) 2406 goto nla_put_failure; 2407 if (nla_put_u64_64bit(skb, DRBD_A_DEVICE_STATISTICS_DEV_AL_WRITES, s->dev_al_writes, 0)) 2408 goto nla_put_failure; 2409 if (nla_put_u64_64bit(skb, DRBD_A_DEVICE_STATISTICS_DEV_BM_WRITES, s->dev_bm_writes, 0)) 2410 goto nla_put_failure; 2411 if (nla_put_u32(skb, DRBD_A_DEVICE_STATISTICS_DEV_UPPER_PENDING, s->dev_upper_pending)) 2412 goto nla_put_failure; 2413 if (nla_put_u32(skb, DRBD_A_DEVICE_STATISTICS_DEV_LOWER_PENDING, s->dev_lower_pending)) 2414 goto nla_put_failure; 2415 if (nla_put_u8(skb, DRBD_A_DEVICE_STATISTICS_DEV_UPPER_BLOCKED, s->dev_upper_blocked)) 2416 goto nla_put_failure; 2417 if (nla_put_u8(skb, DRBD_A_DEVICE_STATISTICS_DEV_LOWER_BLOCKED, s->dev_lower_blocked)) 2418 goto nla_put_failure; 2419 if (nla_put_u8(skb, DRBD_A_DEVICE_STATISTICS_DEV_AL_SUSPENDED, s->dev_al_suspended)) 2420 goto nla_put_failure; 2421 if (nla_put_u64_64bit(skb, DRBD_A_DEVICE_STATISTICS_DEV_EXPOSED_DATA_UUID, s->dev_exposed_data_uuid, 0)) 2422 goto nla_put_failure; 2423 if (nla_put_u64_64bit(skb, DRBD_A_DEVICE_STATISTICS_DEV_CURRENT_UUID, s->dev_current_uuid, 0)) 2424 goto nla_put_failure; 2425 if (nla_put_u32(skb, DRBD_A_DEVICE_STATISTICS_DEV_DISK_FLAGS, s->dev_disk_flags)) 2426 goto nla_put_failure; 2427 if (nla_put(skb, DRBD_A_DEVICE_STATISTICS_HISTORY_UUIDS, min_t(int, DRBD_NL_HISTORY_UUIDS_SIZE, 2428 s->history_uuids_len), s->history_uuids)) 2429 goto nla_put_failure; 2430 2431 nla_nest_end(skb, tla); 2432 return 0; 2433 2434 nla_put_failure: 2435 if (tla) 2436 nla_nest_cancel(skb, tla); 2437 return -EMSGSIZE; 2438 } 2439 2440 int connection_statistics_to_skb(struct sk_buff *skb, struct connection_statistics *s) 2441 { 2442 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_CONNECTION_STATISTICS); 2443 2444 if (!tla) 2445 goto nla_put_failure; 2446 2447 if (nla_put_u8(skb, DRBD_A_CONNECTION_STATISTICS_CONN_CONGESTED, s->conn_congested)) 2448 goto nla_put_failure; 2449 2450 nla_nest_end(skb, tla); 2451 return 0; 2452 2453 nla_put_failure: 2454 if (tla) 2455 nla_nest_cancel(skb, tla); 2456 return -EMSGSIZE; 2457 } 2458 2459 int peer_device_statistics_to_skb(struct sk_buff *skb, struct peer_device_statistics *s) 2460 { 2461 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_PEER_DEVICE_STATISTICS); 2462 2463 if (!tla) 2464 goto nla_put_failure; 2465 2466 if (nla_put_u64_64bit(skb, DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_RECEIVED, s->peer_dev_received, 0)) 2467 goto nla_put_failure; 2468 if (nla_put_u64_64bit(skb, DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_SENT, s->peer_dev_sent, 0)) 2469 goto nla_put_failure; 2470 if (nla_put_u32(skb, DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_PENDING, s->peer_dev_pending)) 2471 goto nla_put_failure; 2472 if (nla_put_u32(skb, DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_UNACKED, s->peer_dev_unacked)) 2473 goto nla_put_failure; 2474 if (nla_put_u64_64bit(skb, DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_OUT_OF_SYNC, s->peer_dev_out_of_sync, 0)) 2475 goto nla_put_failure; 2476 if (nla_put_u64_64bit(skb, DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_RESYNC_FAILED, s->peer_dev_resync_failed, 0)) 2477 goto nla_put_failure; 2478 if (nla_put_u64_64bit(skb, DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_BITMAP_UUID, s->peer_dev_bitmap_uuid, 0)) 2479 goto nla_put_failure; 2480 if (nla_put_u32(skb, DRBD_A_PEER_DEVICE_STATISTICS_PEER_DEV_FLAGS, s->peer_dev_flags)) 2481 goto nla_put_failure; 2482 2483 nla_nest_end(skb, tla); 2484 return 0; 2485 2486 nla_put_failure: 2487 if (tla) 2488 nla_nest_cancel(skb, tla); 2489 return -EMSGSIZE; 2490 } 2491 2492 int drbd_notification_header_to_skb(struct sk_buff *skb, struct drbd_notification_header *s) 2493 { 2494 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_NOTIFICATION_HEADER); 2495 2496 if (!tla) 2497 goto nla_put_failure; 2498 2499 if (nla_put_u32(skb, DRBD_A_DRBD_NOTIFICATION_HEADER_NH_TYPE, s->nh_type)) 2500 goto nla_put_failure; 2501 2502 nla_nest_end(skb, tla); 2503 return 0; 2504 2505 nla_put_failure: 2506 if (tla) 2507 nla_nest_cancel(skb, tla); 2508 return -EMSGSIZE; 2509 } 2510 2511 int drbd_helper_info_to_skb(struct sk_buff *skb, struct drbd_helper_info *s) 2512 { 2513 struct nlattr *tla = nla_nest_start(skb, DRBD_NLA_HELPER); 2514 2515 if (!tla) 2516 goto nla_put_failure; 2517 2518 if (nla_put(skb, DRBD_A_DRBD_HELPER_INFO_HELPER_NAME, min_t(int, 32, 2519 s->helper_name_len + (s->helper_name_len < 32)), s->helper_name)) 2520 goto nla_put_failure; 2521 if (nla_put_u32(skb, DRBD_A_DRBD_HELPER_INFO_HELPER_STATUS, s->helper_status)) 2522 goto nla_put_failure; 2523 2524 nla_nest_end(skb, tla); 2525 return 0; 2526 2527 nla_put_failure: 2528 if (tla) 2529 nla_nest_cancel(skb, tla); 2530 return -EMSGSIZE; 2531 } 2532 2533 void set_disk_conf_defaults(struct disk_conf *x) 2534 { 2535 x->on_io_error = DRBD_ON_IO_ERROR_DEF; 2536 x->fencing = DRBD_FENCING_DEF; 2537 x->resync_rate = DRBD_RESYNC_RATE_DEF; 2538 x->resync_after = DRBD_MINOR_NUMBER_DEF; 2539 x->al_extents = DRBD_AL_EXTENTS_DEF; 2540 x->c_plan_ahead = DRBD_C_PLAN_AHEAD_DEF; 2541 x->c_delay_target = DRBD_C_DELAY_TARGET_DEF; 2542 x->c_fill_target = DRBD_C_FILL_TARGET_DEF; 2543 x->c_max_rate = DRBD_C_MAX_RATE_DEF; 2544 x->c_min_rate = DRBD_C_MIN_RATE_DEF; 2545 x->disk_barrier = DRBD_DISK_BARRIER_DEF; 2546 x->disk_flushes = DRBD_DISK_FLUSHES_DEF; 2547 x->disk_drain = DRBD_DISK_DRAIN_DEF; 2548 x->md_flushes = DRBD_MD_FLUSHES_DEF; 2549 x->disk_timeout = DRBD_DISK_TIMEOUT_DEF; 2550 x->read_balancing = DRBD_READ_BALANCING_DEF; 2551 x->al_updates = DRBD_AL_UPDATES_DEF; 2552 x->discard_zeroes_if_aligned = DRBD_DISCARD_ZEROES_IF_ALIGNED_DEF; 2553 x->rs_discard_granularity = DRBD_RS_DISCARD_GRANULARITY_DEF; 2554 x->disable_write_same = DRBD_DISABLE_WRITE_SAME_DEF; 2555 } 2556 2557 void set_res_opts_defaults(struct res_opts *x) 2558 { 2559 memset(x->cpu_mask, 0, sizeof(x->cpu_mask)); 2560 x->cpu_mask_len = 0; 2561 x->on_no_data = DRBD_ON_NO_DATA_DEF; 2562 } 2563 2564 void set_net_conf_defaults(struct net_conf *x) 2565 { 2566 memset(x->shared_secret, 0, sizeof(x->shared_secret)); 2567 x->shared_secret_len = 0; 2568 memset(x->cram_hmac_alg, 0, sizeof(x->cram_hmac_alg)); 2569 x->cram_hmac_alg_len = 0; 2570 memset(x->integrity_alg, 0, sizeof(x->integrity_alg)); 2571 x->integrity_alg_len = 0; 2572 memset(x->verify_alg, 0, sizeof(x->verify_alg)); 2573 x->verify_alg_len = 0; 2574 memset(x->csums_alg, 0, sizeof(x->csums_alg)); 2575 x->csums_alg_len = 0; 2576 x->wire_protocol = DRBD_PROTOCOL_DEF; 2577 x->connect_int = DRBD_CONNECT_INT_DEF; 2578 x->timeout = DRBD_TIMEOUT_DEF; 2579 x->ping_int = DRBD_PING_INT_DEF; 2580 x->ping_timeo = DRBD_PING_TIMEO_DEF; 2581 x->sndbuf_size = DRBD_SNDBUF_SIZE_DEF; 2582 x->rcvbuf_size = DRBD_RCVBUF_SIZE_DEF; 2583 x->ko_count = DRBD_KO_COUNT_DEF; 2584 x->max_buffers = DRBD_MAX_BUFFERS_DEF; 2585 x->max_epoch_size = DRBD_MAX_EPOCH_SIZE_DEF; 2586 x->unplug_watermark = DRBD_UNPLUG_WATERMARK_DEF; 2587 x->after_sb_0p = DRBD_AFTER_SB_0P_DEF; 2588 x->after_sb_1p = DRBD_AFTER_SB_1P_DEF; 2589 x->after_sb_2p = DRBD_AFTER_SB_2P_DEF; 2590 x->rr_conflict = DRBD_RR_CONFLICT_DEF; 2591 x->on_congestion = DRBD_ON_CONGESTION_DEF; 2592 x->cong_fill = DRBD_CONG_FILL_DEF; 2593 x->cong_extents = DRBD_CONG_EXTENTS_DEF; 2594 x->two_primaries = DRBD_ALLOW_TWO_PRIMARIES_DEF; 2595 x->tcp_cork = DRBD_TCP_CORK_DEF; 2596 x->always_asbp = DRBD_ALWAYS_ASBP_DEF; 2597 x->use_rle = DRBD_USE_RLE_DEF; 2598 x->csums_after_crash_only = DRBD_CSUMS_AFTER_CRASH_ONLY_DEF; 2599 x->sock_check_timeo = DRBD_SOCKET_CHECK_TIMEO_DEF; 2600 } 2601 2602 void set_resize_parms_defaults(struct resize_parms *x) 2603 { 2604 x->al_stripes = DRBD_AL_STRIPES_DEF; 2605 x->al_stripe_size = DRBD_AL_STRIPE_SIZE_DEF; 2606 } 2607