6811333 Remove prom_printf() message in emlxs driver
[opensolaris.git] / usr / src / lib / libipmp / common / ipmp_admin.c
blob8a282f52867322ffbff909421d4c98bb09ecf8d5
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
21 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
22 * Use is subject to license terms.
26 * IPMP administrative interfaces (see PSARC/2007/272).
29 #include <assert.h>
30 #include <errno.h>
31 #include <string.h>
32 #include <unistd.h>
33 #include <sys/time.h>
34 #include <sys/types.h>
36 #include "ipmp_impl.h"
37 #include "ipmp_mpathd.h"
38 #include "ipmp_admin.h"
40 static int
41 ipmp_command(ipmp_handle_t handle, const void *req, uint_t reqsize)
43 ipmp_state_t *statep = (ipmp_state_t *)handle;
44 mi_result_t result;
45 struct timeval end;
46 int save_errno;
47 int retval;
49 if (gettimeofday(&end, NULL) == -1)
50 return (IPMP_FAILURE);
51 end.tv_sec += IPMP_REQTIMEOUT;
53 assert(statep->st_fd == -1);
54 retval = ipmp_connect(&statep->st_fd);
55 if (retval != IPMP_SUCCESS)
56 return (retval);
58 retval = ipmp_write(statep->st_fd, req, reqsize);
59 if (retval != IPMP_SUCCESS)
60 goto out;
62 retval = ipmp_read(statep->st_fd, &result, sizeof (result), &end);
63 if (retval != IPMP_SUCCESS)
64 goto out;
66 errno = result.me_sys_error;
67 retval = result.me_mpathd_error;
68 out:
69 save_errno = errno;
70 (void) close(statep->st_fd);
71 statep->st_fd = -1;
72 errno = save_errno;
73 return (retval);
76 int
77 ipmp_offline(ipmp_handle_t handle, const char *ifname, uint_t minred)
79 mi_offline_t mio;
81 mio.mio_command = MI_OFFLINE;
82 mio.mio_min_redundancy = minred;
83 (void) strlcpy(mio.mio_ifname, ifname, LIFNAMSIZ);
84 return (ipmp_command(handle, &mio, sizeof (mio)));
87 int
88 ipmp_undo_offline(ipmp_handle_t handle, const char *ifname)
90 mi_undo_offline_t miu;
92 miu.miu_command = MI_UNDO_OFFLINE;
93 (void) strlcpy(miu.miu_ifname, ifname, LIFNAMSIZ);
94 return (ipmp_command(handle, &miu, sizeof (miu)));
97 int
98 ipmp_ping_daemon(ipmp_handle_t handle)
100 mi_ping_t mip;
102 mip.mip_command = MI_PING;
103 return (ipmp_command(handle, &mip, sizeof (mip)));