Commit 3d9cee91 authored by Federico Vaga's avatar Federico Vaga

add version control

parents ca75f9be 374ce826
......@@ -14,7 +14,11 @@ obj-m += drivers/
obj-m += buffers/
obj-m += triggers/
GIT_VERSION = $(shell cd $(src); git describe --dirty --long --tags)
# src is defined byt the kernel Makefile, but we want to use it also in our
# local Makefile (tools, lib)
src ?= $(shell pwd)
GIT_VERSION := $(shell cd $(src); git describe --dirty --long --tags)
# For this CSM_VERSION, please see ohwr.org/csm documentation
ifdef CONFIG_CSM_VERSION
......@@ -23,9 +27,15 @@ else
ccflags-y += -DCERN_SUPER_MODULE=""
endif
# Extract major, minor and patch number
ZIO_VERSION := -D__ZIO_MAJOR_VERSION=$(shell echo $(GIT_VERSION) | cut -d '-' -f 2 | cut -d '.' -f 1; )
ZIO_VERSION += -D__ZIO_MINOR_VERSION=$(shell echo $(GIT_VERSION) | cut -d '-' -f 2 | cut -d '.' -f 2; )
ZIO_VERSION += -D__ZIO_PATCH_VERSION=$(shell echo $(GIT_VERSION) | cut -d '-' -f 3)
export ZIO_VERSION
# WARNING: the line below doesn't work in-kernel if you compile with O=
ccflags-y += -I$(src)/include/ -DGIT_VERSION=\"$(GIT_VERSION)\"
ccflags-y += $(ZIO_VERSION)
ccflags-$(CONFIG_ZIO_DEBUG) += -DDEBUG
all: modules tools
......
......@@ -17,13 +17,49 @@
static struct zio_status *zstat = &zio_global_status; /* Always use ptr */
/**
* It verifies the compatibility between the current ZIO version and the
* given driver
*/
static int __zobj_version_check(struct zio_driver *drv)
{
uint32_t min = drv->min_version;
if (!min) {
pr_warn("zio: %s does not have a driver version, cannot verify compatibility",
drv->driver.name);
return 0;
}
if (min > zio_version)
goto out;
if (zio_version_major(min) != zio_version_major(zio_version))
goto out;
if (zio_version_minor(min) != zio_version_minor(zio_version))
goto out;
return 0;
out:
pr_err("zio: %s require version %d.%d-%d but ZIO is %d.%d-%d\n",
drv->driver.name,
zio_version_major(min), zio_version_minor(min),
zio_version_patch(min), zio_version_major(zio_version),
zio_version_minor(zio_version), zio_version_patch(zio_version));
return -1;
}
/*
* zio_show_version
* It shows the current version of ZIO
*/
static ssize_t zio_show_version(struct bus_type *bus, char *buf)
{
return sprintf(buf, "%d.%d\n", ZIO_MAJOR_VERSION, ZIO_MINOR_VERSION);
return sprintf(buf, "%d.%d-%d\n", zio_version_major(zio_version),
zio_version_minor(zio_version),
zio_version_patch(zio_version));
}
/*
......@@ -270,6 +306,14 @@ int zio_register_driver(struct zio_driver *zdrv)
{
int i, err;
/* Check version compatibility */
err = __zobj_version_check(zdrv);
if (err) {
pr_err("ZIO: Cannot register driver %s: incompatible version\n",
zdrv->driver.name);
return -EINVAL;
}
if (!zdrv->id_table) {
pr_err("ZIO: id_table is mandatory for a zio driver\n");
return -EINVAL;
......
......@@ -16,6 +16,9 @@
#include <linux/zio-buffer.h>
#include "zio-internal.h"
const uint32_t zio_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION);
struct zio_status zio_global_status;
static struct zio_status *zstat = &zio_global_status; /* Always use ptr */
/*
......@@ -31,8 +34,8 @@ struct zio_control *zio_alloc_control(gfp_t gfp)
if (!ctrl)
return NULL;
ctrl->major_version = ZIO_MAJOR_VERSION;
ctrl->minor_version = ZIO_MINOR_VERSION;
ctrl->major_version = zio_version_major(zio_version);
ctrl->minor_version = zio_version_minor(zio_version);
if (ntohl(1) == 1)
ctrl->flags |= ZIO_CONTROL_BIG_ENDIAN;
else
......
......@@ -10,6 +10,7 @@ else
endif
ccflags-y += -I$(src)/../include/ -DGIT_VERSION=\"$(GIT_VERSION)\"
ccflags-y += $(ZIO_VERSION)
ccflags-$(CONFIG_ZIO_DEBUG) += -DDEBUG
obj-m = zio-zero.o
......
......@@ -332,6 +332,11 @@ static struct zio_driver ad788x_zdrv = {
},
.id_table = ad788x_table,
.probe = ad788x_zio_probe,
/* All drivers compiled within the ZIO projects are compatibile
with the last version */
.min_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION),
};
static int ad788x_spi_probe(struct spi_device *spi)
......
......@@ -111,6 +111,11 @@ static struct zio_driver zdtc_zdrv = {
},
.id_table = zdtc_table,
.probe = zdtc_probe,
/* All drivers compiled within the ZIO projects are compatibile
with the last version */
.min_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION),
};
/* Lazily, use a single global device */
......
......@@ -122,6 +122,11 @@ static struct zio_driver zpg_zdrv = {
.owner = THIS_MODULE,
},
.id_table = zzero_table,
/* All drivers compiled within the ZIO projects are compatibile
with the last version */
.min_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION),
};
static int __init zgp_init(void)
......
......@@ -172,6 +172,11 @@ static struct zio_driver ztdc_zdrv = {
},
.id_table = ztdc_table,
.probe = ztdc_probe,
/* All drivers compiled within the ZIO projects are compatibile
with the last version */
.min_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION),
};
/* Lazily, use a single global device */
......
......@@ -274,6 +274,11 @@ static struct zio_driver zloop_zdrv = {
},
.id_table = zloop_table,
.probe = zloop_probe,
/* All drivers compiled within the ZIO projects are compatibile
with the last version */
.min_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION),
};
/*
......
......@@ -68,6 +68,11 @@ static struct zio_driver zmini_zdrv = {
.owner = THIS_MODULE,
},
.id_table = zmini_table,
/* All drivers compiled within the ZIO projects are compatibile
with the last version */
.min_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION),
};
/* The device is registered in the bus: we can have several */
......
......@@ -399,6 +399,11 @@ static struct zio_driver zvmk80xx_zdrv = {
.id_table = zvmk80xx_table,
.probe = zvmk80xx_zio_probe,
.remove = zvmk80xx_zio_remove,
/* All drivers compiled within the ZIO projects are compatibile
with the last version */
.min_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION),
};
......
......@@ -208,6 +208,11 @@ static struct zio_driver zzero_zdrv = {
.owner = THIS_MODULE,
},
.id_table = zzero_table,
/* All drivers compiled within the ZIO projects are compatibile
with the last version */
.min_version = ZIO_VERSION(__ZIO_MAJOR_VERSION,
__ZIO_MINOR_VERSION,
__ZIO_PATCH_VERSION),
};
static int __init zzero_init(void)
......
......@@ -8,9 +8,24 @@
#ifndef __ZIO_USER_H__
#define __ZIO_USER_H__
/* ZIO_VERSION: is a zio_class attribute to identify the framework version*/
#define ZIO_MAJOR_VERSION 1
#define ZIO_MINOR_VERSION 0
#define ZIO_VERSION(M, m, p) (((M & 0xFF) << 24) | ((m & 0xFF) << 16) | (p & 0xFFFF))
static inline uint8_t zio_version_major(uint32_t version)
{
return (version >> 24) & 0xFF;
}
static inline uint8_t zio_version_minor(uint32_t version)
{
return (version >> 16) & 0xFF;
}
static inline uint16_t zio_version_patch(uint32_t version)
{
return version & 0xFF;
}
/*
* ZIO_OBJ_NAME_LEN is the name's length used for registered objects
......
......@@ -7,6 +7,8 @@
#ifdef __KERNEL__ /* Nothing more is for user space */
extern const uint32_t zio_version;
/*
* ZIO_NAME_LEN is the full name length used in the head structures.
* It is sometimes built at run time, for example buffer instances
......@@ -124,6 +126,7 @@ struct zio_driver {
int (*probe)(struct zio_device *dev);
int (*remove)(struct zio_device *dev);
struct device_driver driver;
uint32_t min_version; /**< minimum version required to load it */
};
#define to_zio_drv(_drv) container_of(_drv, struct zio_driver, driver)
extern struct bus_type zio_bus_type;
......
# build user-space tools for zio
CFLAGS = -I$(M)/include/ -Wall $(EXTRACFLAGS)
CFLAGS = -I$(M)/include/ -Wall $(ZIO_VERSION) $(EXTRACFLAGS)
CC ?= $(CROSS_COMPILE)gcc
progs := zio-dump
......
......@@ -129,8 +129,8 @@ int main(int argc, char **argv)
exit(1);
}
ctrl.major_version = ZIO_MAJOR_VERSION;
ctrl.minor_version = ZIO_MINOR_VERSION;
ctrl.major_version = __ZIO_MAJOR_VERSION;
ctrl.minor_version = __ZIO_MINOR_VERSION;
if (verbose) {
printf(" time: %9li.%09li\n", ts.tv_sec, ts.tv_nsec);
printf("period: %9li.%09li\n", period.tv_sec, period.tv_nsec);
......
......@@ -90,8 +90,8 @@ int main(int argc, char **argv)
if (i != sizeof(ctrl))
goto ctrl_read_error;
if (!j) {
if (ctrl.major_version != ZIO_MAJOR_VERSION
|| ctrl.minor_version != ZIO_MINOR_VERSION) {
if (ctrl.major_version != __ZIO_MAJOR_VERSION
|| ctrl.minor_version != __ZIO_MINOR_VERSION) {
fprintf(stderr, "%s: unexpected ZIO version\n",
argv[0]);
exit(1);
......
......@@ -112,18 +112,18 @@ void read_channel(int cfd, int dfd, FILE *log)
}
/* Fail badly if the version is not the right one */
if (ctrl.major_version != ZIO_MAJOR_VERSION)
if (ctrl.major_version != __ZIO_MAJOR_VERSION)
err++;
if (ZIO_MAJOR_VERSION == 0 && ctrl.minor_version != ZIO_MINOR_VERSION)
if (__ZIO_MAJOR_VERSION == 0 && ctrl.minor_version != __ZIO_MINOR_VERSION)
err++;
if (err) {
fprintf(stderr, "%s: kernel has zio %i.%i, "
"but I'm compiled for %i.%i\n", prgname,
ctrl.major_version, ctrl.minor_version,
ZIO_MAJOR_VERSION, ZIO_MINOR_VERSION);
__ZIO_MAJOR_VERSION, __ZIO_MINOR_VERSION);
exit(1);
}
if (ctrl.minor_version != ZIO_MINOR_VERSION) {
if (ctrl.minor_version != __ZIO_MINOR_VERSION) {
static int warned;
if (!warned++)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment