On Thu, 09 Jun 2022 15:54:15 +0100, Luís Henriques wrote: > David Disseldorp <ddiss@xxxxxxx> writes: ... > > I take it a more exact calculation would be something like: > > (64K - $max_attrval_namelen - sizeof(user.snrub="fish2\012"))? > > > > Perhaps you could calculate this on the fly for CephFS by passing in the > > filename and subtracting the `getfattr -d $filename` results... That > > said, it'd probably get a bit ugly, expecially if encoding needs to be > > taken into account. > > In fact, this is *exactly* what I had before Dave suggested to keep it > simple. Arg, sorry I missed your previous round. > After moving the code back into common/attr, where's how the > generic code would look like: > > + ceph) > + # CephFS does have a limit for the whole set of names+values > + # attributes in a file. Thus, it is necessary to get the sizes > + # of all names and values already existent and subtract them to > + # the (default) maximum, which is 64k. > + local len=0 > + while read line; do > + # skip 1st line > + [ "$line" != "${line#'#'}" ] && continue > + n=$(echo $line | awk -F"=0x" '{print $1}') > + v=$(echo $line | awk -F"=0x" '{print $2}') > + nlen=${#n} > + vlen=${#v} > + # total is the sum of the name len and the value len > + # divided by 2 because we're dumping them in hex format > + t=$(($nlen + $vlen / 2)) > + len=$(($len + $t)) > + done <<< $(_getfattr -d -e hex $file 2> /dev/null) > + echo $((65536 - $max_attrval_namelen - $len)) > + ;; > > so... yeah, I'm not particularly gifted on shell, it could probably be > done in more clever/cleaner ways. Anyway, I'm open to revisit this if > this is the preferred solution. hmm, I was hoping something like... (( 65536 - $max_attrval_namelen - $(getfattr -d $file | _filter | wc -c) )) would be possible, but getfattr output does make it a bit too messy. Cheers, David