info.c revision b27516f55237249607f754e6e42e865f12456675
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * CDDL HEADER START
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * The contents of this file are subject to the terms of the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Common Development and Distribution License (the "License").
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * You may not use this file except in compliance with the License.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * See the License for the specific language governing permissions
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * and limitations under the License.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * When distributing Covered Code, include this CDDL HEADER in each
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * If applicable, add the following below this CDDL HEADER, with the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * fields enclosed by brackets "[]" replaced with your own identifying
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * information: Portions Copyright [yyyy] [name of copyright owner]
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * CDDL HEADER END
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Copyright (c) 2006 Oracle. All rights reserved.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This software is available to you under a choice of one of two
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * licenses. You may choose to be licensed under the terms of the GNU
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * General Public License (GPL) Version 2, available from the file
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * COPYING in the main directory of this source tree, or the
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * OpenIB.org BSD license below:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * Redistribution and use in source and binary forms, with or
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * without modification, are permitted provided that the following
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * conditions are met:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - Redistributions of source code must retain the above
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * copyright notice, this list of conditions and the following
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * disclaimer.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - Redistributions in binary form must reproduce the above
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * copyright notice, this list of conditions and the following
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * disclaimer in the documentation and/or other materials
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * provided with the distribution.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * SOFTWARE.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This file implements a getsockopt() call which copies a set of fixed
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * sized structs into a user-specified buffer as a means of providing
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * read-only information about RDS.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * For a given information source there are a given number of fixed sized
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * structs at a given time. The structs are only copied if the user-specified
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * buffer is big enough. The destination pages that make up the buffer
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * are pinned for the duration of the copy.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This gives us the following benefits:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - simple implementation, no copy "position" across multiple calls
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - consistent snapshot of an info source
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - atomic copy works well with whatever locking info source has
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - one portable tool to get rds info across implementations
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - long-lived tool can get info without allocating
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * at the following costs:
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * - info source copy must be pinned, may be "large"
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otastatic rdsv3_info_func rdsv3_info_funcs[RDSV3_INFO_LAST - RDSV3_INFO_FIRST + 1];
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_info_register_func(int optname, rdsv3_info_func func)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ASSERT(optname >= RDSV3_INFO_FIRST && optname <= RDSV3_INFO_LAST);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* ARGSUSED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_info_deregister_func(int optname, rdsv3_info_func func)
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota ASSERT(optname >= RDSV3_INFO_FIRST && optname <= RDSV3_INFO_LAST);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * @optval points to the userspace buffer that the information snapshot
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * will be copied into.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * This function returns -errno if there is a failure, particularly -ENOSPC
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * if the given userspace buffer was not large enough to fit the snapshot.
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * On success it returns the positive number of bytes of each array element
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota * in the snapshot.
b27516f55237249607f754e6e42e865f12456675agirirdsv3_info_ioctl(struct rsock *sock, int optname, char *optval,
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota func = rdsv3_info_funcs[optname - RDSV3_INFO_FIRST];
b27516f55237249607f754e6e42e865f12456675agiri if (ddi_copyin(optval, &arg, sizeof (struct rds_info_arg), 0) != 0) {
b27516f55237249607f754e6e42e865f12456675agiri "optname: %d lenp: %llx datap: %llx", optname, arg.lenp, arg.datap);
b27516f55237249607f754e6e42e865f12456675agiri RDSV3_DPRINTF2("rdsv3_info_ioctl", "arg.lenp is NULL");
b27516f55237249607f754e6e42e865f12456675agiri sizeof (uint32_t), 0) != 0) {
b27516f55237249607f754e6e42e865f12456675agiri "ddi_copyin for address, lenp: 0x%p failed", arg.lenp);
b27516f55237249607f754e6e42e865f12456675agiri RDSV3_DPRINTF3("rdsv3_info_ioctl", "optname: %d len: %d datap: %p",
b27516f55237249607f754e6e42e865f12456675agiri /* a 0 len call is just trying to probe its length */
b27516f55237249607f754e6e42e865f12456675agiri if (ulen == 0) {
b27516f55237249607f754e6e42e865f12456675agiri sizeof (uint32_t), 0) != 0) {
b27516f55237249607f754e6e42e865f12456675agiri "optname: %d ulen: %d klen: %d each: %d", optname, ulen, klen,
b27516f55237249607f754e6e42e865f12456675agiri RDSV3_DPRINTF4("rdsv3_info_ioctl", "Return optname: %d", optname);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota return (0);