Print this page
OS-249
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/cmd/ibd_upgrade/ibd_delete_link.c
+++ new/usr/src/cmd/ibd_upgrade/ibd_delete_link.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
|
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 + * Copyright (c) 2011, Joyent Inc. All rights reserved.
24 25 */
25 26
26 27 #include <stdio.h>
27 28 #include <door.h>
28 29 #include <errno.h>
29 30 #include <strings.h>
30 31 #include <sys/mman.h>
31 32 #include <libdladm.h>
32 33 #include <libdlib.h>
33 34 #include <libdllink.h>
34 35
35 36 extern dladm_status_t dladm_door_fd(dladm_handle_t, int *);
36 37
37 38 static dladm_status_t
38 39 ibd_dladm_door_call(dladm_handle_t handle, void *arg, size_t asize, void *rbuf,
39 40 size_t rsize)
40 41 {
41 42 door_arg_t darg;
42 43 int door_fd;
43 44 dladm_status_t status = DLADM_STATUS_OK;
44 45
45 46 darg.data_ptr = arg;
46 47 darg.data_size = asize;
47 48 darg.desc_ptr = NULL;
48 49 darg.desc_num = 0;
49 50 darg.rbuf = rbuf;
50 51 darg.rsize = rsize;
51 52
52 53 /* The door descriptor is opened if it isn't already */
53 54 if ((status = dladm_door_fd(handle, &door_fd)) != DLADM_STATUS_OK)
54 55 return (status);
55 56
56 57 if (door_call(door_fd, &darg) == -1)
57 58 return (DLADM_STATUS_FAILED);
58 59
59 60 if (darg.rbuf != rbuf) {
60 61 /*
61 62 * The size of the input rbuf is not big enough so that
62 63 * the door allocate the rbuf itself. In this case, simply
63 64 * think something wrong with the door call.
64 65 */
65 66 (void) munmap(darg.rbuf, darg.rsize);
66 67 return (DLADM_STATUS_TOOSMALL);
67 68 }
68 69
69 70 if (darg.rsize != rsize)
70 71 return (DLADM_STATUS_FAILED);
71 72
72 73 if ((((dlmgmt_retval_t *)rbuf)->lr_err) == 0)
73 74 return (DLADM_STATUS_OK);
74 75 else
75 76 return (DLADM_STATUS_FAILED);
76 77 }
77 78
78 79 static int
|
↓ open down ↓ |
45 lines elided |
↑ open up ↑ |
79 80 ibd_delete_link(dladm_handle_t dlh, char *link)
80 81 {
81 82 dlmgmt_door_getlinkid_t getlinkid;
82 83 dlmgmt_getlinkid_retval_t retval;
83 84 datalink_id_t linkid;
84 85 dladm_status_t status;
85 86 char errmsg[DLADM_STRSIZE];
86 87
87 88 getlinkid.ld_cmd = DLMGMT_CMD_GETLINKID;
88 89 (void) strlcpy(getlinkid.ld_link, link, MAXLINKNAMELEN);
90 + getlinkid.ld_zoneid = -1;
89 91
90 92 if ((status = ibd_dladm_door_call(dlh, &getlinkid, sizeof (getlinkid),
91 93 &retval, sizeof (retval))) != DLADM_STATUS_OK) {
92 94 (void) fprintf(stderr,
93 95 "dladm_door_call failed: %s; linkname = %s\n",
94 96 dladm_status2str(status, errmsg), link);
95 97 return (status);
96 98 }
97 99
98 100 if (retval.lr_class != DATALINK_CLASS_PHYS) {
99 101 (void) fprintf(stderr,
100 102 "Not a physical link: linkname = %s, class = 0x%x\n",
101 103 link, (uint_t)retval.lr_class);
102 104 return (status);
103 105 }
104 106
105 107 linkid = retval.lr_linkid;
106 108
107 109 if ((status = dladm_remove_conf(dlh, linkid)) != DLADM_STATUS_OK) {
108 110 (void) fprintf(stderr, "dladm_remove_conf failed: %s\n",
109 111 dladm_status2str(status, errmsg));
110 112 return (status);
111 113 }
112 114
113 115 if ((status = dladm_destroy_datalink_id(dlh, linkid,
114 116 DLADM_OPT_ACTIVE | DLADM_OPT_PERSIST)) != DLADM_STATUS_OK) {
115 117 (void) fprintf(stderr, "dladm_destroy_datalink_id failed: %s\n",
116 118 dladm_status2str(status, errmsg));
117 119 }
118 120
119 121 return (status);
120 122 }
121 123
122 124 int
123 125 main(int argc, char *argv[])
124 126 {
125 127 dladm_handle_t dlh;
126 128 int i;
127 129 dladm_status_t status;
128 130 char errmsg[DLADM_STRSIZE];
129 131
130 132 if (argc < 2) {
131 133 (void) fprintf(stderr,
132 134 "Usage: ibd_delete_link linkname ...\n");
133 135 return (2);
134 136 }
135 137
136 138 if ((status = dladm_open(&dlh)) != DLADM_STATUS_OK) {
137 139 (void) fprintf(stderr, "Failed to open dladm handle: %s\n",
138 140 dladm_status2str(status, errmsg));
139 141 return (1);
140 142 }
141 143
142 144 for (i = 1; i < argc; i++) {
143 145 if (ibd_delete_link(dlh, argv[i]) != DLADM_STATUS_OK) {
144 146 dladm_close(dlh);
145 147 return (1);
146 148 }
147 149 }
148 150
149 151 dladm_close(dlh);
150 152 return (0);
151 153 }
|
↓ open down ↓ |
53 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX