diff --git a/META b/META index 4059082b98..1e1c6fba9d 100644 --- a/META +++ b/META @@ -1,7 +1,7 @@ Meta: 1 Name: zfs Branch: 1.0 -Version: 0.4.9 +Version: 0.5.0 Release: 1 Release-Tags: relext License: CDDL diff --git a/cmd/zdb/zdb.c b/cmd/zdb/zdb.c index 933ae0999b..d9bda79055 100644 --- a/cmd/zdb/zdb.c +++ b/cmd/zdb/zdb.c @@ -2409,8 +2409,11 @@ dump_simulated_ddt(spa_t *spa) avl_tree_t t; void *cookie = NULL; zdb_ddt_entry_t *zdde; - ddt_histogram_t ddh_total = { 0 }; - ddt_stat_t dds_total = { 0 }; + ddt_histogram_t ddh_total; + ddt_stat_t dds_total; + + bzero(&ddh_total, sizeof (ddt_histogram_t)); + bzero(&dds_total, sizeof (ddt_stat_t)); avl_create(&t, ddt_entry_compare, sizeof (zdb_ddt_entry_t), offsetof(zdb_ddt_entry_t, zdde_node)); diff --git a/lib/libspl/Makefile.am b/lib/libspl/Makefile.am index c4bdcef09b..5005a2c6f8 100644 --- a/lib/libspl/Makefile.am +++ b/lib/libspl/Makefile.am @@ -17,10 +17,13 @@ libspl_la_SOURCES = \ ${top_srcdir}/lib/libspl/gethrestime.c \ ${top_srcdir}/lib/libspl/getmntany.c \ ${top_srcdir}/lib/libspl/list.c \ + ${top_srcdir}/lib/libspl/ltos.c \ ${top_srcdir}/lib/libspl/mkdirp.c \ + ${top_srcdir}/lib/libspl/stol.c \ ${top_srcdir}/lib/libspl/strlcat.c \ ${top_srcdir}/lib/libspl/strlcpy.c \ ${top_srcdir}/lib/libspl/strnlen.c \ + ${top_srcdir}/lib/libspl/timestamp.c \ ${top_srcdir}/lib/libspl/zone.c \ ${top_srcdir}/lib/libspl/xdr.c \ ${top_srcdir}/lib/libspl/${TARGET_ASM_DIR}/atomic.S \ diff --git a/lib/libspl/include/label.h b/lib/libspl/include/label.h new file mode 100644 index 0000000000..370b63eaf9 --- /dev/null +++ b/lib/libspl/include/label.h @@ -0,0 +1,240 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _TSOL_LABEL_H +#define _TSOL_LABEL_H + +#include +#include +#include + +/* Procedural Interface Structure Definitions */ + +struct label_info { /* structure returned by label_info */ + short ilabel_len; /* max Information Label length */ + short slabel_len; /* max Sensitivity Label length */ + short clabel_len; /* max CMW Label length */ + short clear_len; /* max Clearance Label length */ + short vers_len; /* version string length */ + short header_len; /* max len of banner page header */ + short protect_as_len; /* max len of banner page protect as */ + short caveats_len; /* max len of banner page caveats */ + short channels_len; /* max len of banner page channels */ +}; + +typedef struct label_set_identifier { /* valid label set identifier */ + int type; /* type of the set */ + char *name; /* name of the set if needed */ +} set_id; + +struct name_fields { /* names for label builder fields */ + char *class_name; /* Classifications field name */ + char *comps_name; /* Compartments field name */ + char *marks_name; /* Markings field name */ +}; + +/* Label Set Identifier Types */ + +/* + * The accreditation ranges as specified in the label encodings file. + * The name parameter is ignored. + * + * System Accreditation Range is all valid labels plus Admin High and Low. + * + * User Accreditation Range is valid user labels as defined in the + * ACCREDITATION RANGE: section of the label encodings file. + */ + +#define SYSTEM_ACCREDITATION_RANGE 1 +#define USER_ACCREDITATION_RANGE 2 + + +/* System Call Interface Definitions */ + +extern int getlabel(const char *, m_label_t *); +extern int fgetlabel(int, m_label_t *); + +extern int getplabel(m_label_t *); +extern int setflabel(const char *, m_label_t *); +extern char *getpathbylabel(const char *, char *, size_t, + const m_label_t *sl); +extern m_label_t *getzonelabelbyid(zoneid_t); +extern m_label_t *getzonelabelbyname(const char *); +extern zoneid_t getzoneidbylabel(const m_label_t *); +extern char *getzonenamebylabel(const m_label_t *); +extern char *getzonerootbyid(zoneid_t); +extern char *getzonerootbyname(const char *); +extern char *getzonerootbylabel(const m_label_t *); +extern m_label_t *getlabelbypath(const char *); + + +/* Flag word values */ + +#define ALL_ENTRIES 0x00000000 +#define ACCESS_RELATED 0x00000001 +#define ACCESS_MASK 0x0000FFFF +#define ACCESS_SHIFT 0 + +#define LONG_WORDS 0x00010000 /* use long names */ +#define SHORT_WORDS 0x00020000 /* use short names if present */ +#define LONG_CLASSIFICATION 0x00040000 /* use long classification */ +#define SHORT_CLASSIFICATION 0x00080000 /* use short classification */ +#define NO_CLASSIFICATION 0x00100000 /* don't translate the class */ +#define VIEW_INTERNAL 0x00200000 /* don't promote/demote */ +#define VIEW_EXTERNAL 0x00400000 /* promote/demote label */ + +#define NEW_LABEL 0x00000001 /* create a full new label */ +#define NO_CORRECTION 0x00000002 /* don't correct label errors */ + /* implies NEW_LABEL */ + +#define CVT_DIM 0x01 /* display word dimmed */ +#define CVT_SET 0x02 /* display word currently set */ + +/* Procedure Interface Definitions available to user */ + +/* APIs shared with the kernel are in +#include +#include + +/* + * Definitions for the call parameters for the door-based label + * translation service. + */ + +#define BUFSIZE 4096 + +#define DOOR_PATH "/var/tsol/doors/" +#define DOOR_NAME "labeld" +#define COOKIE (void *)0x6c616264 /* "labd" */ + +/* Op codes */ + +/* Labeld Commands */ + +#define LABELDNULL 1 + +/* Miscellaneous */ + +#define BLINSET 10 +#define BSLVALID 11 +#define BILVALID 12 +#define BCLEARVALID 13 +#define LABELINFO 14 +#define LABELVERS 15 +#define BLTOCOLOR 16 + +/* Binary to String Label Translation */ + +#define BSLTOS 23 +#define BCLEARTOS 25 + +/* String to Binary Label Translation */ + +#define STOBSL 31 +#define STOBCLEAR 33 + +/* + * Dimming List Routines + * Contract private for label builders + */ + +#define BSLCVT 40 +#define BCLEARCVT 42 +#define LABELFIELDS 43 +#define UDEFS 44 + +#define GETFLABEL 45 +#define SETFLABEL 46 +#define ZCOPY 47 + +/* NEW LABELS */ +/* DIA printer banner labels */ + +#define PR_CAVEATS 101 +#define PR_CHANNELS 102 +#define PR_LABEL 103 +#define PR_TOP 104 + +/* DIA label to string */ + +#define LTOS 105 + +/* DIA string to label */ + +#define STOL 106 + +/* Structures */ + +typedef uint_t bufp_t; /* offset into buf[] in/out string buffer */ + +/* Null call */ + +typedef struct { + int null; +} null_call_t; + +typedef struct { + int null; +} null_ret_t; + +/* Miscellaneous interfaces */ + +typedef struct { + bslabel_t label; + int type; +} inset_call_t; + +typedef struct { + int inset; +} inset_ret_t; + +typedef struct { + bslabel_t label; +} slvalid_call_t; + +typedef struct { + int valid; +} slvalid_ret_t; + +typedef struct { + bclear_t clear; +} clrvalid_call_t; + +typedef struct { + int valid; +} clrvalid_ret_t; + +typedef struct { + int null; +} info_call_t; + +typedef struct { + struct label_info info; +} info_ret_t; + +typedef struct { + int null; +} vers_call_t; + +typedef struct { + char vers[BUFSIZE]; +} vers_ret_t; + +typedef struct { + blevel_t label; +} color_call_t; + +typedef struct { + char color[BUFSIZE]; +} color_ret_t; + +/* Binary Label to String interfaces */ + +typedef struct { + bslabel_t label; + uint_t flags; +} bsltos_call_t; + +typedef struct { + char slabel[BUFSIZE]; +} bsltos_ret_t; + +typedef struct { + bclear_t clear; + uint_t flags; +} bcleartos_call_t; + +typedef struct { + char cslabel[BUFSIZE]; +} bcleartos_ret_t; + +/* String to Binary Label interfaces */ + +typedef struct { + bslabel_t label; + uint_t flags; + char string[BUFSIZE]; +} stobsl_call_t; + +typedef struct { + bslabel_t label; +} stobsl_ret_t; + +typedef struct { + bclear_t clear; + uint_t flags; + char string[BUFSIZE]; +} stobclear_call_t; + +typedef struct { + bclear_t clear; +} stobclear_ret_t; + +/* + * The following Dimming List and Miscellaneous interfaces + * implement contract private interfaces for the label builder + * interfaces. + */ + +/* Dimming List interfaces */ + +typedef struct { + bslabel_t label; + brange_t bounds; + uint_t flags; +} bslcvt_call_t; + +typedef struct { + bufp_t string; + bufp_t dim; + bufp_t lwords; + bufp_t swords; + size_t d_len; + size_t l_len; + size_t s_len; + int first_comp; + int first_mark; + char buf[BUFSIZE]; +} cvt_ret_t; + +typedef cvt_ret_t bslcvt_ret_t; + +typedef struct { + bclear_t clear; + brange_t bounds; + uint_t flags; +} bclearcvt_call_t; + +typedef cvt_ret_t bclearcvt_ret_t; + +/* Miscellaneous interfaces */ + +typedef struct { + int null; +} fields_call_t; + +typedef struct { + bufp_t classi; + bufp_t compsi; + bufp_t marksi; + char buf[BUFSIZE]; +} fields_ret_t; + +typedef struct { + int null; +} udefs_call_t; + +typedef struct { + bslabel_t sl; + bclear_t clear; +} udefs_ret_t; + +typedef struct { + bslabel_t sl; + char pathname[BUFSIZE]; +} setfbcl_call_t; + +typedef struct { + int status; +} setfbcl_ret_t; + +typedef struct { + bslabel_t src_win_sl; + int transfer_mode; + bufp_t remote_dir; + bufp_t filename; + bufp_t local_dir; + bufp_t display; + char buf[BUFSIZE]; +} zcopy_call_t; + +typedef struct { + int status; +} zcopy_ret_t; + +typedef struct { + m_label_t label; + uint_t flags; +} pr_call_t; + +typedef struct { + char buf[BUFSIZE]; +} pr_ret_t; + +typedef struct { + m_label_t label; + uint_t flags; +} ls_call_t; + +typedef struct { + char buf[BUFSIZE]; +} ls_ret_t; + +typedef struct { + m_label_t label; + uint_t flags; + char string[BUFSIZE]; +} sl_call_t; + +typedef struct { + m_label_t label; +} sl_ret_t; + +/* Labeld operation call structure */ + +typedef struct { + uint_t op; + union { + null_call_t null_arg; + + inset_call_t inset_arg; + slvalid_call_t slvalid_arg; + clrvalid_call_t clrvalid_arg; + info_call_t info_arg; + vers_call_t vers_arg; + color_call_t color_arg; + + bsltos_call_t bsltos_arg; + bcleartos_call_t bcleartos_arg; + + stobsl_call_t stobsl_arg; + stobclear_call_t stobclear_arg; + + bslcvt_call_t bslcvt_arg; + bclearcvt_call_t bclearcvt_arg; + fields_call_t fields_arg; + udefs_call_t udefs_arg; + setfbcl_call_t setfbcl_arg; + zcopy_call_t zcopy_arg; + pr_call_t pr_arg; + ls_call_t ls_arg; + sl_call_t sl_arg; + } cargs; +} labeld_call_t; + +/* Labeld operation return structure */ + +typedef struct { + int ret; /* labeld return codes */ + int err; /* function error codes */ + union { + null_ret_t null_ret; + + inset_ret_t inset_ret; + slvalid_ret_t slvalid_ret; + clrvalid_ret_t clrvalid_ret; + info_ret_t info_ret; + vers_ret_t vers_ret; + color_ret_t color_ret; + + bsltos_ret_t bsltos_ret; + bcleartos_ret_t bcleartos_ret; + + stobsl_ret_t stobsl_ret; + stobclear_ret_t stobclear_ret; + + bslcvt_ret_t bslcvt_ret; + bclearcvt_ret_t bclearcvt_ret; + fields_ret_t fields_ret; + udefs_ret_t udefs_ret; + setfbcl_ret_t setfbcl_ret; + zcopy_ret_t zcopy_ret; + pr_ret_t pr_ret; + ls_ret_t ls_ret; + sl_ret_t sl_ret; + } rvals; +} labeld_ret_t; + +/* Labeld call/return structure */ + +typedef struct { + union { + labeld_call_t acall; + labeld_ret_t aret; + } param; +} labeld_data_t; + +#define callop param.acall.op +#define retret param.aret.ret +#define reterr param.aret.err + +#define CALL_SIZE(type, buf) (size_t)(sizeof (type) + sizeof (int) + (buf)) +#define RET_SIZE(type, buf) (size_t)(sizeof (type) + 2*sizeof (int) + (buf)) +#define CALL_SIZE_STR(type, buf) CALL_SIZE(type, (-BUFSIZE +(buf))) + +/* Return Codes */ + +#define SUCCESS 1 /* Call OK */ +#define NOTFOUND -1 /* Function not found */ +#define SERVERFAULT -2 /* Internal labeld error */ +#define NOSERVER -3 /* No server thread available, try later */ + +/* Labeld common client call function */ + +static inline int +__call_labeld(labeld_data_t **dptr, size_t *ndata, size_t *adata) +{ + return NOSERVER; +} + +/* Flag Translation Values */ + +#define L_NEW_LABEL 0x10000000 + +/* GFI FLAGS */ + +#define GFI_FLAG_MASK 0x0000FFFF +#define GFI_ACCESS_RELATED 0x00000001 + +/* binary to ASCII */ + +#define LABELS_NO_CLASS 0x00010000 +#define LABELS_SHORT_CLASS 0x00020000 +#define LABELS_SHORT_WORDS 0x00040000 + +/* Label view */ + +#define LABELS_VIEW_INTERNAL 0x00100000 +#define LABELS_VIEW_EXTERNAL 0x00200000 + +/* Dimming list (convert -- b*cvt* ) */ + +#define LABELS_FULL_CONVERT 0x00010000 + +/* ASCII to binary */ + +#define LABELS_NEW_LABEL 0x00010000 +#define LABELS_FULL_PARSE 0x00020000 +#define LABELS_ONLY_INFO_LABEL 0x00040000 + +#define MOVE_FILE 0 +#define COPY_FILE 1 +#define LINK_FILE 2 + +#define PIPEMSG_FILEOP_ERROR 1 +#define PIPEMSG_EXIST_ERROR 2 +#define PIPEMSG_DONE 7 +#define PIPEMSG_PATH_ERROR 20 +#define PIPEMSG_ZONE_ERROR 21 +#define PIPEMSG_LABEL_ERROR 22 +#define PIPEMSG_READ_ERROR 23 +#define PIPEMSG_READONLY_ERROR 24 +#define PIPEMSG_WRITE_ERROR 25 +#define PIPEMSG_CREATE_ERROR 26 +#define PIPEMSG_DELETE_ERROR 27 +#define PIPEMSG_CANCEL 101 +#define PIPEMSG_PROCEED 102 +#define PIPEMSG_MERGE 103 +#define PIPEMSG_REPLACE_BUFFER 104 +#define PIPEMSG_RENAME_BUFFER 105 +#define PIPEMSG_MULTI_PROCEED 106 +#define PIPEMSG_RENAME_FILE 107 + +#endif /* _LABELD_H */ diff --git a/lib/libspl/include/priv.h b/lib/libspl/include/priv.h index 6c9a2c0e66..3e8b138a02 100644 --- a/lib/libspl/include/priv.h +++ b/lib/libspl/include/priv.h @@ -32,6 +32,15 @@ /* Couldn't find this definition in OpenGrok */ #define PRIV_SYS_CONFIG "sys_config" +/* + * priv_op_t indicates a privilege operation type + */ +typedef enum priv_op { + PRIV_ON, + PRIV_OFF, + PRIV_SET +} priv_op_t; + static inline boolean_t priv_ineffect(const char *priv) { return B_TRUE; } #endif diff --git a/lib/libspl/include/statcommon.h b/lib/libspl/include/statcommon.h new file mode 100644 index 0000000000..1f376f5c7c --- /dev/null +++ b/lib/libspl/include/statcommon.h @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + * + * Common routines for acquiring snapshots of kstats for + * iostat, mpstat, and vmstat. + */ + +#ifndef _STATCOMMON_H +#define _STATCOMMON_H + +#include + +#define NODATE 0 /* Default: No time stamp */ +#define DDATE 1 /* Standard date format */ +#define UDATE 2 /* Internal representation of Unix time */ + +/* Print a timestamp in either Unix or standard format. */ +void print_timestamp(uint_t); + +#endif /* _STATCOMMON_H */ diff --git a/lib/libspl/include/sys/systm.h b/lib/libspl/include/sys/systm.h new file mode 100644 index 0000000000..5cb088dcc9 --- /dev/null +++ b/lib/libspl/include/sys/systm.h @@ -0,0 +1,30 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _LIBSPL_SYS_SYSTM_H +#define _LIBSPL_SYS_SYSTM_H + +#endif /* _LIBSPL_SYS_SYSTM_H */ diff --git a/lib/libspl/include/sys/time.h b/lib/libspl/include/sys/time.h index dc6e4f574f..0cbbd928db 100644 --- a/lib/libspl/include/sys/time.h +++ b/lib/libspl/include/sys/time.h @@ -30,6 +30,18 @@ #include_next #include +#ifndef SEC +#define SEC 1 +#endif + +#ifndef MILLISEC +#define MILLISEC 1000 +#endif + +#ifndef MICROSEC +#define MICROSEC 1000000 +#endif + #ifndef NANOSEC #define NANOSEC 1000000000 #endif @@ -41,4 +53,4 @@ extern hrtime_t gethrtime(void); extern void gethrestime(timestruc_t *); -#endif +#endif /* _LIBSPL_SYS_TIME_H */ diff --git a/lib/libspl/include/sys/tsol/label.h b/lib/libspl/include/sys/tsol/label.h new file mode 100644 index 0000000000..f88f40973d --- /dev/null +++ b/lib/libspl/include/sys/tsol/label.h @@ -0,0 +1,168 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _SYS_TSOL_LABEL_H +#define _SYS_TSOL_LABEL_H + +#include +#ifdef _KERNEL +#include +#include +#include +#endif /* _KERNEL */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * types of label comparison + */ +#define EQUALITY_CHECK 0 +#define DOMINANCE_CHECK 1 + +/* Manifest human readable label names */ +#define ADMIN_LOW "ADMIN_LOW" +#define ADMIN_HIGH "ADMIN_HIGH" + +/* Binary Label Structure Definitions */ + +typedef struct _mac_label_impl m_label_t; + +typedef m_label_t blevel_t, /* compatibility */ + bslabel_t, /* Sensitivity Label */ + bclear_t; /* Clearance */ + +typedef struct _tsol_binary_level_lrange { /* Level Range */ + m_label_t *lower_bound; + m_label_t *upper_bound; +} m_range_t; + +typedef m_range_t blrange_t; + +typedef struct tsol_mlp_s { + uchar_t mlp_ipp; + uint16_t mlp_port; + uint16_t mlp_port_upper; +} tsol_mlp_t; + +/* Procedure Interface Definitions available to user and kernel */ + +extern int bltype(const void *, uint8_t); +extern int blequal(const m_label_t *, const m_label_t *); +extern int bldominates(const m_label_t *, const m_label_t *); +extern int blstrictdom(const m_label_t *, const m_label_t *); +extern int blinrange(const m_label_t *, const m_range_t *); +extern void blmaximum(m_label_t *, const m_label_t *); +extern void blminimum(m_label_t *, const m_label_t *); +extern void bsllow(m_label_t *); +extern void bslhigh(m_label_t *); +extern void bclearlow(m_label_t *); +extern void bclearhigh(m_label_t *); +extern void bslundef(m_label_t *); +extern void bclearundef(m_label_t *); +extern void setbltype(void *, uint8_t); +extern boolean_t bisinvalid(const void *); + +#ifdef _KERNEL +typedef struct tsol_mlp_entry_s { + struct tsol_mlp_entry_s *mlpe_next, *mlpe_prev; + zoneid_t mlpe_zoneid; + tsol_mlp_t mlpe_mlp; +} tsol_mlp_entry_t; + +typedef struct tsol_mlp_list_s { + krwlock_t mlpl_rwlock; + tsol_mlp_entry_t *mlpl_first, *mlpl_last; +} tsol_mlp_list_t; + +typedef struct ts_label_s { + uint_t tsl_ref; /* Reference count */ + uint32_t tsl_doi; /* Domain of Interpretation */ + uint32_t tsl_flags; /* TSLF_* below */ + m_label_t tsl_label; /* Actual label */ +} ts_label_t; + +#define DEFAULT_DOI 1 + +/* + * TSLF_UNLABELED is set in tsl_flags for packets with no explicit label + * when the peer is unlabeled. + * + * TSLF_IMPLICIT_IN is set when a packet is received with no explicit label + * from a peer which is flagged in the tnrhdb as label-aware. + * + * TSLF_IMPLICIT_OUT is set when the packet should be sent without an + * explict label even if the peer or next-hop router is flagged in the + * tnrhdb as label-aware. + */ + +#define TSLF_UNLABELED 0x00000001 /* peer is unlabeled */ +#define TSLF_IMPLICIT_IN 0x00000002 /* inbound implicit */ +#define TSLF_IMPLICIT_OUT 0x00000004 /* outbound implicit */ + +#define CR_SL(cr) (label2bslabel(crgetlabel(cr))) + +extern ts_label_t *l_admin_low; +extern ts_label_t *l_admin_high; +extern uint32_t default_doi; +extern int sys_labeling; + +extern void label_init(void); +extern ts_label_t *labelalloc(const m_label_t *, uint32_t, int); +extern ts_label_t *labeldup(const ts_label_t *, int); +extern void label_hold(ts_label_t *); +extern void label_rele(ts_label_t *); +extern m_label_t *label2bslabel(ts_label_t *); +extern uint32_t label2doi(ts_label_t *); +extern boolean_t label_equal(const ts_label_t *, const ts_label_t *); +extern cred_t *newcred_from_bslabel(m_label_t *, uint32_t, int); +extern cred_t *copycred_from_bslabel(const cred_t *, m_label_t *, + uint32_t, int); +extern cred_t *copycred_from_tslabel(const cred_t *, ts_label_t *, + int); +extern ts_label_t *getflabel(vnode_t *); +extern int getlabel(const char *, m_label_t *); +extern int fgetlabel(int, m_label_t *); +extern int _blinrange(const m_label_t *, const brange_t *); +extern int blinlset(const m_label_t *, const blset_t); + +extern int l_to_str_internal(const m_label_t *, char **); +extern int hexstr_to_label(const char *, m_label_t *); + +/* + * The use of '!!' here prevents users from referencing this function-like + * macro as though it were an l-value, and in normal use is optimized away + * by the compiler. + */ +#define is_system_labeled() (!!(sys_labeling > 0)) + +#endif /* _KERNEL */ + +#ifdef __cplusplus +} +#endif + +#endif /* !_SYS_TSOL_LABEL_H */ diff --git a/lib/libspl/include/sys/tsol/label_macro.h b/lib/libspl/include/sys/tsol/label_macro.h new file mode 100644 index 0000000000..455d70347d --- /dev/null +++ b/lib/libspl/include/sys/tsol/label_macro.h @@ -0,0 +1,351 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _LABEL_MACRO_H +#define _LABEL_MACRO_H + +#include + +/* PRIVATE ONLY TO THE LABEL LIBRARY. DO NOT USE ELSEWHERE */ + +/* Actual Binary Label Structure Definitions */ + +typedef int16_t _Classification; +typedef struct { + union { + uint8_t class_ar[2]; + _Classification class_chunk; + } class_u; +} Classification_t; + +typedef struct { + uint32_t c1; + uint32_t c2; + uint32_t c3; + uint32_t c4; + uint32_t c5; + uint32_t c6; + uint32_t c7; + uint32_t c8; +} Compartments_t; + +typedef struct { + uint32_t m1; + uint32_t m2; + uint32_t m3; + uint32_t m4; + uint32_t m5; + uint32_t m6; + uint32_t m7; + uint32_t m8; +} Markings_t; + +typedef struct _mac_label_impl { + uint8_t id; /* Magic to say label type */ + uint8_t _c_len; /* Number of Compartment words */ + Classification_t classification; + Compartments_t compartments; +} _mac_label_impl_t; + +typedef _mac_label_impl_t _blevel_impl_t, /* compatibility */ + _bslabel_impl_t, /* Sensitivity Label */ + _bclear_impl_t; /* Clearance */ + +typedef struct _binary_information_label_impl { /* Information Label */ + _mac_label_impl_t binformation_level; + Markings_t markings; +} _bilabel_impl_t; + +typedef struct _binary_cmw_label_impl { /* CMW Label */ + _bslabel_impl_t bcl_sensitivity_label; + _bilabel_impl_t bcl_information_label; +} _bclabel_impl_t; + +typedef struct _binary_level_range_impl { /* Level Range */ + _mac_label_impl_t lower_bound; + _mac_label_impl_t upper_bound; +} _brange_impl_t, brange_t; + +#define NMLP_MAX 0x10 +#define NSLS_MAX 0x4 + +typedef _mac_label_impl_t blset_t[NSLS_MAX]; + +/* Label Identifier Types */ + +#define SUN_MAC_ID 0x41 /* MAC label, legacy SUN_SL_ID */ +#define SUN_UCLR_ID 0x49 /* User Clearance, legacy SUN_CLR_ID */ + +#define _C_LEN 8 /* number of compartments words */ + +/* m_label_t macros */ +#define _MTYPE(l, t) \ + (((_mac_label_impl_t *)(l))->id == (t)) + +#define _MSETTYPE(l, t) \ + (((_mac_label_impl_t *)(l))->id = (t)) + +#define _MGETTYPE(l) (((_mac_label_impl_t *)(l))->id) + +#define _MEQUAL(l1, l2) \ + (LCLASS(l1) == LCLASS(l2) && \ + (l1)->_comps.c1 == (l2)->_comps.c1 && \ + (l1)->_comps.c2 == (l2)->_comps.c2 && \ + (l1)->_comps.c3 == (l2)->_comps.c3 && \ + (l1)->_comps.c4 == (l2)->_comps.c4 && \ + (l1)->_comps.c5 == (l2)->_comps.c5 && \ + (l1)->_comps.c6 == (l2)->_comps.c6 && \ + (l1)->_comps.c7 == (l2)->_comps.c7 && \ + (l1)->_comps.c8 == (l2)->_comps.c8) + +#define SUN_INVALID_ID 0 /* uninitialized label */ +#define SUN_CMW_ID 0x83 /* 104 - total bytes in CMW Label */ +#define SUN_SL_ID 0x41 /* 36 - total bytes in Sensitivity Label */ +#define SUN_SL_UN 0xF1 /* undefined Sensitivity Label */ +#define SUN_IL_ID 0x42 /* 68 - total bytes in Information Label */ +#define SUN_IL_UN 0x73 /* undefined Information Label */ +#define SUN_CLR_ID 0x49 /* 36 - total bytes in Clearance */ +#define SUN_CLR_UN 0xF9 /* undefined Clearance */ + +#define _bcl_sl bcl_sensitivity_label +#define _bcl_il bcl_information_label +#define _bslev_il binformation_level + +#define _lclass classification +#ifdef _BIG_ENDIAN +#define LCLASS(slp) ((slp)->_lclass.class_u.class_chunk) +#define LCLASS_SET(slp, l) ((slp)->_lclass.class_u.class_chunk = (l)) +#else +#define LCLASS(slp) \ + ((_Classification)(((slp)->_lclass.class_u.class_ar[0] << 8) | \ + (slp)->_lclass.class_u.class_ar[1])) +#define LCLASS_SET(slp, l) \ + ((slp)->_lclass.class_u.class_ar[0] = (uint8_t)((l)>> 8), \ + (slp)->_lclass.class_u.class_ar[1] = (uint8_t)(l)) +#endif /* _BIG_ENDIAN */ +#define _comps compartments + +#define _iid _bslev_il.id +#define _i_c_len _bslev_il._c_len +#define _iclass _bslev_il._lclass +#ifdef _BIG_ENDIAN +#define ICLASS(ilp) ((ilp)->_iclass.class_u.class_chunk) +#define ICLASS_SET(ilp, l) ((ilp)->_iclass.class_u.class_chunk = (l)) +#else +#define ICLASS(ilp) \ + ((_Classification)(((ilp)->_iclass.class_u.class_ar[0] << 8) | \ + (ilp)->_iclass.class_u.class_ar[1])) +#define ICLASS_SET(ilp, l) \ + ((ilp)->_iclass.class_u.class_ar[0] = (uint8_t)((l)>> 8), \ + (ilp)->_iclass.class_u.class_ar[1] = (uint8_t)(l)) +#endif /* _BIG_ENDIAN */ +#define _icomps _bslev_il._comps +#define _imarks markings + +/* Manifest Constant Values */ + +#define LOW_CLASS 0 /* Admin_Low classification value */ +#define HIGH_CLASS 0x7FFF /* Admin_High classification value */ +#define EMPTY_SET 0 /* Empty compartments and markings set */ +#define UNIVERSAL_SET 0xFFFFFFFFU /* Universal compartments and */ + /* markings set */ + +/* Construct initial labels */ + +#define _LOW_LABEL(l, t) \ + ((l)->id = t, (l)->_c_len = _C_LEN, LCLASS_SET(l, LOW_CLASS), \ + (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ + (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ + EMPTY_SET) + +#define _HIGH_LABEL(l, t) \ + ((l)->id = t, (l)->_c_len = _C_LEN, LCLASS_SET(l, HIGH_CLASS), \ + (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ + (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ + UNIVERSAL_SET) + +/* Macro equivalents */ + +/* Is this memory a properly formatted label of type t? */ +#define BLTYPE(l, t) \ + ((t) == SUN_CMW_ID ? \ + (((_bclabel_impl_t *)(l))->_bcl_sl.id == SUN_SL_ID || \ + ((_bclabel_impl_t *)(l))->_bcl_sl.id == SUN_SL_UN) && \ + (((_bclabel_impl_t *)(l))->_bcl_il._iid == SUN_IL_ID || \ + ((_bclabel_impl_t *)(l))->_bcl_il._iid == SUN_IL_UN) : \ + ((_mac_label_impl_t *)(l))->id == (t)) + +/* Are the levels of these labels equal? */ +#define BLEQUAL(l1, l2) \ + _BLEQUAL((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) + +#define _BLEQUAL(l1, l2) \ + (LCLASS(l1) == LCLASS(l2) && \ + (l1)->_comps.c1 == (l2)->_comps.c1 && \ + (l1)->_comps.c2 == (l2)->_comps.c2 && \ + (l1)->_comps.c3 == (l2)->_comps.c3 && \ + (l1)->_comps.c4 == (l2)->_comps.c4 && \ + (l1)->_comps.c5 == (l2)->_comps.c5 && \ + (l1)->_comps.c6 == (l2)->_comps.c6 && \ + (l1)->_comps.c7 == (l2)->_comps.c7 && \ + (l1)->_comps.c8 == (l2)->_comps.c8) + +/* Does the level of l1 dominate that of l2? */ +#define BLDOMINATES(l1, l2) \ + _BLDOMINATES((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) + +#define _BLDOMINATES(l1, l2) (LCLASS(l1) >= LCLASS(l2) && \ + (l2)->_comps.c1 == ((l1)->_comps.c1 & (l2)->_comps.c1) && \ + (l2)->_comps.c2 == ((l1)->_comps.c2 & (l2)->_comps.c2) && \ + (l2)->_comps.c3 == ((l1)->_comps.c3 & (l2)->_comps.c3) && \ + (l2)->_comps.c4 == ((l1)->_comps.c4 & (l2)->_comps.c4) && \ + (l2)->_comps.c5 == ((l1)->_comps.c5 & (l2)->_comps.c5) && \ + (l2)->_comps.c6 == ((l1)->_comps.c6 & (l2)->_comps.c6) && \ + (l2)->_comps.c7 == ((l1)->_comps.c7 & (l2)->_comps.c7) && \ + (l2)->_comps.c8 == ((l1)->_comps.c8 & (l2)->_comps.c8)) + +/* Does the level of l1 strictly dominate that of l2? */ +#define BLSTRICTDOM(l1, l2) (!BLEQUAL(l1, l2) && BLDOMINATES(l1, l2)) + +/* Is the level of l within the range r? */ +#define BLINRANGE(l, r)\ + (BLDOMINATES((l), &((r)->lower_bound)) && \ + BLDOMINATES(&((r)->upper_bound), (l))) + +/* Least Upper Bound level l1 and l2 replacing l1 with the result. */ +#define BLMAXIMUM(l1, l2) \ + _BLMAXIMUM((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) + +#define _BLMAXIMUM(l1, l2)\ + (((l1)->_lclass = (LCLASS(l1) < LCLASS(l2)) ? \ + (l2)->_lclass : (l1)->_lclass), \ + (l1)->_comps.c1 |= (l2)->_comps.c1, \ + (l1)->_comps.c2 |= (l2)->_comps.c2, \ + (l1)->_comps.c3 |= (l2)->_comps.c3, \ + (l1)->_comps.c4 |= (l2)->_comps.c4, \ + (l1)->_comps.c5 |= (l2)->_comps.c5, \ + (l1)->_comps.c6 |= (l2)->_comps.c6, \ + (l1)->_comps.c7 |= (l2)->_comps.c7, \ + (l1)->_comps.c8 |= (l2)->_comps.c8) + +/* Greatest Lower Bound level l1 and l2 replacing l1 with the result. */ +#define BLMINIMUM(l1, l2) \ + _BLMINIMUM((_mac_label_impl_t *)(l1), (_mac_label_impl_t *)(l2)) + +#define _BLMINIMUM(l1, l2)\ + (((l1)->_lclass = (LCLASS(l1) > LCLASS(l2)) ? \ + (l2)->_lclass : (l1)->_lclass), \ + (l1)->_comps.c1 &= (l2)->_comps.c1, \ + (l1)->_comps.c2 &= (l2)->_comps.c2, \ + (l1)->_comps.c3 &= (l2)->_comps.c3, \ + (l1)->_comps.c4 &= (l2)->_comps.c4, \ + (l1)->_comps.c5 &= (l2)->_comps.c5, \ + (l1)->_comps.c6 &= (l2)->_comps.c6, \ + (l1)->_comps.c7 &= (l2)->_comps.c7, \ + (l1)->_comps.c8 &= (l2)->_comps.c8) + +/* Create Manifest Labels */ + +/* Write a System_Low CMW Label into this memory. */ +#define BCLLOW(l) (BSLLOW(BCLTOSL(l)), BILLOW(BCLTOIL(l))) + +/* Write a System_Low Sensitivity Label into this memory. */ +#define BSLLOW(l) _BSLLOW((_bslabel_impl_t *)(l)) + +#define _BSLLOW(l) \ + ((l)->id = SUN_SL_ID, (l)->_c_len = _C_LEN, LCLASS_SET(l, LOW_CLASS), \ + (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ + (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ + EMPTY_SET) + +/* Write a System_High Sensitivity Label into this memory. */ +#define BSLHIGH(l) _BSLHIGH((_bslabel_impl_t *)(l)) + +#define _BSLHIGH(l) \ + ((l)->id = SUN_SL_ID, (l)->_c_len = _C_LEN, LCLASS_SET(l, HIGH_CLASS), \ + (l)->_comps.c1 = (l)->_comps.c2 = (l)->_comps.c3 = (l)->_comps.c4 = \ + (l)->_comps.c5 = (l)->_comps.c6 = (l)->_comps.c7 = (l)->_comps.c8 = \ + UNIVERSAL_SET) + +/* Write a System_Low Information Label into this memory. */ +#define BILLOW(l) _BILLOW((_bilabel_impl_t *)(l)) + +#define _BILLOW(l) \ + ((l)->_iid = SUN_IL_ID, (l)->_i_c_len = _C_LEN, \ + ICLASS_SET(l, LOW_CLASS), \ + (l)->_icomps.c1 = (l)->_icomps.c2 = (l)->_icomps.c3 = \ + (l)->_icomps.c4 = (l)->_icomps.c5 = (l)->_icomps.c6 = \ + (l)->_icomps.c7 = (l)->_icomps.c8 = EMPTY_SET, \ + (l)->_imarks.m1 = (l)->_imarks.m2 = (l)->_imarks.m3 = \ + (l)->_imarks.m4 = (l)->_imarks.m5 = (l)->_imarks.m6 = \ + (l)->_imarks.m7 = (l)->_imarks.m8 = EMPTY_SET) + + +/* Write a System_Low Sensitivity Label into this memory. */ +#define BCLEARLOW(l) _BCLEARLOW((_bclear_impl_t *)(l)) + +#define _BCLEARLOW(c) \ + ((c)->id = SUN_CLR_ID, (c)->_c_len = _C_LEN, \ + LCLASS_SET(c, LOW_CLASS), \ + (c)->_comps.c1 = (c)->_comps.c2 = (c)->_comps.c3 = (c)->_comps.c4 = \ + (c)->_comps.c5 = (c)->_comps.c6 = (c)->_comps.c7 = (c)->_comps.c8 = \ + EMPTY_SET) + +/* Write a System_High Sensitivity Label into this memory. */ +#define BCLEARHIGH(l) _BCLEARHIGH((_bclear_impl_t *)(l)) + +#define _BCLEARHIGH(c) \ + ((c)->id = SUN_CLR_ID, (c)->_c_len = _C_LEN, \ + LCLASS_SET(c, HIGH_CLASS), \ + (c)->_comps.c1 = (c)->_comps.c2 = (c)->_comps.c3 = (c)->_comps.c4 = \ + (c)->_comps.c5 = (c)->_comps.c6 = (c)->_comps.c7 = (c)->_comps.c8 = \ + UNIVERSAL_SET) + +/* Write an undefined Sensitivity Label into this memory. */ +#define BSLUNDEF(l) (((_bslabel_impl_t *)(l))->id = SUN_SL_UN) + +/* Write an undefined Clearance into this memory. */ +#define BCLEARUNDEF(c) (((_bclear_impl_t *)(c))->id = SUN_CLR_UN) + +/* Retrieve the Sensitivity Label portion of a CMW Label */ +#define BCLTOSL(l) ((bslabel_t *)&((_bclabel_impl_t *)(l))->_bcl_sl) + +/* Retrieve the Information Label portion of a CMW Label */ +#define BCLTOIL(l) ((_bilabel_impl_t *)&((_bclabel_impl_t *)(l))->_bcl_il) + +/* Copy the Sensitivity Label portion from a CMW Label */ +#define GETCSL(l1, l2) \ + (*((_bslabel_impl_t *)(l1)) = ((_bclabel_impl_t *)(l2))->_bcl_sl) + +/* Replace the Sensitivity Label portion of a CMW Label */ +#define SETCSL(l1, l2) \ + (((_bclabel_impl_t *)(l1))->_bcl_sl = *((_bslabel_impl_t *)(l2))) + +/* Set type of this memory to the label type 't' */ +#define SETBLTYPE(l, t) (((_bclabel_impl_t *)(l))->_bcl_sl.id = (t)) + +#define GETBLTYPE(l) (((const _bclabel_impl_t *)(l))->_bcl_sl.id) + +#endif /* !_LABEL_MACRO_H */ diff --git a/lib/libspl/include/sys/uio.h b/lib/libspl/include/sys/uio.h index 0aed91357f..8adc923e50 100644 --- a/lib/libspl/include/sys/uio.h +++ b/lib/libspl/include/sys/uio.h @@ -37,14 +37,72 @@ * contributors. */ -#ifndef _LIBSPL_SYS_UIO_H +#ifndef _LIBSPL_SYS_UIO_H #define _LIBSPL_SYS_UIO_H -/* struct iovec is defined in glibc's sys/uio.h */ #include_next -typedef enum uio_rw { UIO_READ, UIO_WRITE } uio_rw_t; +typedef struct iovec iovec_t; -#define UIO_SYSSPACE 1 +typedef enum uio_rw { + UIO_READ = 0, + UIO_WRITE = 1, +} uio_rw_t; + +typedef enum uio_seg { + UIO_USERSPACE = 0, + UIO_SYSSPACE = 1, + UIO_USERISPACE= 2, +} uio_seg_t; + +typedef struct uio { + struct iovec *uio_iov; /* pointer to array of iovecs */ + int uio_iovcnt; /* number of iovecs */ + offset_t uio_loffset; /* file offset */ + uio_seg_t uio_segflg; /* address space (kernel or user) */ + uint16_t uio_fmode; /* file mode flags */ + uint16_t uio_extflg; /* extended flags */ + offset_t uio_limit; /* u-limit (maximum byte offset) */ + ssize_t uio_resid; /* residual count */ +} uio_t; + +typedef enum xuio_type { + UIOTYPE_ASYNCIO, + UIOTYPE_ZEROCOPY, +} xuio_type_t; + +#define UIOA_IOV_MAX 16 + +typedef struct uioa_page_s { /* locked uio_iov state */ + int uioa_pfncnt; /* count of pfn_t(s) in *uioa_ppp */ + void **uioa_ppp; /* page_t or pfn_t arrary */ + caddr_t uioa_base; /* address base */ + size_t uioa_len; /* span length */ +} uioa_page_t; + +typedef struct xuio { + uio_t xu_uio; /* embedded UIO structure */ + + /* Extended uio fields */ + enum xuio_type xu_type; /* uio type */ + union { + struct { + uint32_t xu_a_state; /* state of async i/o */ + ssize_t xu_a_mbytes; /* bytes moved */ + uioa_page_t *xu_a_lcur; /* uioa_locked[] pointer */ + void **xu_a_lppp; /* lcur->uioa_pppp[] pointer */ + void *xu_a_hwst[4]; /* opaque hardware state */ + uioa_page_t xu_a_locked[UIOA_IOV_MAX]; + } xu_aio; + + struct { + int xu_zc_rw; /* read or write buffer */ + void *xu_zc_priv; /* fs specific */ + } xu_zc; + } xu_ext; +} xuio_t; + +#define XUIO_XUZC_PRIV(xuio) xuio->xu_ext.xu_zc.xu_zc_priv +#define XUIO_XUZC_RW(xuio) xuio->xu_ext.xu_zc.xu_zc_rw #endif /* _SYS_UIO_H */ diff --git a/lib/libspl/include/sys/vnode.h b/lib/libspl/include/sys/vnode.h new file mode 100644 index 0000000000..f25e9e9c48 --- /dev/null +++ b/lib/libspl/include/sys/vnode.h @@ -0,0 +1,30 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _LIBSPL_SYS_VNODE_H +#define _LIBSPL_SYS_VNODE_H + +#endif /* _LIBSPL_SYS_VNODE_H */ diff --git a/lib/libspl/include/util/sscanf.h b/lib/libspl/include/util/sscanf.h new file mode 100644 index 0000000000..9d13bf25f1 --- /dev/null +++ b/lib/libspl/include/util/sscanf.h @@ -0,0 +1,30 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2010 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _LIBSPL_UTIL_SSCANF_H +#define _LIBSPL_UTIL_SSCANF_H + +#endif diff --git a/lib/libspl/ltos.c b/lib/libspl/ltos.c new file mode 100644 index 0000000000..3e734e9a71 --- /dev/null +++ b/lib/libspl/ltos.c @@ -0,0 +1,313 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include "label.h" +#include "labeld.h" +#include +#include +#include + + + +static _mac_label_impl_t low; +static _mac_label_impl_t high; +static int inited = 0; + +#define freeit(a, l) free(a) + +/* 0x + Classification + '-' + ll + '-' + Compartments + end of string */ +#define _HEX_SIZE 2+(sizeof (Classification_t)*2)+4+\ + (sizeof (Compartments_t)*2)+1 + +/* 0x + Classification + '-' + ll + '-' + end of string */ +#define _MIN_HEX (2 + (sizeof (Classification_t)*2) + 4 + 1) + +static char digits[] = "0123456789abcdef"; + +#define HEX(h, i, l, s) \ + for (; i < s; /* */) {\ + h[i++] = digits[(unsigned int)(*l >> 4)];\ + h[i++] = digits[(unsigned int)(*l++&0xF)]; } + +static int +__hex(char **s, const m_label_t *l) +{ + char *hex; + int i = 0; + uchar_t *hl; + int hex_len; + uchar_t *len; + + hl = (uchar_t *)&(((_mac_label_impl_t *)l)->_c_len); + len = hl; + + if (*len == 0) { + /* old binary label */ + hex_len = _HEX_SIZE; + } else { + hex_len = _MIN_HEX + (*len * sizeof (uint32_t) * 2); + } + + if ((hex = malloc(hex_len)) == NULL) { + return (-1); + } + + /* header */ + + hex[i++] = '0'; + hex[i++] = 'x'; + + /* classification */ + + hl++; /* start at classification */ + HEX(hex, i, hl, 6); + + /* Add compartments length */ + hex[i++] = '-'; + HEX(hex, i, len, 9); + hex[i++] = '-'; + + /* compartments */ + HEX(hex, i, hl, hex_len-1); + hex[i] = '\0'; + + /* truncate trailing zeros */ + + while (hex[i-1] == '0' && hex[i-2] == '0') { + i -= 2; + } + hex[i] = '\0'; + + if ((*s = strdup(hex)) == NULL) { + freeit(hex, hex_len); + return (-1); + } + + freeit(hex, hex_len); + return (0); + +} + +int +l_to_str_internal(const m_label_t *l, char **s) +{ + if (inited == 0) { + inited = 1; + _BSLLOW(&low); + _BSLHIGH(&high); + } + + if (!(_MTYPE(l, SUN_MAC_ID) || _MTYPE(l, SUN_UCLR_ID))) { + errno = EINVAL; + *s = NULL; + return (-1); + } + if (_MEQUAL(&low, (_mac_label_impl_t *)l)) { + if ((*s = strdup(ADMIN_LOW)) == NULL) { + return (-1); + } + return (0); + } + if (_MEQUAL(&high, (_mac_label_impl_t *)l)) { + if ((*s = strdup(ADMIN_HIGH)) == NULL) { + return (-1); + } + return (0); + } + + return (__hex(s, l)); +} + +/* + * label_to_str -- convert a label to the requested type of string. + * + * Entry l = label to convert; + * t = type of conversion; + * f = flags for conversion type; + * + * Exit *s = allocated converted string; + * Caller must call free() to free. + * + * Returns 0, success. + * -1, error, errno set; *s = NULL. + * + * Calls labeld + */ + +int +label_to_str(const m_label_t *l, char **s, const m_label_str_t t, uint_t f) +{ + labeld_data_t call; + labeld_data_t *callp = &call; + size_t bufsize = sizeof (labeld_data_t); + size_t datasize; + int err; + int string_start = 0; + + if (inited == 0) { + inited = 1; + _BSLLOW(&low); + _BSLHIGH(&high); + } + +#define lscall callp->param.acall.cargs.ls_arg +#define lsret callp->param.aret.rvals.ls_ret + switch (t) { + case M_LABEL: + call.callop = LTOS; + lscall.label = *l; + lscall.flags = f; + datasize = CALL_SIZE(ls_call_t, 0); + if ((err = __call_labeld(&callp, &bufsize, &datasize)) == + SUCCESS) { + if (callp->reterr != 0) { + errno = EINVAL; + *s = NULL; + return (-1); + } + *s = strdup(lsret.buf); + if (callp != &call) { + /* release returned buffer */ + (void) munmap((void *)callp, bufsize); + } + if (*s == NULL) { + return (-1); + } + return (0); + } + switch (err) { + case NOSERVER: + /* server not present */ + /* special case admin_low and admin_high */ + + if (_MEQUAL(&low, (_mac_label_impl_t *)l)) { + if ((*s = strdup(ADMIN_LOW)) == NULL) { + return (-1); + } + return (0); + } else if (_MEQUAL(&high, (_mac_label_impl_t *)l)) { + if ((*s = strdup(ADMIN_HIGH)) == NULL) { + return (-1); + } + return (0); + } + errno = ENOTSUP; + break; + default: + errno = EINVAL; + break; + } + *s = NULL; + return (-1); +#undef lscall +#undef lsret + + case M_INTERNAL: { + return (l_to_str_internal(l, s)); + } + +#define ccall callp->param.acall.cargs.color_arg +#define cret callp->param.aret.rvals.color_ret + case M_COLOR: + datasize = CALL_SIZE(color_call_t, 0); + call.callop = BLTOCOLOR; + ccall.label = *l; + + if (__call_labeld(&callp, &bufsize, &datasize) == SUCCESS) { + if (callp->reterr != 0) { + errno = EINVAL; + *s = NULL; + return (-1); + } + *s = strdup(cret.color); + if (callp != &call) { + /* release returned buffer */ + (void) munmap((void *)callp, bufsize); + } + if (*s == NULL) { + return (-1); + } + return (0); + } else { + errno = ENOTSUP; + *s = NULL; + return (-1); + } +#undef ccall +#undef cret + +#define prcall callp->param.acall.cargs.pr_arg +#define prret callp->param.aret.rvals.pr_ret + case PRINTER_TOP_BOTTOM: + call.callop = PR_TOP; + break; + case PRINTER_LABEL: + call.callop = PR_LABEL; + break; + case PRINTER_CAVEATS: + call.callop = PR_CAVEATS; + string_start = 1; /* compensate for leading space */ + break; + case PRINTER_CHANNELS: + call.callop = PR_CHANNELS; + string_start = 1; /* compensate for leading space */ + break; + default: + errno = EINVAL; + *s = NULL; + return (-1); + } + /* do the common printer calls */ + datasize = CALL_SIZE(pr_call_t, 0); + prcall.label = *l; + prcall.flags = f; + if (__call_labeld(&callp, &bufsize, &datasize) == SUCCESS) { + if (callp->reterr != 0) { + errno = EINVAL; + *s = NULL; + return (-1); + } + *s = strdup(&prret.buf[string_start]); + if (callp != &call) { + /* release returned buffer */ + (void) munmap((void *)callp, bufsize); + } + if (*s == NULL) { + return (-1); + } + return (0); + } else { + errno = ENOTSUP; + *s = NULL; + return (-1); + } +#undef prcall +#undef prret +} diff --git a/lib/libspl/stol.c b/lib/libspl/stol.c new file mode 100644 index 0000000000..4f466f7deb --- /dev/null +++ b/lib/libspl/stol.c @@ -0,0 +1,432 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define IS_LOW(s) \ + ((strncasecmp(s, ADMIN_LOW, (sizeof (ADMIN_LOW) - 1)) == 0) && \ + (s[sizeof (ADMIN_LOW) - 1] == '\0')) +#define IS_HIGH(s) \ + ((strncasecmp(s, ADMIN_HIGH, (sizeof (ADMIN_HIGH) - 1)) == 0) && \ + (s[sizeof (ADMIN_HIGH) - 1] == '\0')) +#define IS_HEX(f, s) \ + (((((f) == L_NO_CORRECTION)) || ((f) == L_DEFAULT)) && \ + (((s)[0] == '0') && (((s)[1] == 'x') || ((s)[1] == 'X')))) + +static boolean_t +unhex(const char **h, uchar_t *l, int len) +{ + const char *hx = *h; + char ch; + uchar_t byte; + + for (; len--; ) { + ch = *hx++; + if (!isxdigit(ch)) + return (B_FALSE); + if (isdigit(ch)) + byte = ch - '0'; + else + byte = ch - (isupper(ch) ? 'A' - 10 : 'a' - 10); + byte <<= 4; + ch = *hx++; + if (!isxdigit(ch)) + return (B_FALSE); + if (isdigit(ch)) + byte |= ch - '0'; + else + byte |= ch - (isupper(ch) ? 'A' - 10 : 'a' - 10); + *l++ = byte; + } + *h = hx; + return (B_TRUE); +} + +/* + * Formats accepted: + * 0x + 4 class + 64 comps + end of string + * 0x + 4 class + '-' + ll + '-' + comps + end of string + * ll = number of words to fill out the entire comps field + * presumes trailing zero for comps + * + * So in the case of 256 comps (i.e., 8 compartment words): + * 0x0006-08-7ff3f + * 0x + Classification + Compartments + end of string + * 0[xX]hhh... + */ + +static int +htol(const char *s, m_label_t *l) +{ + const char *h = &s[2]; /* skip 0[xX] */ + uchar_t *lp = (uchar_t *)&(((_mac_label_impl_t *)l)->_lclass); + size_t len = sizeof (_mac_label_impl_t) - 4; + int bytes; + + /* unpack 16 bit signed classification */ + if (!unhex(&h, lp, 2) || (LCLASS(l) < 0)) { + return (-1); + } + lp = (uchar_t *)&(((_mac_label_impl_t *)l)->_comps); + if (h[0] == '-' && h[3] == '-') { + uchar_t size; + + /* length specified of internal text label */ + h++; /* skip '-' */ + if (!unhex(&h, &size, 1)) { + return (-1); + } + /* convert size from words to bytes */ + if ((size * sizeof (uint32_t)) > len) { + /* + * internal label greater than will fit in current + * binary. + */ + return (-1); + } + bzero(lp, len); + h++; /* skip '-' */ + } + bytes = strlen(h)/2; + if ((bytes > len) || + (bytes*2 != strlen(h)) || + !unhex(&h, lp, bytes)) { + return (-1); + } + return (0); +} + +/* + * hexstr_to_label -- parse a string representing a hex label into a + * binary label. Only admin high/low and hex are + * accepted. + * + * Returns 0, success. + * -1, failure + */ +int +hexstr_to_label(const char *s, m_label_t *l) +{ + uint_t f = L_DEFAULT; + + /* translate hex, admin_low and admin_high */ + if (IS_LOW(s)) { + _LOW_LABEL(l, SUN_MAC_ID); + return (0); + } else if (IS_HIGH(s)) { + _HIGH_LABEL(l, SUN_MAC_ID); + return (0); + } else if (IS_HEX(f, s)) { + _LOW_LABEL(l, SUN_MAC_ID); + if (htol(s, l) == 0) + return (0); + } + + return (-1); +} + +static int +convert_id(m_label_type_t t) +{ + switch (t) { + case MAC_LABEL: + return (SUN_MAC_ID); + case USER_CLEAR: + return (SUN_UCLR_ID); + default: + return (-1); + } +} + +/* + * str_to_label -- parse a string into the requested label type. + * + * Entry s = string to parse. + * l = label to create or modify. + * t = label type (MAC_LABEL, USER_CLEAR). + * f = flags + * L_DEFAULT, + * L_MODIFY_EXISTING, use the existing label as a basis for + * the parse string. + * L_NO_CORRECTION, s must be correct and full by the + * label_encoding rules. + * L_CHECK_AR, for non-hex s, MAC_LABEL, check the l_e AR + * + * Exit l = parsed label value. + * e = index into string of error. + * = M_BAD_STRING (-3 L_BAD_LABEL) or could be zero, + * indicates entire string, + * e = M_BAD_LABEL (-2 L_BAD_CLASSIFICATION), problems with l + * e = M_OUTSIDE_AR (-4 unrelated to L_BAD_* return values) + * + * Returns 0, success. + * -1, failure + * errno = ENOTSUP, the underlying label mechanism + * does not support label parsing. + * ENOMEM, unable to allocate memory for l. + * EINVAL, invalid argument, l != NULL or + * invalid label type for the underlying + * label mechanism. + */ +#define _M_GOOD_LABEL -1 /* gfi L_GOOD_LABEL */ +int +str_to_label(const char *str, m_label_t **l, const m_label_type_t t, uint_t f, + int *e) +{ + char *s = strdup(str); + char *st = s; + char *p; + labeld_data_t call; + labeld_data_t *callp = &call; + size_t bufsize = sizeof (labeld_data_t); + size_t datasize; + int err = M_BAD_LABEL; + int id = convert_id(t); + boolean_t new = B_FALSE; + uint_t lf = (f & ~L_CHECK_AR); /* because L_DEFAULT == 0 */ + + if (st == NULL) { + errno = ENOMEM; + return (-1); + } + if (*l == NULL) { + if ((*l = m_label_alloc(t)) == NULL) { + free(st); + return (-1); + } + if (id == -1) { + goto badlabel; + } + _LOW_LABEL(*l, id); + new = B_TRUE; + } else if (_MTYPE(*l, SUN_INVALID_ID) && + ((lf == L_NO_CORRECTION) || (lf == L_DEFAULT))) { + _LOW_LABEL(*l, id); + new = B_TRUE; + } else if (!(_MTYPE(*l, SUN_MAC_ID) || _MTYPE(*l, SUN_CLR_ID))) { + goto badlabel; + } + + if (new == B_FALSE && id == -1) { + goto badlabel; + } + + /* get to the beginning of the string to parse */ + while (isspace(*s)) { + s++; + } + + /* accept a leading '[' and trailing ']' for old times sake */ + if (*s == '[') { + *s = ' '; + s++; + while (isspace(*s)) { + s++; + } + } + p = s; + while (*p != '\0' && *p != ']') { + p++; + } + + /* strip trailing spaces */ + while (p != s && isspace(*(p-1))) { + --p; + } + *p = '\0'; /* end of string */ + + /* translate hex, admin_low and admin_high */ + id = _MGETTYPE(*l); + if (IS_LOW(s)) { + _LOW_LABEL(*l, id); + goto goodlabel; + } else if (IS_HIGH(s)) { + _HIGH_LABEL(*l, id); + goto goodlabel; + } else if (IS_HEX(lf, s)) { + if (htol(s, *l) != 0) { + /* whole string in error */ + err = 0; + goto badlabel; + } + goto goodlabel; + } +#define slcall callp->param.acall.cargs.sl_arg +#define slret callp->param.aret.rvals.sl_ret + /* now try label server */ + + datasize = CALL_SIZE_STR(sl_call_t, strlen(st) + 1); + if (datasize > bufsize) { + if ((callp = malloc(datasize)) == NULL) { + free(st); + return (-1); + } + bufsize = datasize; + } + callp->callop = STOL; + slcall.label = **l; + slcall.flags = f; + if (new) + slcall.flags |= L_NEW_LABEL; + (void) strcpy(slcall.string, st); + /* + * callp->reterr = L_GOOD_LABEL (-1) == OK; + * L_BAD_CLASSIFICATION (-2) == bad input + * classification: class + * L_BAD_LABEL (-3) == either string or input label bad + * M_OUTSIDE_AR (-4) == resultant MAC_LABEL is out + * l_e accreditation range + * O'E == offset in string 0 == entire string. + */ + if (__call_labeld(&callp, &bufsize, &datasize) == SUCCESS) { + + err = callp->reterr; + if (callp != &call) { + /* free allocated buffer */ + free(callp); + } + switch (err) { + case _M_GOOD_LABEL: /* L_GOOD_LABEL */ + **l = slret.label; + goto goodlabel; + case M_BAD_LABEL: /* L_BAD_CLASSIFICATION */ + case M_BAD_STRING: /* L_BAD_LABEL */ + default: + goto badlabel; + } + } + switch (callp->reterr) { + case NOSERVER: + errno = ENOTSUP; + break; + default: + errno = EINVAL; + break; + } + free(st); + return (-1); + +badlabel: + errno = EINVAL; + free(st); + if (e != NULL) + *e = err; + return (-1); + +goodlabel: + free(st); + return (0); +} +#undef slcall +#undef slret + +/* + * m_label_alloc -- allocate a label structure + * + * Entry t = label type (MAC_LABEL, USER_CLEAR). + * + * Exit If error, NULL, errno set to ENOMEM + * Otherwise, pointer to m_label_t memory + */ + +/* ARGUSED */ +m_label_t * +m_label_alloc(const m_label_type_t t) +{ + m_label_t *l; + + switch (t) { + case MAC_LABEL: + case USER_CLEAR: + if ((l = malloc(sizeof (_mac_label_impl_t))) == NULL) { + return (NULL); + } + _MSETTYPE(l, SUN_INVALID_ID); + break; + default: + errno = EINVAL; + return (NULL); + } + return (l); +} + +/* + * m_label_dup -- make a duplicate copy of the given label. + * + * Entry l = label to duplicate. + * + * Exit d = duplicate copy of l. + * + * Returns 0, success + * -1, if error. + * errno = ENOTSUP, the underlying label mechanism + * does not support label duplication. + * ENOMEM, unable to allocate memory for d. + * EINVAL, invalid argument, l == NULL or + * invalid label type for the underlying + * label mechanism. + */ + +int +m_label_dup(m_label_t **d, const m_label_t *l) +{ + if (d == NULL || *d != NULL) { + errno = EINVAL; + return (-1); + } + if ((*d = malloc(sizeof (_mac_label_impl_t))) == NULL) { + errno = ENOMEM; + return (-1); + } + + (void) memcpy(*d, l, sizeof (_mac_label_impl_t)); + return (0); +} + +/* + * m_label_free -- free label structure + * + * Entry l = label to free. + * + * Exit memory freed. + * + */ + +void +m_label_free(m_label_t *l) +{ + if (l) + free(l); +} diff --git a/lib/libspl/timestamp.c b/lib/libspl/timestamp.c new file mode 100644 index 0000000000..a4f4cf4e47 --- /dev/null +++ b/lib/libspl/timestamp.c @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2009 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include +#include +#include +#include "statcommon.h" + +/* + * Print timestamp as decimal reprentation of time_t value (-T u was specified) + * or in date(1) format (-T d was specified). + */ +void +print_timestamp(uint_t timestamp_fmt) +{ + time_t t = time(NULL); + static char *fmt = NULL; + + /* We only need to retrieve this once per invocation */ + if (fmt == NULL) + fmt = nl_langinfo(_DATE_FMT); + + if (timestamp_fmt == UDATE) { + (void) printf("%ld\n", t); + } else if (timestamp_fmt == DDATE) { + char dstr[64]; + int len; + + len = strftime(dstr, sizeof (dstr), fmt, localtime(&t)); + if (len > 0) + (void) printf("%s\n", dstr); + } +} diff --git a/lib/libzfs/Makefile.am b/lib/libzfs/Makefile.am index 7ffd81cf28..24ade074ee 100644 --- a/lib/libzfs/Makefile.am +++ b/lib/libzfs/Makefile.am @@ -20,6 +20,7 @@ libzfs_la_SOURCES = \ ${top_srcdir}/lib/libzfs/libzfs_changelist.c \ ${top_srcdir}/lib/libzfs/libzfs_config.c \ ${top_srcdir}/lib/libzfs/libzfs_dataset.c \ + ${top_srcdir}/lib/libzfs/libzfs_fru.c \ ${top_srcdir}/lib/libzfs/libzfs_graph.c \ ${top_srcdir}/lib/libzfs/libzfs_import.c \ ${top_srcdir}/lib/libzfs/libzfs_mount.c \ diff --git a/lib/libzfs/libzfs_config.c b/lib/libzfs/libzfs_config.c index 9b875ee1f3..f1ddac98ab 100644 --- a/lib/libzfs/libzfs_config.c +++ b/lib/libzfs/libzfs_config.c @@ -101,7 +101,7 @@ namespace_reload(libzfs_handle_t *hdl) nvlist_t *config; config_node_t *cn; nvpair_t *elem; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; void *cookie; if (hdl->libzfs_ns_gen == 0) { @@ -226,7 +226,7 @@ zpool_get_config(zpool_handle_t *zhp, nvlist_t **oldconfig) int zpool_refresh_stats(zpool_handle_t *zhp, boolean_t *missing) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int error; nvlist_t *config; libzfs_handle_t *hdl = zhp->zpool_hdl; diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index bd0c685905..4e2dfbce82 100644 --- a/lib/libzfs/libzfs_dataset.c +++ b/lib/libzfs/libzfs_dataset.c @@ -308,7 +308,7 @@ get_recvd_props_ioctl(zfs_handle_t *zhp) { libzfs_handle_t *hdl = zhp->zfs_hdl; nvlist_t *recvdprops; - zfs_cmd_t zc = { 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int err; if (zcmd_alloc_dst_nvlist(hdl, &zc, 0) != 0) @@ -371,7 +371,7 @@ static int get_stats(zfs_handle_t *zhp) { int rc = 0; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; if (zcmd_alloc_dst_nvlist(zhp->zfs_hdl, &zc, 0) != 0) return (-1); @@ -431,7 +431,7 @@ make_dataset_handle_common(zfs_handle_t *zhp, zfs_cmd_t *zc) zfs_handle_t * make_dataset_handle(libzfs_handle_t *hdl, const char *path) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; zfs_handle_t *zhp = calloc(sizeof (zfs_handle_t), 1); @@ -1308,7 +1308,7 @@ zfs_setprop_error(libzfs_handle_t *hdl, zfs_prop_t prop, int err, int zfs_prop_set(zfs_handle_t *zhp, const char *propname, const char *propval) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int ret = -1; prop_changelist_t *cl = NULL; char errbuf[1024]; @@ -1398,7 +1398,7 @@ error: int zfs_prop_inherit(zfs_handle_t *zhp, const char *propname, boolean_t received) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int ret; prop_changelist_t *cl; libzfs_handle_t *hdl = zhp->zfs_hdl; @@ -1573,7 +1573,7 @@ static int get_numeric_property(zfs_handle_t *zhp, zfs_prop_t prop, zprop_source_t *src, char **source, uint64_t *val) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; nvlist_t *zplprops = NULL; struct mnttab mnt; char *mntopt_on = NULL; @@ -2307,7 +2307,7 @@ zfs_prop_get_userquota_common(zfs_handle_t *zhp, const char *propname, uint64_t *propvalue, zfs_userquota_prop_t *typep) { int err; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; (void) strncpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); @@ -2426,7 +2426,7 @@ top: int zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; zfs_handle_t *nzhp; int ret; @@ -2462,7 +2462,7 @@ zfs_iter_filesystems(zfs_handle_t *zhp, zfs_iter_f func, void *data) int zfs_iter_snapshots(zfs_handle_t *zhp, zfs_iter_f func, void *data) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; zfs_handle_t *nzhp; int ret; @@ -2553,7 +2553,7 @@ static int check_parents(libzfs_handle_t *hdl, const char *path, uint64_t *zoned, boolean_t accept_ancestor, int *prefixlen) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char parent[ZFS_MAXNAMELEN]; char *slash; zfs_handle_t *zhp; @@ -2763,7 +2763,7 @@ int zfs_create(libzfs_handle_t *hdl, const char *path, zfs_type_t type, nvlist_t *props) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int ret; uint64_t size = 0; uint64_t blocksize = zfs_prop_default_numeric(ZFS_PROP_VOLBLOCKSIZE); @@ -2914,7 +2914,7 @@ zfs_create(libzfs_handle_t *hdl, const char *path, zfs_type_t type, int zfs_destroy(zfs_handle_t *zhp, boolean_t defer) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); @@ -2975,7 +2975,7 @@ zfs_check_snap_cb(zfs_handle_t *zhp, void *arg) int zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int ret; struct destroydata dd = { 0 }; @@ -3020,7 +3020,7 @@ zfs_destroy_snaps(zfs_handle_t *zhp, char *snapname, boolean_t defer) int zfs_clone(zfs_handle_t *zhp, const char *target, nvlist_t *props) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char parent[ZFS_MAXNAMELEN]; int ret; char errbuf[1024]; @@ -3110,7 +3110,7 @@ int zfs_promote(zfs_handle_t *zhp) { libzfs_handle_t *hdl = zhp->zfs_hdl; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char parent[MAXPATHLEN]; int ret; char errbuf[1024]; @@ -3164,7 +3164,7 @@ zfs_snapshot(libzfs_handle_t *hdl, const char *path, boolean_t recursive, const char *delim; char parent[ZFS_MAXNAMELEN]; zfs_handle_t *zhp; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int ret; char errbuf[1024]; @@ -3296,7 +3296,7 @@ zfs_rollback(zfs_handle_t *zhp, zfs_handle_t *snap, boolean_t force) { rollback_data_t cb = { 0 }; int err; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; boolean_t restore_resv = 0; uint64_t old_volsize = 0, new_volsize; zfs_prop_t resv_prop = { 0 }; @@ -3412,7 +3412,7 @@ int zfs_rename(zfs_handle_t *zhp, const char *target, boolean_t recursive) { int ret; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char *delim; prop_changelist_t *cl = NULL; zfs_handle_t *zhrp = NULL; @@ -3720,7 +3720,7 @@ zfs_deleg_share_nfs(libzfs_handle_t *hdl, char *dataset, char *path, char *resource, void *export, void *sharetab, int sharemax, zfs_share_op_t operation) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int error; (void) strlcpy(zc.zc_name, dataset, sizeof (zc.zc_name)); @@ -3771,7 +3771,7 @@ static int zfs_smb_acl_mgmt(libzfs_handle_t *hdl, char *dataset, char *path, zfs_smb_acl_op_t cmd, char *resource1, char *resource2) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; nvlist_t *nvlist = NULL; int error; @@ -3853,7 +3853,7 @@ int zfs_userspace(zfs_handle_t *zhp, zfs_userquota_prop_t type, zfs_userspace_cb_t func, void *arg) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int error; zfs_useracct_t buf[100]; @@ -3889,7 +3889,7 @@ int zfs_hold(zfs_handle_t *zhp, const char *snapname, const char *tag, boolean_t recursive, boolean_t temphold, boolean_t enoent_ok) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; libzfs_handle_t *hdl = zhp->zfs_hdl; (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); @@ -4038,7 +4038,7 @@ int zfs_release(zfs_handle_t *zhp, const char *snapname, const char *tag, boolean_t recursive) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; libzfs_handle_t *hdl = zhp->zfs_hdl; (void) strlcpy(zc.zc_name, zhp->zfs_name, sizeof (zc.zc_name)); diff --git a/lib/libzfs/libzfs_graph.c b/lib/libzfs/libzfs_graph.c index 48e722edb0..0e538e3ded 100644 --- a/lib/libzfs/libzfs_graph.c +++ b/lib/libzfs/libzfs_graph.c @@ -379,7 +379,7 @@ zfs_graph_add(libzfs_handle_t *hdl, zfs_graph_t *zgp, const char *source, static int iterate_children(libzfs_handle_t *hdl, zfs_graph_t *zgp, const char *dataset) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; zfs_vertex_t *zvp; /* @@ -473,7 +473,7 @@ iterate_children(libzfs_handle_t *hdl, zfs_graph_t *zgp, const char *dataset) static boolean_t external_dependents(libzfs_handle_t *hdl, zfs_graph_t *zgp, const char *dataset) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; /* * Check whether this dataset is a clone or has clones since diff --git a/lib/libzfs/libzfs_import.c b/lib/libzfs/libzfs_import.c index 35d961ae09..19cdbee255 100644 --- a/lib/libzfs/libzfs_import.c +++ b/lib/libzfs/libzfs_import.c @@ -374,7 +374,7 @@ static nvlist_t * refresh_config(libzfs_handle_t *hdl, nvlist_t *config) { nvlist_t *nvl; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int err; if (zcmd_write_conf_nvlist(hdl, &zc, config) != 0) diff --git a/lib/libzfs/libzfs_pool.c b/lib/libzfs/libzfs_pool.c index 42cb34a80b..011e820cd0 100644 --- a/lib/libzfs/libzfs_pool.c +++ b/lib/libzfs/libzfs_pool.c @@ -61,7 +61,7 @@ static int read_efi_label(nvlist_t *config, diskaddr_t *sb); static int zpool_get_all_props(zpool_handle_t *zhp) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; libzfs_handle_t *hdl = zhp->zpool_hdl; (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); @@ -558,7 +558,7 @@ error: int zpool_set_prop(zpool_handle_t *zhp, const char *propname, const char *propval) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int ret = -1; char errbuf[1024]; nvlist_t *nvl = NULL; @@ -875,7 +875,7 @@ int zpool_create(libzfs_handle_t *hdl, const char *pool, nvlist_t *nvroot, nvlist_t *props, nvlist_t *fsprops) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; nvlist_t *zc_fsprops = NULL; nvlist_t *zc_props = NULL; char msg[1024]; @@ -1007,7 +1007,7 @@ create_failed: int zpool_destroy(zpool_handle_t *zhp) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; zfs_handle_t *zfp = NULL; libzfs_handle_t *hdl = zhp->zpool_hdl; char msg[1024]; @@ -1051,7 +1051,7 @@ zpool_destroy(zpool_handle_t *zhp) int zpool_add(zpool_handle_t *zhp, nvlist_t *nvroot) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int ret; libzfs_handle_t *hdl = zhp->zpool_hdl; char msg[1024]; @@ -1175,7 +1175,7 @@ zpool_add(zpool_handle_t *zhp, nvlist_t *nvroot) int zpool_export_common(zpool_handle_t *zhp, boolean_t force, boolean_t hardforce) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; (void) snprintf(msg, sizeof (msg), dgettext(TEXT_DOMAIN, @@ -1388,7 +1388,7 @@ int zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname, nvlist_t *props, boolean_t importfaulted) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; zpool_rewind_policy_t policy; nvlist_t *nvi = NULL; char *thename; @@ -1532,7 +1532,7 @@ zpool_import_props(libzfs_handle_t *hdl, nvlist_t *config, const char *newname, int zpool_scan(zpool_handle_t *zhp, pool_scan_func_t func) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; libzfs_handle_t *hdl = zhp->zpool_hdl; @@ -2074,7 +2074,7 @@ int zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags, vdev_state_t *newstate) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; nvlist_t *tgt; boolean_t avail_spare, l2cache, islog; @@ -2145,7 +2145,7 @@ zpool_vdev_online(zpool_handle_t *zhp, const char *path, int flags, int zpool_vdev_offline(zpool_handle_t *zhp, const char *path, boolean_t istmp) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; nvlist_t *tgt; boolean_t avail_spare, l2cache; @@ -2195,7 +2195,7 @@ zpool_vdev_offline(zpool_handle_t *zhp, const char *path, boolean_t istmp) int zpool_vdev_fault(zpool_handle_t *zhp, uint64_t guid, vdev_aux_t aux) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; libzfs_handle_t *hdl = zhp->zpool_hdl; @@ -2230,7 +2230,7 @@ zpool_vdev_fault(zpool_handle_t *zhp, uint64_t guid, vdev_aux_t aux) int zpool_vdev_degrade(zpool_handle_t *zhp, uint64_t guid, vdev_aux_t aux) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; libzfs_handle_t *hdl = zhp->zpool_hdl; @@ -2284,7 +2284,7 @@ int zpool_vdev_attach(zpool_handle_t *zhp, const char *old_disk, const char *new_disk, nvlist_t *nvroot, int replacing) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; int ret; nvlist_t *tgt; @@ -2475,7 +2475,7 @@ zpool_vdev_attach(zpool_handle_t *zhp, int zpool_vdev_detach(zpool_handle_t *zhp, const char *path) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; nvlist_t *tgt; boolean_t avail_spare, l2cache; @@ -2573,7 +2573,7 @@ int zpool_vdev_split(zpool_handle_t *zhp, char *newname, nvlist_t **newroot, nvlist_t *props, splitflags_t flags) { - zfs_cmd_t zc = { 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; nvlist_t *tree, *config, **child, **newchild, *newconfig = NULL; nvlist_t **varray = NULL, *zc_props = NULL; @@ -2783,7 +2783,7 @@ out: int zpool_vdev_remove(zpool_handle_t *zhp, const char *path) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; nvlist_t *tgt; boolean_t avail_spare, l2cache, islog; @@ -2828,7 +2828,7 @@ zpool_vdev_remove(zpool_handle_t *zhp, const char *path) int zpool_clear(zpool_handle_t *zhp, const char *path, nvlist_t *rewindnvl) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; nvlist_t *tgt; zpool_rewind_policy_t policy; @@ -2896,7 +2896,7 @@ zpool_clear(zpool_handle_t *zhp, const char *path, nvlist_t *rewindnvl) int zpool_vdev_clear(zpool_handle_t *zhp, uint64_t guid) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; char msg[1024]; libzfs_handle_t *hdl = zhp->zpool_hdl; @@ -2980,7 +2980,7 @@ path_to_devid(const char *path) static void set_path(zpool_handle_t *zhp, nvlist_t *nv, const char *path) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; (void) strncpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); (void) strncpy(zc.zc_value, path, sizeof (zc.zc_value)); @@ -3141,7 +3141,7 @@ zbookmark_compare(const void *a, const void *b) int zpool_get_errlog(zpool_handle_t *zhp, nvlist_t **nverrlistp) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; uint64_t count; zbookmark_t *zb = NULL; int i; @@ -3237,7 +3237,7 @@ nomem: int zpool_upgrade(zpool_handle_t *zhp, uint64_t new_version) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; libzfs_handle_t *hdl = zhp->zpool_hdl; (void) strcpy(zc.zc_name, zhp->zpool_name); @@ -3299,7 +3299,7 @@ zpool_stage_history(libzfs_handle_t *hdl, const char *history_str) static int get_history(zpool_handle_t *zhp, char *buf, uint64_t *off, uint64_t *len) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; libzfs_handle_t *hdl = zhp->zpool_hdl; (void) strlcpy(zc.zc_name, zhp->zpool_name, sizeof (zc.zc_name)); @@ -3512,7 +3512,7 @@ void zpool_obj_to_path(zpool_handle_t *zhp, uint64_t dsobj, uint64_t obj, char *pathname, size_t len) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; boolean_t mounted = B_FALSE; char *mntpnt = NULL; char dsname[MAXNAMELEN]; diff --git a/lib/libzfs/libzfs_sendrecv.c b/lib/libzfs/libzfs_sendrecv.c index 55258ee6ae..988a85b2da 100644 --- a/lib/libzfs/libzfs_sendrecv.c +++ b/lib/libzfs/libzfs_sendrecv.c @@ -58,7 +58,7 @@ extern void zfs_setprop_error(libzfs_handle_t *, zfs_prop_t, int, char *); static int zfs_receive_impl(libzfs_handle_t *, const char *, recvflags_t, int, const char *, nvlist_t *, avl_tree_t *, char **); -static const zio_cksum_t zero_cksum = { 0 }; +static const zio_cksum_t zero_cksum = { { 0 } }; typedef struct dedup_arg { int inputfd; @@ -868,7 +868,7 @@ static int dump_ioctl(zfs_handle_t *zhp, const char *fromsnap, boolean_t fromorigin, int outfd, boolean_t enoent_ok, boolean_t *got_enoent, nvlist_t *debugnv) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; libzfs_handle_t *hdl = zhp->zfs_hdl; nvlist_t *thisdbg; @@ -1040,7 +1040,7 @@ dump_filesystem(zfs_handle_t *zhp, void *arg) int rv = 0; send_dump_data_t *sdd = arg; boolean_t missingfrom = B_FALSE; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; (void) snprintf(zc.zc_name, sizeof (zc.zc_name), "%s@%s", zhp->zfs_name, sdd->tosnap); @@ -1486,7 +1486,7 @@ recv_rename(libzfs_handle_t *hdl, const char *name, const char *tryname, int baselen, char *newname, recvflags_t flags) { static int seq; - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int err; prop_changelist_t *clp; zfs_handle_t *zhp; @@ -1559,7 +1559,7 @@ static int recv_destroy(libzfs_handle_t *hdl, const char *name, int baselen, char *newname, recvflags_t flags) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; int err = 0; prop_changelist_t *clp; zfs_handle_t *zhp; @@ -1787,7 +1787,7 @@ again: stream_originguid, originguid)) { case 1: { /* promote it! */ - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; nvlist_t *origin_nvfs; char *origin_fsname; @@ -1859,7 +1859,7 @@ again: if (0 == nvlist_lookup_nvlist(stream_nvfs, "snapprops", &props) && 0 == nvlist_lookup_nvlist(props, stream_snapname, &props)) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; zc.zc_cookie = B_TRUE; /* received */ (void) snprintf(zc.zc_name, sizeof (zc.zc_name), @@ -2288,7 +2288,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, dmu_replay_record_t *drr_noswap, const char *sendfs, nvlist_t *stream_nv, avl_tree_t *stream_avl, char **top_zfs) { - zfs_cmd_t zc = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc = { "\0", "\0", "\0", "\0", 0 }; time_t begin_time; int ioctl_err, ioctl_errno, err; char *cp; @@ -2654,7 +2654,7 @@ zfs_receive_one(libzfs_handle_t *hdl, int infd, const char *tosnap, zcmd_free_nvlists(&zc); if (err == 0 && snapprops_nvlist) { - zfs_cmd_t zc2 = { "\0", "\0", "\0", 0 }; + zfs_cmd_t zc2 = { "\0", "\0", "\0", "\0", 0 }; (void) strcpy(zc2.zc_name, zc.zc_value); zc2.zc_cookie = B_TRUE; /* received */ diff --git a/lib/libzpool/Makefile.am b/lib/libzpool/Makefile.am index 039d7f60b8..e28d7304b4 100644 --- a/lib/libzpool/Makefile.am +++ b/lib/libzpool/Makefile.am @@ -19,6 +19,7 @@ libzpool_la_SOURCES = \ ${top_srcdir}/lib/libzpool/util.c \ ${top_srcdir}/module/zcommon/zfs_comutil.c \ ${top_srcdir}/module/zcommon/zfs_deleg.c \ + ${top_srcdir}/module/zcommon/zfs_fletcher.c \ ${top_srcdir}/module/zcommon/zfs_namecheck.c \ ${top_srcdir}/module/zcommon/zfs_prop.c \ ${top_srcdir}/module/zcommon/zpool_prop.c \ @@ -27,11 +28,15 @@ libzpool_la_SOURCES = \ ${top_srcdir}/module/zcommon/include/sys/fs/zfs.h \ ${top_srcdir}/module/zcommon/include/zfs_comutil.h \ ${top_srcdir}/module/zcommon/include/zfs_deleg.h \ + ${top_srcdir}/module/zcommon/include/zfs_fletcher.h \ ${top_srcdir}/module/zcommon/include/zfs_namecheck.h \ ${top_srcdir}/module/zcommon/include/zfs_prop.h \ ${top_srcdir}/module/zfs/arc.c \ ${top_srcdir}/module/zfs/bplist.c \ + ${top_srcdir}/module/zfs/bpobj.c \ ${top_srcdir}/module/zfs/dbuf.c \ + ${top_srcdir}/module/zfs/ddt.c \ + ${top_srcdir}/module/zfs/ddt_zap.c \ ${top_srcdir}/module/zfs/dmu.c \ ${top_srcdir}/module/zfs/dmu_object.c \ ${top_srcdir}/module/zfs/dmu_objset.c \ @@ -42,18 +47,20 @@ libzpool_la_SOURCES = \ ${top_srcdir}/module/zfs/dnode.c \ ${top_srcdir}/module/zfs/dnode_sync.c \ ${top_srcdir}/module/zfs/dsl_dataset.c \ + ${top_srcdir}/module/zfs/dsl_deadlist.c \ ${top_srcdir}/module/zfs/dsl_deleg.c \ ${top_srcdir}/module/zfs/dsl_dir.c \ ${top_srcdir}/module/zfs/dsl_pool.c \ ${top_srcdir}/module/zfs/dsl_prop.c \ - ${top_srcdir}/module/zfs/dsl_scrub.c \ + ${top_srcdir}/module/zfs/dsl_scan.c \ ${top_srcdir}/module/zfs/dsl_synctask.c \ - ${top_srcdir}/module/zfs/fletcher.c \ ${top_srcdir}/module/zfs/fm.c \ ${top_srcdir}/module/zfs/gzip.c \ ${top_srcdir}/module/zfs/lzjb.c \ ${top_srcdir}/module/zfs/metaslab.c \ ${top_srcdir}/module/zfs/refcount.c \ + ${top_srcdir}/module/zfs/rrwlock.c \ + ${top_srcdir}/module/zfs/sa.c \ ${top_srcdir}/module/zfs/sha256.c \ ${top_srcdir}/module/zfs/spa.c \ ${top_srcdir}/module/zfs/spa_boot.c \ @@ -69,8 +76,8 @@ libzpool_la_SOURCES = \ ${top_srcdir}/module/zfs/vdev_cache.c \ ${top_srcdir}/module/zfs/vdev_file.c \ ${top_srcdir}/module/zfs/vdev_label.c \ - ${top_srcdir}/module/zfs/vdev_missing.c \ ${top_srcdir}/module/zfs/vdev_mirror.c \ + ${top_srcdir}/module/zfs/vdev_missing.c \ ${top_srcdir}/module/zfs/vdev_queue.c \ ${top_srcdir}/module/zfs/vdev_raidz.c \ ${top_srcdir}/module/zfs/vdev_root.c \ @@ -78,14 +85,17 @@ libzpool_la_SOURCES = \ ${top_srcdir}/module/zfs/zap_leaf.c \ ${top_srcdir}/module/zfs/zap_micro.c \ ${top_srcdir}/module/zfs/zfs_byteswap.c \ + ${top_srcdir}/module/zfs/zfs_debug.c \ ${top_srcdir}/module/zfs/zfs_fm.c \ ${top_srcdir}/module/zfs/zfs_fuid.c \ + ${top_srcdir}/module/zfs/zfs_sa.c \ ${top_srcdir}/module/zfs/zfs_znode.c \ ${top_srcdir}/module/zfs/zil.c \ ${top_srcdir}/module/zfs/zio.c \ ${top_srcdir}/module/zfs/zio_checksum.c \ ${top_srcdir}/module/zfs/zio_compress.c \ ${top_srcdir}/module/zfs/zio_inject.c \ + ${top_srcdir}/module/zfs/zle.c \ ${top_srcdir}/module/zfs/include/sys/arc.h \ ${top_srcdir}/module/zfs/include/sys/bplist.h \ ${top_srcdir}/module/zfs/include/sys/dbuf.h \ diff --git a/module/zcommon/Makefile.in b/module/zcommon/Makefile.in index 58e2591f60..def2b7d978 100644 --- a/module/zcommon/Makefile.in +++ b/module/zcommon/Makefile.in @@ -14,4 +14,5 @@ ${MODULE}-objs += zfs_prop.o ${MODULE}-objs += zprop_common.o ${MODULE}-objs += zfs_namecheck.o ${MODULE}-objs += zfs_comutil.o +${MODULE}-objs += zfs_fletcher.o ${MODULE}-objs += zpool_prop.o diff --git a/module/zfs/Makefile.in b/module/zfs/Makefile.in index 0353b0225e..ab25cc0b38 100644 --- a/module/zfs/Makefile.in +++ b/module/zfs/Makefile.in @@ -11,7 +11,10 @@ obj-m := ${MODULE}.o ${MODULE}-objs += arc.o ${MODULE}-objs += bplist.o +${MODULE}-objs += bpobj.o ${MODULE}-objs += dbuf.o +${MODULE}-objs += ddt.o +${MODULE}-objs += ddt_zap.o ${MODULE}-objs += dmu.o ${MODULE}-objs += dmu_object.o ${MODULE}-objs += dmu_objset.o @@ -22,19 +25,20 @@ ${MODULE}-objs += dmu_zfetch.o ${MODULE}-objs += dnode.o ${MODULE}-objs += dnode_sync.o ${MODULE}-objs += dsl_dataset.o +${MODULE}-objs += dsl_deadlist.o ${MODULE}-objs += dsl_deleg.o ${MODULE}-objs += dsl_dir.o ${MODULE}-objs += dsl_pool.o ${MODULE}-objs += dsl_prop.o -${MODULE}-objs += dsl_scrub.o +${MODULE}-objs += dsl_scan.o ${MODULE}-objs += dsl_synctask.o -${MODULE}-objs += fletcher.o ${MODULE}-objs += fm.o ${MODULE}-objs += gzip.o ${MODULE}-objs += lzjb.o ${MODULE}-objs += metaslab.o ${MODULE}-objs += refcount.o ${MODULE}-objs += rrwlock.o +${MODULE}-objs += sa.o ${MODULE}-objs += sha256.o ${MODULE}-objs += spa.o ${MODULE}-objs += spa_boot.o @@ -62,6 +66,7 @@ ${MODULE}-objs += zap_micro.o ${MODULE}-objs += zfs_acl.o ${MODULE}-objs += zfs_byteswap.o ${MODULE}-objs += zfs_ctldir.o +${MODULE}-objs += zfs_debug.o ${MODULE}-objs += zfs_dir.o ${MODULE}-objs += zfs_fm.o ${MODULE}-objs += zfs_fuid.o @@ -69,6 +74,7 @@ ${MODULE}-objs += zfs_ioctl.o ${MODULE}-objs += zfs_log.o ${MODULE}-objs += zfs_replay.o ${MODULE}-objs += zfs_rlock.o +${MODULE}-objs += zfs_sa.o ${MODULE}-objs += zfs_vfsops.o ${MODULE}-objs += zfs_vnops.o ${MODULE}-objs += zfs_znode.o @@ -77,4 +83,5 @@ ${MODULE}-objs += zio.o ${MODULE}-objs += zio_checksum.o ${MODULE}-objs += zio_compress.o ${MODULE}-objs += zio_inject.o +${MODULE}-objs += zle.o ${MODULE}-objs += zvol.o diff --git a/module/zfs/dsl_scan.c b/module/zfs/dsl_scan.c index 6f095dad8e..0eb1b1f782 100644 --- a/module/zfs/dsl_scan.c +++ b/module/zfs/dsl_scan.c @@ -1234,10 +1234,12 @@ static void dsl_scan_ddt(dsl_scan_t *scn, dmu_tx_t *tx) { ddt_bookmark_t *ddb = &scn->scn_phys.scn_ddt_bookmark; - ddt_entry_t dde = { 0 }; + ddt_entry_t dde; int error; uint64_t n = 0; + bzero(&dde, sizeof (ddt_entry_t)); + while ((error = ddt_walk(scn->scn_dp->dp_spa, ddb, &dde)) == 0) { ddt_t *ddt; diff --git a/module/zpios/zpios.c b/module/zpios/zpios.c index 89b3f34696..ff2db3b39b 100644 --- a/module/zpios/zpios.c +++ b/module/zpios/zpios.c @@ -40,7 +40,7 @@ static spl_class *zpios_class; static spl_device *zpios_device; - +static char *zpios_tag = "zpios_tag"; static int zpios_upcall(char *path, char *phase, run_args_t *run_args, int rc) @@ -161,17 +161,26 @@ zpios_dmu_setup(run_args_t *run_args) { zpios_time_t *t = &(run_args->stats.cr_time); objset_t *os; + char name[32]; uint64_t obj = 0ULL; - int i, rc = 0; + int i, rc = 0, rc2; (void)zpios_upcall(run_args->pre, PHASE_PRE_CREATE, run_args, 0); t->start = zpios_timespec_now(); - rc = dmu_objset_open(run_args->pool, DMU_OST_ZFS, DS_MODE_USER, &os); - if (rc) { - zpios_print(run_args->file, "Error dmu_objset_open() " - "failed: %d\n", rc); + (void)snprintf(name, 32, "%s/id_%d", run_args->pool, run_args->id); + rc = dmu_objset_create(name, DMU_OST_OTHER, 0, NULL, NULL); + if (rc) { + zpios_print(run_args->file, "Error dmu_objset_create(%s, ...) " + "failed: %d\n", name, rc); goto out; + } + + rc = dmu_objset_own(name, DMU_OST_OTHER, 0, zpios_tag, &os); + if (rc) { + zpios_print(run_args->file, "Error dmu_objset_own(%s, ...) " + "failed: %d\n", name, rc); + goto out_destroy; } if (!(run_args->flags & DMU_FPP)) { @@ -180,7 +189,7 @@ zpios_dmu_setup(run_args_t *run_args) rc = -EBADF; zpios_print(run_args->file, "Error zpios_dmu_" "object_create() failed, %d\n", rc); - goto out; + goto out_destroy; } } @@ -213,6 +222,13 @@ zpios_dmu_setup(run_args_t *run_args) } run_args->os = os; +out_destroy: + if (rc) { + rc2 = dmu_objset_destroy(name, B_FALSE); + if (rc2) + zpios_print(run_args->file, "Error dmu_objset_destroy" + "(%s, ...) failed: %d\n", name, rc2); + } out: t->stop = zpios_timespec_now(); t->delta = zpios_timespec_sub(t->stop, t->start); @@ -340,15 +356,18 @@ zpios_get_work_item(run_args_t *run_args, dmu_obj_t *obj, __u64 *offset, } static void -zpios_remove_objects(run_args_t *run_args) +zpios_remove_objset(run_args_t *run_args) { zpios_time_t *t = &(run_args->stats.rm_time); zpios_region_t *region; + char name[32]; int rc = 0, i; (void)zpios_upcall(run_args->pre, PHASE_PRE_REMOVE, run_args, 0); t->start = zpios_timespec_now(); + (void)snprintf(name, 32, "%s/id_%d", run_args->pool, run_args->id); + if (run_args->flags & DMU_REMOVE) { if (run_args->flags & DMU_FPP) { for (i = 0; i < run_args->region_count; i++) { @@ -373,7 +392,14 @@ zpios_remove_objects(run_args_t *run_args) } } - dmu_objset_close(run_args->os); + dmu_objset_disown(run_args->os, zpios_tag); + + if (run_args->flags & DMU_REMOVE) { + rc = dmu_objset_destroy(name, B_FALSE); + if (rc) + zpios_print(run_args->file, "Error dmu_objset_destroy" + "(%s, ...) failed: %d\n", name, rc); + } t->stop = zpios_timespec_now(); t->delta = zpios_timespec_sub(t->stop, t->start); @@ -843,7 +869,7 @@ zpios_do_one_run(struct file *file, zpios_cmd_t *kcmd, return rc; rc = zpios_threads_run(run_args); - zpios_remove_objects(run_args); + zpios_remove_objset(run_args); if (rc) goto cleanup; @@ -1009,61 +1035,71 @@ zpios_ioctl_cfg(struct file *file, unsigned long arg) static int zpios_ioctl_cmd(struct file *file, unsigned long arg) { - zpios_cmd_t kcmd; - int rc = -EINVAL; + zpios_cmd_t *kcmd; void *data = NULL; + int rc = -EINVAL; - rc = copy_from_user(&kcmd, (zpios_cfg_t *)arg, sizeof(kcmd)); + kcmd = kmem_alloc(sizeof(zpios_cmd_t), KM_SLEEP); + if (kcmd == NULL) { + zpios_print(file, "Unable to kmem_alloc() %ld byte for " + "zpios_cmd_t\n", sizeof(zpios_cmd_t)); + return -ENOMEM; + } + + rc = copy_from_user(kcmd, (zpios_cfg_t *)arg, sizeof(zpios_cmd_t)); if (rc) { zpios_print(file, "Unable to copy command structure " "from user to kernel memory, %d\n", rc); - return -EFAULT; + goto out_cmd; } - if (kcmd.cmd_magic != ZPIOS_CMD_MAGIC) { + if (kcmd->cmd_magic != ZPIOS_CMD_MAGIC) { zpios_print(file, "Bad command magic 0x%x != 0x%x\n", - kcmd.cmd_magic, ZPIOS_CFG_MAGIC); - return -EINVAL; + kcmd->cmd_magic, ZPIOS_CFG_MAGIC); + rc = -EINVAL; + goto out_cmd; } /* Allocate memory for any opaque data the caller needed to pass on */ - if (kcmd.cmd_data_size > 0) { - data = (void *)vmem_alloc(kcmd.cmd_data_size, KM_SLEEP); + if (kcmd->cmd_data_size > 0) { + data = (void *)vmem_alloc(kcmd->cmd_data_size, KM_SLEEP); if (data == NULL) { zpios_print(file, "Unable to vmem_alloc() %ld " "bytes for data buffer\n", - (long)kcmd.cmd_data_size); - return -ENOMEM; + (long)kcmd->cmd_data_size); + rc = -ENOMEM; + goto out_cmd; } rc = copy_from_user(data, (void *)(arg + offsetof(zpios_cmd_t, - cmd_data_str)), kcmd.cmd_data_size); + cmd_data_str)), kcmd->cmd_data_size); if (rc) { zpios_print(file, "Unable to copy data buffer " "from user to kernel memory, %d\n", rc); - vmem_free(data, kcmd.cmd_data_size); - return -EFAULT; + goto out_data; } } - rc = zpios_do_one_run(file, &kcmd, kcmd.cmd_data_size, data); + rc = zpios_do_one_run(file, kcmd, kcmd->cmd_data_size, data); if (data != NULL) { /* If the test failed do not print out the stats */ if (rc) - goto cleanup; + goto out_data; rc = copy_to_user((void *)(arg + offsetof(zpios_cmd_t, - cmd_data_str)), data, kcmd.cmd_data_size); + cmd_data_str)), data, kcmd->cmd_data_size); if (rc) { zpios_print(file, "Unable to copy data buffer " "from kernel to user memory, %d\n", rc); rc = -EFAULT; } -cleanup: - vmem_free(data, kcmd.cmd_data_size); +out_data: + vmem_free(data, kcmd->cmd_data_size); } +out_cmd: + kmem_free(kcmd, sizeof(zpios_cmd_t)); return rc; }