Skip to content

Commit

Permalink
Merge pull request openzfs#540 from delphix/projects/merge-upstream/m…
Browse files Browse the repository at this point in the history
…aster

Merge remote-tracking branch '6.0/stage' into 'master'
  • Loading branch information
delphix-devops-bot authored Jul 27, 2022
2 parents febfcff + 57f5a0a commit afc6009
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 105 deletions.
15 changes: 10 additions & 5 deletions cmd/zfs/zfs_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ zfs_sort_only_by_name(const zfs_sort_column_t *sc)
sc->sc_prop == ZFS_PROP_NAME);
}

int
zfs_sort_only_by_createtxg(const zfs_sort_column_t *sc)
{
return (sc != NULL && sc->sc_next == NULL &&
sc->sc_prop == ZFS_PROP_CREATETXG);
}

static int
zfs_compare(const void *larg, const void *rarg)
{
Expand Down Expand Up @@ -301,7 +308,7 @@ zfs_sort(const void *larg, const void *rarg, void *data)
for (psc = sc; psc != NULL; psc = psc->sc_next) {
char lbuf[ZFS_MAXPROPLEN], rbuf[ZFS_MAXPROPLEN];
char *lstr, *rstr;
uint64_t lnum, rnum;
uint64_t lnum = 0, rnum = 0;
boolean_t lvalid, rvalid;
int ret = 0;

Expand Down Expand Up @@ -352,11 +359,9 @@ zfs_sort(const void *larg, const void *rarg, void *data)
zfs_get_type(r), B_FALSE);

if (lvalid)
(void) zfs_prop_get_numeric(l, psc->sc_prop,
&lnum, NULL, NULL, 0);
lnum = zfs_prop_get_int(l, psc->sc_prop);
if (rvalid)
(void) zfs_prop_get_numeric(r, psc->sc_prop,
&rnum, NULL, NULL, 0);
rnum = zfs_prop_get_int(r, psc->sc_prop);
}

if (!lvalid && !rvalid)
Expand Down
1 change: 1 addition & 0 deletions cmd/zfs/zfs_iter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ int zfs_for_each(int, char **, int options, zfs_type_t,
int zfs_add_sort_column(zfs_sort_column_t **, const char *, boolean_t);
void zfs_free_sort_columns(zfs_sort_column_t *);
int zfs_sort_only_by_name(const zfs_sort_column_t *);
int zfs_sort_only_by_createtxg(const zfs_sort_column_t *);

#ifdef __cplusplus
}
Expand Down
9 changes: 6 additions & 3 deletions cmd/zfs/zfs_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3655,11 +3655,14 @@ found3:;
argv += optind;

/*
* If we are only going to list snapshot names and sort by name,
* then we can use faster version.
* If we are only going to list snapshot names and sort by name or
* by createtxg, then we can use faster version.
*/
if (strcmp(fields, "name") == 0 && zfs_sort_only_by_name(sortcol))
if (strcmp(fields, "name") == 0 &&
(zfs_sort_only_by_name(sortcol) ||
zfs_sort_only_by_createtxg(sortcol))) {
flags |= ZFS_ITER_SIMPLE;
}

