__u32 cl_supp_cksum_types;
/* checksum algorithm to be used */
enum cksum_types cl_cksum_type;
+ /* preferred checksum algorithm to be used */
+ enum cksum_types cl_preferred_cksum_type;
/* also protected by the poorly named _loi_list_lock lock above */
struct osc_async_rc cl_ar;
* checksum type due to its benchmarking at libcfs module load.
* Caution is advised, however, since what is fastest on a single client may
* not be the fastest or most efficient algorithm on the server. */
-static inline enum cksum_types
-obd_cksum_type_select(const char *obd_name, enum cksum_types cksum_types)
+static inline
+enum cksum_types obd_cksum_type_select(const char *obd_name,
+ enum cksum_types cksum_types,
+ enum cksum_types preferred)
{
- u32 flag = obd_cksum_type_pack(obd_name, cksum_types);
+ u32 flag;
+
+ if (preferred & cksum_types)
+ return preferred;
+
+ flag = obd_cksum_type_pack(obd_name, cksum_types);
return obd_cksum_type_unpack(flag);
}
init_waitqueue_head(&cli->cl_destroy_waitq);
atomic_set(&cli->cl_destroy_in_flight, 0);
+
cli->cl_supp_cksum_types = OBD_CKSUM_CRC32;
+ cli->cl_preferred_cksum_type = 0;
#ifdef ENABLE_CHECKSUM
/* Turn on checksumming by default. */
cli->cl_checksum = 1;
int i;
DECLARE_CKSUM_NAME;
char kernbuf[10];
+ int rc = -EINVAL;
- if (obd == NULL)
- return 0;
+ if (obd == NULL)
+ return 0;
- if (count > sizeof(kernbuf) - 1)
- return -EINVAL;
+ if (count > sizeof(kernbuf) - 1)
+ return -EINVAL;
if (copy_from_user(kernbuf, buffer, count))
- return -EFAULT;
- if (count > 0 && kernbuf[count - 1] == '\n')
- kernbuf[count - 1] = '\0';
- else
- kernbuf[count] = '\0';
-
- for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
- if (((1 << i) & obd->u.cli.cl_supp_cksum_types) == 0)
- continue;
- if (!strcmp(kernbuf, cksum_name[i])) {
- obd->u.cli.cl_cksum_type = 1 << i;
- return count;
- }
- }
- return -EINVAL;
+ return -EFAULT;
+
+ if (count > 0 && kernbuf[count - 1] == '\n')
+ kernbuf[count - 1] = '\0';
+ else
+ kernbuf[count] = '\0';
+
+ for (i = 0; i < ARRAY_SIZE(cksum_name); i++) {
+ if (strcmp(kernbuf, cksum_name[i]) == 0) {
+ obd->u.cli.cl_preferred_cksum_type = BIT(i);
+ if (obd->u.cli.cl_supp_cksum_types & BIT(i)) {
+ obd->u.cli.cl_cksum_type = BIT(i);
+ rc = count;
+ } else {
+ rc = -ENOTSUPP;
+ }
+ break;
+ }
+ }
+ return rc;
}
LPROC_SEQ_FOPS(osc_checksum_type);
cli->cl_supp_cksum_types = OBD_CKSUM_ADLER;
}
cli->cl_cksum_type = obd_cksum_type_select(imp->imp_obd->obd_name,
- cli->cl_supp_cksum_types);
+ cli->cl_supp_cksum_types,
+ cli->cl_preferred_cksum_type);
if (ocd->ocd_connect_flags & OBD_CONNECT_BRW_SIZE)
cli->cl_max_pages_per_rpc =
set_checksum_type()
{
lctl set_param -n osc.*osc-[^mM]*.checksum_type $1
- log "set checksum type to $1"
- return 0
+ rc=$?
+ log "set checksum type to $1, rc = $rc"
+ return $rc
+}
+
+get_osc_checksum_type()
+{
+ # arugment 1: OST name, like OST0000
+ ost=$1
+ checksum_type=$(lctl get_param -n osc.*${ost}-osc-[^mM]*.checksum_type |
+ sed 's/.*\[\(.*\)\].*/\1/g')
+ rc=$?
+ [ $rc -ne 0 ] && error "failed to get checksum type of $ost, rc = $rc, output = $checksum_type"
+ echo $checksum_type
}
+
F77_TMP=$TMP/f77-temp
F77SZ=8
setup_f77() {
}
run_test 77k "enable/disable checksum correctly"
+test_77l() {
+ [ $PARALLEL == "yes" ] && skip "skip parallel run"
+ $GSS && skip_env "could not run with gss"
+
+ set_checksums 1
+ stack_trap "set_checksums $ORIG_CSUM" EXIT
+ stack_trap "set_checksum_type $ORIG_CSUM_TYPE" EXIT
+
+ set_checksum_type invalid && error "unexpected success of invalid checksum type"
+
+ $LFS setstripe -c 1 -i 0 $DIR/$tfile
+ for algo in $CKSUM_TYPES; do
+ set_checksum_type $algo || error "fail to set checksum type $algo"
+ osc_algo=$(get_osc_checksum_type OST0000)
+ [ "$osc_algo" != "$algo" ] && error "checksum type is $osc_algo after setting it to $algo"
+
+ # no locks, no reqs to let the connection idle
+ cancel_lru_locks osc
+ lru_resize_disable osc
+ wait_osc_import_state client ost1 IDLE
+
+ # ensure ost1 is connected
+ stat $DIR/$tfile >/dev/null || error "can't stat"
+ wait_osc_import_state client ost1 FULL
+
+ osc_algo=$(get_osc_checksum_type OST0000)
+ [ "$osc_algo" != "$algo" ] && error "checksum type changed from $algo to $osc_algo after reconnection"
+ done
+ return 0
+}
+run_test 77l "preferred checksum type is remembered after reconnected"
+
[ "$ORIG_CSUM" ] && set_checksums $ORIG_CSUM || true
rm -f $F77_TMP
unset F77_TMP