14520Snw141292 /* 24520Snw141292 * CDDL HEADER START 34520Snw141292 * 44520Snw141292 * The contents of this file are subject to the terms of the 54520Snw141292 * Common Development and Distribution License (the "License"). 64520Snw141292 * You may not use this file except in compliance with the License. 74520Snw141292 * 84520Snw141292 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 94520Snw141292 * or http://www.opensolaris.org/os/licensing. 104520Snw141292 * See the License for the specific language governing permissions 114520Snw141292 * and limitations under the License. 124520Snw141292 * 134520Snw141292 * When distributing Covered Code, include this CDDL HEADER in each 144520Snw141292 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 154520Snw141292 * If applicable, add the following below this CDDL HEADER, with the 164520Snw141292 * fields enclosed by brackets "[]" replaced with your own identifying 174520Snw141292 * information: Portions Copyright [yyyy] [name of copyright owner] 184520Snw141292 * 194520Snw141292 * CDDL HEADER END 204520Snw141292 */ 214520Snw141292 /* 224520Snw141292 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 234520Snw141292 * Use is subject to license terms. 244520Snw141292 */ 254520Snw141292 264520Snw141292 #pragma ident "%Z%%M% %I% %E% SMI" 274520Snw141292 284520Snw141292 /* 294520Snw141292 * Utility routines 304520Snw141292 */ 314520Snw141292 324520Snw141292 #include <stdio.h> 334520Snw141292 #include <stdlib.h> 344520Snw141292 #include <errno.h> 354520Snw141292 #include <libintl.h> 364520Snw141292 #include "idmap_impl.h" 374520Snw141292 384520Snw141292 #define _UDT_SIZE_INCR 1 394520Snw141292 404520Snw141292 #define _GET_IDS_SIZE_INCR 1 414520Snw141292 424520Snw141292 static struct timeval TIMEOUT = { 25, 0 }; 434520Snw141292 444520Snw141292 idmap_retcode 45*4644Sbaban _udt_extend_batch(idmap_udt_handle_t *udthandle) { 464520Snw141292 idmap_update_op *tmplist; 474520Snw141292 size_t nsize; 484520Snw141292 494520Snw141292 if (udthandle->next >= udthandle->batch.idmap_update_batch_len) { 504520Snw141292 nsize = (udthandle->batch.idmap_update_batch_len + 514520Snw141292 _UDT_SIZE_INCR) * sizeof (*tmplist); 524520Snw141292 tmplist = realloc( 534520Snw141292 udthandle->batch.idmap_update_batch_val, nsize); 544520Snw141292 if (tmplist == NULL) 554520Snw141292 return (IDMAP_ERR_MEMORY); 564520Snw141292 (void) memset((uchar_t *)tmplist + 574520Snw141292 (udthandle->batch.idmap_update_batch_len * 584520Snw141292 sizeof (*tmplist)), 0, 594520Snw141292 _UDT_SIZE_INCR * sizeof (*tmplist)); 604520Snw141292 udthandle->batch.idmap_update_batch_val = tmplist; 614520Snw141292 udthandle->batch.idmap_update_batch_len += _UDT_SIZE_INCR; 624520Snw141292 } 634520Snw141292 udthandle->batch.idmap_update_batch_val[udthandle->next].opnum = 64*4644Sbaban OP_NONE; 654520Snw141292 return (IDMAP_SUCCESS); 664520Snw141292 } 674520Snw141292 684520Snw141292 idmap_retcode 694520Snw141292 _get_ids_extend_batch(idmap_get_handle_t *gh) { 704520Snw141292 idmap_mapping *t1; 714520Snw141292 idmap_get_res_t *t2; 724520Snw141292 size_t nsize, len; 734520Snw141292 744520Snw141292 len = gh->batch.idmap_mapping_batch_len; 754520Snw141292 if (gh->next >= len) { 764520Snw141292 /* extend the request array */ 774520Snw141292 nsize = (len + _GET_IDS_SIZE_INCR) * sizeof (*t1); 784520Snw141292 t1 = realloc(gh->batch.idmap_mapping_batch_val, nsize); 794520Snw141292 if (t1 == NULL) 804520Snw141292 return (IDMAP_ERR_MEMORY); 814520Snw141292 (void) memset((uchar_t *)t1 + (len * sizeof (*t1)), 0, 824520Snw141292 _GET_IDS_SIZE_INCR * sizeof (*t1)); 834520Snw141292 gh->batch.idmap_mapping_batch_val = t1; 844520Snw141292 854520Snw141292 /* extend the return list */ 864520Snw141292 nsize = (len + _GET_IDS_SIZE_INCR) * sizeof (*t2); 874520Snw141292 t2 = realloc(gh->retlist, nsize); 884520Snw141292 if (t2 == NULL) 894520Snw141292 return (IDMAP_ERR_MEMORY); 904520Snw141292 (void) memset((uchar_t *)t2 + (len * sizeof (*t2)), 0, 914520Snw141292 _GET_IDS_SIZE_INCR * sizeof (*t2)); 924520Snw141292 gh->retlist = t2; 934520Snw141292 944520Snw141292 gh->batch.idmap_mapping_batch_len += _GET_IDS_SIZE_INCR; 954520Snw141292 } 964520Snw141292 return (IDMAP_SUCCESS); 974520Snw141292 } 984520Snw141292 994520Snw141292 idmap_stat 1004520Snw141292 _iter_get_next_list(int type, idmap_iter_t *iter, 1014520Snw141292 void *arg, uchar_t **list, size_t valsize, 1024520Snw141292 xdrproc_t xdr_arg_proc, xdrproc_t xdr_res_proc) { 1034520Snw141292 1044520Snw141292 CLIENT *clnt; 1054520Snw141292 enum clnt_stat clntstat; 1064520Snw141292 1074520Snw141292 iter->next = 0; 1084520Snw141292 iter->retlist = NULL; 1094520Snw141292 _IDMAP_GET_CLIENT_HANDLE(iter->ih, clnt); 1104520Snw141292 1114520Snw141292 /* init the result */ 1124520Snw141292 if (*list) { 1134520Snw141292 xdr_free(xdr_res_proc, (caddr_t)*list); 1144520Snw141292 } else { 1154520Snw141292 if ((*list = malloc(valsize)) == NULL) { 1164520Snw141292 errno = ENOMEM; 1174520Snw141292 return (IDMAP_ERR_MEMORY); 1184520Snw141292 } 1194520Snw141292 } 1204520Snw141292 (void) memset(*list, 0, valsize); 1214520Snw141292 1224520Snw141292 clntstat = clnt_call(clnt, type, 1234520Snw141292 xdr_arg_proc, (caddr_t)arg, 1244520Snw141292 xdr_res_proc, (caddr_t)*list, 1254520Snw141292 TIMEOUT); 1264520Snw141292 if (clntstat != RPC_SUCCESS) { 1274520Snw141292 free(*list); 128*4644Sbaban return (_idmap_rpc2stat(clnt)); 1294520Snw141292 } 1304520Snw141292 iter->retlist = *list; 1314520Snw141292 return (IDMAP_SUCCESS); 1324520Snw141292 } 133*4644Sbaban 134*4644Sbaban idmap_stat 135*4644Sbaban _idmap_rpc2stat(CLIENT *clnt) { 136*4644Sbaban /* 137*4644Sbaban * We only deal with door_call(3C) errors here. We look at 138*4644Sbaban * r_err.re_errno instead of r_err.re_status because we need 139*4644Sbaban * to differentiate between RPC failures caused by bad door fd 140*4644Sbaban * and others. 141*4644Sbaban */ 142*4644Sbaban struct rpc_err r_err; 143*4644Sbaban if (clnt) { 144*4644Sbaban clnt_geterr(clnt, &r_err); 145*4644Sbaban errno = r_err.re_errno; 146*4644Sbaban switch (r_err.re_errno) { 147*4644Sbaban case ENOMEM: 148*4644Sbaban return (IDMAP_ERR_MEMORY); 149*4644Sbaban case EBADF: 150*4644Sbaban return (IDMAP_ERR_RPC_HANDLE); 151*4644Sbaban default: 152*4644Sbaban return (IDMAP_ERR_RPC); 153*4644Sbaban } 154*4644Sbaban } 155*4644Sbaban 156*4644Sbaban /* null handle */ 157*4644Sbaban return (IDMAP_ERR_RPC_HANDLE); 158*4644Sbaban } 159