/*
* If "-o space" and no types were specified, don't display snapshots.
Expand Down
114 changes: 105 additions & 9 deletions cmd/zfs_object_agent/server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,20 @@ enum Commands {
#[clap(short = 'b', long)]
bucket: String,

/// Credentials profile in ~/.aws/credentials
#[clap(short = 'p', long)]
profile: Option<String>,

/// AWS access key id
#[clap(
short = 'i',
long,
alias = "aws_access_key_id",
requires = "aws-secret-access-key",
required_unless_present = "aws-instance-profile",
conflicts_with = "aws-instance-profile"
required_unless_present = "profile",
conflicts_with = "aws-instance-profile",
conflicts_with = "profile"
)]
aws_access_key_id: Option<String>,

Expand All @@ -136,12 +142,19 @@ enum Commands {
alias = "aws_secret_access_key",
requires = "aws-access-key-id",
required_unless_present = "aws-instance-profile",
conflicts_with = "aws-instance-profile"
required_unless_present = "profile",
conflicts_with = "aws-instance-profile",
conflicts_with = "profile"
)]
aws_secret_access_key: Option<String>,

/// Use IAM instance profile
#[clap(short = 'm', long, alias = "aws_instance_profile")]
#[clap(
short = 'm',
long,
alias = "aws_instance_profile",
conflicts_with = "profile"
)]
aws_instance_profile: bool,
},
/// test connectivity blob
Expand All @@ -154,15 +167,26 @@ enum Commands {
#[clap(short = 'b', long)]
bucket: String,

/// Credentials profile in ~/.azure/credentials
#[clap(
short = 'p',
long,
conflicts_with = "azure-account",
conflicts_with = "azure-key",
conflicts_with = "managed-identity"
)]
profile: Option<String>,

/// Azure-Blob account name
#[clap(short = 'a', long)]
azure_account: String,
#[clap(short = 'a', long, required_unless_present = "profile")]
azure_account: Option<String>,

/// Azure-Blob secret key
#[clap(
short = 's',
long,
required_unless_present = "managed-identity",
required_unless_present = "profile",
conflicts_with = "managed-identity"
)]
azure_key: Option<String>,
Expand All @@ -172,6 +196,7 @@ enum Commands {
short = 'm',
long,
required_unless_present = "azure-key",
required_unless_present = "profile",
conflicts_with = "azure-key"
)]
managed_identity: bool,
Expand Down Expand Up @@ -211,6 +236,7 @@ fn main() {
endpoint,
region,
bucket,
profile,
aws_access_key_id,
aws_secret_access_key,
aws_instance_profile,
Expand All @@ -220,6 +246,8 @@ fn main() {
region,
credentials: if aws_instance_profile {
S3Credentials::InstanceProfile
} else if let Some(p) = profile {
S3Credentials::Profile(p)
} else {
S3Credentials::Key {
aws_access_key_id: aws_access_key_id.unwrap(),
Expand All @@ -234,17 +262,22 @@ fn main() {
Some(Commands::TestConnectivityBlob {
endpoint,
bucket,
profile,
azure_account,
azure_key,
managed_identity,
}) => {
let protocol = ObjectAccessProtocol::Blob {
endpoint,
credentials: if managed_identity {
BlobCredentials::ManagedCredentials { azure_account }
BlobCredentials::ManagedCredentials {
azure_account: azure_account.unwrap(),
}
} else if profile.is_some() {
BlobCredentials::Profile(profile.unwrap())
} else {
BlobCredentials::Key {
azure_account,
azure_account: azure_account.unwrap(),
azure_key: azure_key.unwrap(),
}
},
Expand Down Expand Up @@ -329,13 +362,15 @@ mod test {
Some(Commands::TestConnectivityBlob {
endpoint,
bucket,
profile,
azure_account,
azure_key,
managed_identity,
}) => {
assert_eq!(endpoint.unwrap(), "foo");
assert_eq!(&bucket, "bar");
assert_eq!(azure_account, "azure-account");
assert!(profile.is_none());
assert_eq!(azure_account.unwrap(), "azure-account");
assert_eq!(azure_key.unwrap(), "super-secret-key");
assert!(!managed_identity);
}
Expand All @@ -352,20 +387,44 @@ mod test {
Some(Commands::TestConnectivityBlob {
endpoint,
bucket,
profile,
azure_account,
azure_key,
managed_identity,
}) => {
assert_eq!(endpoint.unwrap(), "foo");
assert_eq!(&bucket, "bar");
assert_eq!(azure_account, "azure-account");
assert!(profile.is_none());
assert_eq!(azure_account.unwrap(), "azure-account");
assert!(azure_key.is_none());
assert!(managed_identity);
}
_ => panic!("wrong subcommand"),
}
}

#[test]
fn test_connectivity_blob_profile() {
let cli = pos("zfs_object_agent test-connectivity-blob -e foo -b bar -p profile");
match cli.command {
Some(Commands::TestConnectivityBlob {
endpoint,
bucket,
profile,
azure_account,
azure_key,
managed_identity,
}) => {
assert_eq!(endpoint.unwrap(), "foo");
assert_eq!(&bucket, "bar");
assert_eq!(profile.unwrap(), "profile");
assert!(azure_account.is_none());
assert!(azure_key.is_none());
assert!(!managed_identity);
}
_ => panic!("wrong subcommand"),
}
}
#[test]
fn test_connectivity_default_protocol() {
let cli =
Expand All @@ -375,13 +434,15 @@ mod test {
endpoint,
region,
bucket,
profile,
aws_access_key_id,
aws_secret_access_key,
aws_instance_profile,
}) => {
assert_eq!(endpoint, "foo");
assert_eq!(region, "bar");
assert_eq!(&bucket, "baz");
assert!(profile.is_none());
assert!(aws_access_key_id.is_none());
assert!(aws_secret_access_key.is_none());
assert!(aws_instance_profile);
Expand All @@ -392,6 +453,31 @@ mod test {

#[test]
fn test_connectivity_profile() {
let cli = pos("zfs_object_agent test-connectivity-s3 -e foo -r bar -b baz -p profile");
match cli.command {
Some(Commands::TestConnectivityS3 {
endpoint,
region,
bucket,
profile,
aws_access_key_id,
aws_secret_access_key,
aws_instance_profile,
}) => {
assert_eq!(endpoint, "foo");
assert_eq!(region, "bar");
assert_eq!(&bucket, "baz");
assert_eq!(profile.unwrap(), "profile");
assert!(aws_access_key_id.is_none());
assert!(aws_secret_access_key.is_none());
assert!(!aws_instance_profile);
}
_ => panic!("wrong subcommand"),
}
}

#[test]
fn test_connectivity_instance_profile() {
let cli = pos(
"zfs_object_agent test-connectivity-s3 -e foo -r bar -b baz --aws-instance-profile",
);
Expand All @@ -400,13 +486,15 @@ mod test {
endpoint,
region,
bucket,
profile,
aws_access_key_id,
aws_secret_access_key,
aws_instance_profile,
}) => {
assert_eq!(endpoint, "foo");
assert_eq!(region, "bar");
assert_eq!(&bucket, "baz");
assert!(profile.is_none());
assert!(aws_access_key_id.is_none());
assert!(aws_secret_access_key.is_none());
assert!(aws_instance_profile);
Expand All @@ -423,13 +511,15 @@ mod test {
endpoint,
region,
bucket,
profile,
aws_access_key_id,
aws_secret_access_key,
aws_instance_profile,
}) => {
assert_eq!(endpoint, "foo");
assert_eq!(region, "bar");
assert_eq!(&bucket, "baz");
assert!(profile.is_none());
assert_eq!(aws_access_key_id.unwrap(), "abcd");
assert_eq!(aws_secret_access_key.unwrap(), "1234");
assert!(!aws_instance_profile);
Expand All @@ -450,6 +540,9 @@ mod test {
fn test_connectivity_s3_param_conflicts() {
neg("zfs_object_agent test-connectivity-s3 -e foo -r bar -b baz -i abcd -s 1234 --aws-instance-profile");
neg("zfs_object_agent test-connectivity-s3 -e foo -r bar -b baz -i abcd --aws-instance-profile");
neg("zfs_object_agent test-connectivity-s3 -e foo -r bar -b baz -p profile --aws-instance-profile");
neg("zfs_object_agent test-connectivity-s3 -e foo -r bar -b baz -s 1234 -p profile");
neg("zfs_object_agent test-connectivity-s3 -e foo -r bar -b baz -i abcd -p profile");
}

#[test]
Expand All @@ -464,6 +557,9 @@ mod test {
#[test]
fn test_connectivity_blob_param_conflicts() {
neg("zfs_object_agent test-connectivity-blob -e foo -b baz -a abcd -s 1234 --managed_identity");
neg("zfs_object_agent test-connectivity-blob -e foo -b baz -a abcd -p profile");
neg("zfs_object_agent test-connectivity-blob -e foo -b baz -s 123 -p profile");
neg("zfs_object_agent test-connectivity-blob -e foo -b baz -p profile --managed_identity");
}

#[test]
Expand Down
Loading

0 comments on commit afc6009

Please sign in to comment.