Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .cci.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ cosaPod(buildroot: true) {

stage("Build metal+live") {
shwrap("cd /srv/fcos && cosa build metal")
shwrap("cd /srv/fcos && cosa buildextend-metal4k")
shwrap("cd /srv/fcos && cosa buildextend-live")
}
stage("Test ISO") {
shwrap("cd /srv/fcos && kola testiso -S")
shwrap("cd /srv/fcos && kola testiso -SP --qemu-native-4k")
}
}
21 changes: 20 additions & 1 deletion src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ use nix::{errno::Errno, mount};
use regex::Regex;
use std::collections::HashMap;
use std::convert::TryInto;
use std::fs::{remove_dir, File};
use std::fs::{remove_dir, File, OpenOptions};
use std::num::NonZeroU32;
use std::os::raw::c_int;
use std::os::unix::fs::FileTypeExt;
use std::os::unix::io::AsRawFd;
use std::path::{Path, PathBuf};
use std::process::Command;
Expand Down Expand Up @@ -209,6 +210,24 @@ pub fn reread_partition_table(file: &mut File) -> Result<()> {
Ok(())
}

pub fn get_sector_size_for_path(device: &Path) -> Result<NonZeroU32> {
let dev = OpenOptions::new()
.read(true)
.open(device)
.chain_err(|| format!("opening {:?}", device))?;

if !dev
.metadata()
.chain_err(|| format!("getting metadata for {:?}", device))?
.file_type()
.is_block_device()
{
bail!("{:?} is not a block device", device);
}

get_sector_size(&dev)
}

/// Get the logical sector size of a block device.
pub fn get_sector_size(file: &File) -> Result<NonZeroU32> {
let fd = file.as_raw_fd();
Expand Down
31 changes: 26 additions & 5 deletions src/cmdline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
use clap::{crate_version, App, AppSettings, Arg, ArgMatches, SubCommand};
use error_chain::bail;
use reqwest::Url;
use std::path::Path;

use crate::blockdev::*;
use crate::errors::*;
use crate::source::*;

Expand Down Expand Up @@ -346,6 +348,11 @@ pub fn parse_args() -> Result<Config> {
}

fn parse_install(matches: &ArgMatches) -> Result<Config> {
let device = matches
.value_of("device")
.map(String::from)
.expect("device missing");

// Build image location. Ideally we'd use conflicts_with (and an
// ArgGroup for streams), but that doesn't play well with default
// arguments, so we manually prioritize modes.
Expand All @@ -363,13 +370,30 @@ fn parse_install(matches: &ArgMatches) -> Result<Config> {
} else {
None
};
let format = match get_sector_size_for_path(Path::new(&device))
.chain_err(|| format!("getting sector size of {}", &device))?
.get()
{
4096 => "4k.raw.xz",
512 => "raw.xz",
n => {
// could bail on non-512, but let's be optimistic and just warn but try the regular
// 512b image
eprintln!(
"Found non-standard sector size {} for {}, assuming 512b-compatible",
n, &device
);
"raw.xz"
}
};

Box::new(StreamLocation::new(
matches.value_of("stream").expect("stream missing"),
matches
.value_of("architecture")
.expect("architecture missing"),
"metal",
"raw.xz",
format,
base_url.as_ref(),
)?)
};
Expand All @@ -378,10 +402,7 @@ fn parse_install(matches: &ArgMatches) -> Result<Config> {

// build configuration
Ok(Config::Install(InstallConfig {
device: matches
.value_of("device")
.map(String::from)
.expect("device missing"),
device,
location,
ignition: matches.value_of("ignition-file").map(String::from),
platform: matches.value_of("platform").map(String::from),
Expand Down
10 changes: 7 additions & 3 deletions src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,15 @@ impl Display for StreamLocation {
if self.stream_base_url.is_some() {
write!(
f,
"Downloading image and signature referenced from {}",
self.stream_url
"Downloading image ({}) and signature referenced from {}",
self.format, self.stream_url
)
} else {
write!(f, "Downloading {} image and signature", self.stream)
write!(
f,
"Downloading {} image ({}) and signature",
self.stream, self.format
)
}
}
}
Expand Down