Skip to content
Permalink
b9c23b4088
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 76 lines (66 sloc) 1.66 KB
#! /usr/bin/bash
usage() {
cat <<EOF >&2
usage:
$0 create JOBID SIZE UID # create SIZE GiB /dev/shm/mxqd/mnt/job/$JOBID
$0 cleanup JOBID # cleanup
EOF
exit 1
}
tmpdir=/scratch/local2/mxqd/tmp
mntdir=/dev/shm/mxqd/mnt/job
cmd_create() {
(( $# == 3 )) || usage
MXQ_JOBID=$1
MXQ_SIZE=$2
MXQ_UID=$3
filename=$tmpdir/$MXQ_JOBID.tmp
mountpoint=$mntdir/$MXQ_JOBID
umask 006
mkdir -p $tmpdir
mkdir -p $mntdir
status=1;
if fallocate -l ${MXQ_SIZE}G $filename; then
if loopdevice=$(losetup --find --show $filename); then
if mkfs.ext4 \
-q \
-m 0 \
-E nodiscard,mmp_update_interval=300,lazy_journal_init=1,root_owner=$MXQ_UID:0 \
-O '64bit,ext_attr,filetype,^has_journal,huge_file,inline_data,^mmp,^quota,sparse_super2' \
$loopdevice \
&& mkdir -p $mountpoint && mount -Odata=writeback,barrier=0 $loopdevice $mountpoint; then
rmdir $mountpoint/lost+found
status=0
fi
losetup -d $loopdevice
fi
rm $filename
else
test -e $filename && rm $filename
fi
exit $status
}
cmd_cleanup() {
(( $# == 1 )) || usage
MXQ_JOBID=$1
(
shopt -s dotglob;
rm -rf /dev/shm/mxqd/mnt/job/$MXQ_JOBID/*
umount /dev/shm/mxqd/mnt/job/$MXQ_JOBID
rmdir /dev/shm/mxqd/mnt/job/$MXQ_JOBID
) &
}
(( $# > 0 )) || usage
cmd="$1"
shift;
case "$cmd" in
create)
cmd_create "$@"
;;
cleanup)
cmd_cleanup "$@"
;;
*)
usage
;;
esac