16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * This file contains code imported from the OFED rds source file info.c
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * Oracle elects to have and use the contents of info.c under and governed
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * by the OpenIB.org BSD license (see below for full license text). However,
16e76cdd6e3cfaac7d91c3b0644ee1bc6cf52347agiri * the following notice accompanied the original version of this file:
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"
fe817b6022080da0a98b5d2d8cd179f594d6ca5eEiji Otastatic rdsv3_info_func rdsv3_info_funcs[RDS_INFO_LAST - RDS_INFO_FIRST + 1];
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_info_register_func(int optname, rdsv3_info_func func)
fe817b6022080da0a98b5d2d8cd179f594d6ca5eEiji Ota ASSERT(optname >= RDS_INFO_FIRST && optname <= RDS_INFO_LAST);
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Ota/* ARGSUSED */
c0dd49bdd68c0d758a67d56f07826f3b45cfc664Eiji Otardsv3_info_deregister_func(int optname, rdsv3_info_func func)
fe817b6022080da0a98b5d2d8cd179f594d6ca5eEiji Ota ASSERT(optname >= RDS_INFO_FIRST && optname <= RDS_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,
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);