[ENBD] md5sum switch

Peter T. Breuer ptb at it.uc3m.es
Fri Jan 9 07:42:18 MST 2004


"Also sprach Peter T. Breuer:"
> Oh ... the ioctl is:
> 
>       case ENBD_SET_MD5SUM:     /* PTB - change to do/plead md5summing */
>         ENBD_DEBUG (3, "ENBD_SET_MD5SUM %ld\n", arg);
>         if (arg) {
>             atomic_set_mask (ENBD_MD5SUM, &lo->flags);
>         }
>         else {
>             atomic_clear_mask (ENBD_MD5SUM, &lo->flags);
>         }
>         return 0;
> 
> and I suppose one could make that fancier. If the argument is > 4096
> one could assume it is the address of a struct that contains two
> integers, the on and off thresholds. Ecch ... modal. Umm. Any better
> idea?

Perhaps ... if the argument is even (terminates in 0 mod 2), then
we want to switch OFF md5summing, and clear the flag and set the on
threshold to arg/2.  A negative value means never switch on, thus
"-2" as an argument switches off md5summing forever.

If the argument is odd (terminates in 1 mod 2), then we want to switch
ON md5summing, and set the flag and set the off threshold to (arg-1)/2.
A negative value means never switch off, so "-1" as argument
switches on md5summing forever.

      case ENBD_SET_MD5SUM:     /* PTB - change to do/plead md5summing */
        ENBD_DEBUG (3, "ENBD_SET_MD5SUM %ld\n", arg);
        if (arg & 1) {
            // PTB odd. switch on md5sum and possibly raise off_threshold
            atomic_set_mask (ENBD_MD5SUM, &lo->flags);
            if (arg != 1) {
                md5_off_threshold = (long)arg >> 1;
            }
        }
        else {
            // PTB even. switch off md5sum and possibly raise on_threshold
            atomic_clear_mask (ENBD_MD5SUM, &lo->flags);
            if (arg != 0) {
                md5_on_threshold = (long)arg >> 1;
            }
        }

Which has the merit of not mixing addresses and values. And the obvious
demerits.

Peter



More information about the ENBD mailing list