aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/lustre/lustre/obdclass
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging/lustre/lustre/obdclass')
-rw-r--r--drivers/staging/lustre/lustre/obdclass/Makefile15
-rw-r--r--drivers/staging/lustre/lustre/obdclass/acl.c27
-rw-r--r--drivers/staging/lustre/lustre/obdclass/capa.c23
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_io.c11
-rw-r--r--drivers/staging/lustre/lustre/obdclass/cl_lock.c2
-rw-r--r--drivers/staging/lustre/lustre/obdclass/class_obd.c133
-rw-r--r--drivers/staging/lustre/lustre/obdclass/debug.c1
-rw-r--r--drivers/staging/lustre/lustre/obdclass/dt_object.c56
-rw-r--r--drivers/staging/lustre/lustre/obdclass/genops.c49
-rw-r--r--drivers/staging/lustre/lustre/obdclass/idmap.c477
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linkea.c194
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-module.c10
-rw-r--r--drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c8
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog.c89
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_cat.c20
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_ioctl.c418
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_lvfs.c847
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_obd.c25
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_osd.c1290
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_swab.c52
-rw-r--r--drivers/staging/lustre/lustre/obdclass/llog_test.c1072
-rw-r--r--drivers/staging/lustre/lustre/obdclass/local_storage.c894
-rw-r--r--drivers/staging/lustre/lustre/obdclass/local_storage.h91
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lprocfs_counters.c139
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lprocfs_status.c147
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lu_ucred.c107
-rw-r--r--drivers/staging/lustre/lustre/obdclass/lustre_handles.c2
-rw-r--r--drivers/staging/lustre/lustre/obdclass/md_attrs.c199
-rw-r--r--drivers/staging/lustre/lustre/obdclass/mea.c112
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_config.c144
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obd_mount.c64
-rw-r--r--drivers/staging/lustre/lustre/obdclass/obdo.c78
-rw-r--r--drivers/staging/lustre/lustre/obdclass/statfs_pack.c2
33 files changed, 705 insertions, 6093 deletions
diff --git a/drivers/staging/lustre/lustre/obdclass/Makefile b/drivers/staging/lustre/lustre/obdclass/Makefile
index ba10043fdd50..e894681797c2 100644
--- a/drivers/staging/lustre/lustre/obdclass/Makefile
+++ b/drivers/staging/lustre/lustre/obdclass/Makefile
@@ -1,10 +1,11 @@
-obj-$(CONFIG_LUSTRE_FS) += obdclass.o llog_test.o
+obj-$(CONFIG_LUSTRE_FS) += obdclass.o
obdclass-y := linux/linux-module.o linux/linux-obdo.o linux/linux-sysctl.o \
llog.o llog_cat.o llog_obd.o llog_swab.o class_obd.o debug.o \
- genops.o uuid.o llog_ioctl.o lprocfs_status.o \
- lustre_handles.o lustre_peer.o llog_osd.o \
- local_storage.o statfs_pack.o obdo.o obd_config.o obd_mount.o\
- mea.o lu_object.o dt_object.o capa.o cl_object.o \
- cl_page.o cl_lock.o cl_io.o lu_ref.o acl.o idmap.o \
- lu_ucred.o
+ genops.o uuid.o lprocfs_status.o \
+ lustre_handles.o lustre_peer.o \
+ statfs_pack.o obdo.o obd_config.o obd_mount.o \
+ lu_object.o dt_object.o capa.o cl_object.o \
+ cl_page.o cl_lock.o cl_io.o lu_ref.o acl.o
+
+obdclass-$(CONFIG_PROC_FS) += lprocfs_counters.o
diff --git a/drivers/staging/lustre/lustre/obdclass/acl.c b/drivers/staging/lustre/lustre/obdclass/acl.c
index 3b394a0bff9d..2619bfeceb8b 100644
--- a/drivers/staging/lustre/lustre/obdclass/acl.c
+++ b/drivers/staging/lustre/lustre/obdclass/acl.c
@@ -196,8 +196,10 @@ int lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, int size,
case ACL_GROUP_OBJ:
case ACL_MASK:
case ACL_OTHER:
- if (id != ACL_UNDEFINED_ID)
- GOTO(_out, rc = -EIO);
+ if (id != ACL_UNDEFINED_ID) {
+ rc = -EIO;
+ goto _out;
+ }
memcpy(&new->a_entries[j++], &header->a_entries[i],
sizeof(posix_acl_xattr_entry));
@@ -215,7 +217,8 @@ int lustre_posix_acl_xattr_filter(posix_acl_xattr_header *header, int size,
sizeof(posix_acl_xattr_entry));
break;
default:
- GOTO(_out, rc = -EIO);
+ rc = -EIO;
+ goto _out;
}
}
@@ -318,8 +321,10 @@ int lustre_acl_xattr_merge2posix(posix_acl_xattr_header *posix_header, int size,
case ACL_USER_OBJ:
case ACL_GROUP_OBJ:
case ACL_OTHER:
- if (ae.e_id != ACL_UNDEFINED_ID)
- GOTO(_out, rc = -EIO);
+ if (ae.e_id != ACL_UNDEFINED_ID) {
+ rc = -EIO;
+ goto _out;
+ }
if (ae.e_stat != ES_DEL) {
new->a_entries[j].e_tag =
@@ -336,7 +341,8 @@ int lustre_acl_xattr_merge2posix(posix_acl_xattr_header *posix_header, int size,
if (ae.e_stat == ES_DEL)
break;
default:
- GOTO(_out, rc = -EIO);
+ rc = -EIO;
+ goto _out;
}
}
} else {
@@ -437,8 +443,10 @@ lustre_acl_xattr_merge2ext(posix_acl_xattr_header *posix_header, int size,
case ACL_GROUP_OBJ:
case ACL_MASK:
case ACL_OTHER:
- if (pae.e_id != ACL_UNDEFINED_ID)
- GOTO(out, rc = -EIO);
+ if (pae.e_id != ACL_UNDEFINED_ID) {
+ rc = -EIO;
+ goto out;
+ }
case ACL_USER:
/* ignore "nobody" entry. */
if (pae.e_id == NOBODY_UID)
@@ -501,7 +509,8 @@ lustre_acl_xattr_merge2ext(posix_acl_xattr_header *posix_header, int size,
}
break;
default:
- GOTO(out, rc = -EIO);
+ rc = -EIO;
+ goto out;
}
}
diff --git a/drivers/staging/lustre/lustre/obdclass/capa.c b/drivers/staging/lustre/lustre/obdclass/capa.c
index 5af61a8c0b85..cd1abce378ea 100644
--- a/drivers/staging/lustre/lustre/obdclass/capa.c
+++ b/drivers/staging/lustre/lustre/obdclass/capa.c
@@ -213,12 +213,11 @@ struct obd_capa *capa_add(struct hlist_head *hash, struct lustre_capa *capa)
capa_delete_lru(list);
spin_unlock(&capa_lock);
return ocapa;
- } else {
- capa_get(old);
- spin_unlock(&capa_lock);
- capa_put(ocapa);
- return old;
}
+ capa_get(old);
+ spin_unlock(&capa_lock);
+ capa_put(ocapa);
+ return old;
}
EXPORT_SYMBOL(capa_add);
@@ -312,13 +311,14 @@ int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
min = ll_crypto_tfm_alg_min_keysize(tfm);
if (keylen < min) {
CERROR("keylen at least %d bits for aes\n", min * 8);
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
}
rc = crypto_blkcipher_setkey(tfm, key, min);
if (rc) {
CERROR("failed to setting key for aes\n");
- GOTO(out, rc);
+ goto out;
}
sg_init_table(&sd, 1);
@@ -334,7 +334,7 @@ int capa_encrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
rc = crypto_blkcipher_encrypt(&desc, &sd, &ss, 16);
if (rc) {
CERROR("failed to encrypt for aes\n");
- GOTO(out, rc);
+ goto out;
}
out:
@@ -364,13 +364,14 @@ int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
min = ll_crypto_tfm_alg_min_keysize(tfm);
if (keylen < min) {
CERROR("keylen at least %d bits for aes\n", min * 8);
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
}
rc = crypto_blkcipher_setkey(tfm, key, min);
if (rc) {
CERROR("failed to setting key for aes\n");
- GOTO(out, rc);
+ goto out;
}
sg_init_table(&sd, 1);
@@ -387,7 +388,7 @@ int capa_decrypt_id(__u32 *d, __u32 *s, __u8 *key, int keylen)
rc = crypto_blkcipher_decrypt(&desc, &sd, &ss, 16);
if (rc) {
CERROR("failed to decrypt for aes\n");
- GOTO(out, rc);
+ goto out;
}
out:
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_io.c b/drivers/staging/lustre/lustre/obdclass/cl_io.c
index 6870ee823736..f2383a497cbe 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_io.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_io.c
@@ -126,7 +126,7 @@ void cl_io_fini(const struct lu_env *env, struct cl_io *io)
info->clt_current_io = NULL;
/* sanity check for layout change */
- switch(io->ci_type) {
+ switch (io->ci_type) {
case CIT_READ:
case CIT_WRITE:
break;
@@ -1452,12 +1452,13 @@ struct cl_req *cl_req_alloc(const struct lu_env *env, struct cl_page *page,
if (req != NULL) {
int result;
+ req->crq_type = crt;
+ INIT_LIST_HEAD(&req->crq_pages);
+ INIT_LIST_HEAD(&req->crq_layers);
+
OBD_ALLOC(req->crq_o, nr_objects * sizeof(req->crq_o[0]));
if (req->crq_o != NULL) {
req->crq_nrobjs = nr_objects;
- req->crq_type = crt;
- INIT_LIST_HEAD(&req->crq_pages);
- INIT_LIST_HEAD(&req->crq_layers);
result = cl_req_init(env, req, page);
} else
result = -ENOMEM;
@@ -1559,7 +1560,7 @@ EXPORT_SYMBOL(cl_req_prep);
* for the same request.
*/
void cl_req_attr_set(const struct lu_env *env, struct cl_req *req,
- struct cl_req_attr *attr, obd_valid flags)
+ struct cl_req_attr *attr, u64 flags)
{
const struct cl_req_slice *slice;
struct cl_page *page;
diff --git a/drivers/staging/lustre/lustre/obdclass/cl_lock.c b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
index 7d99319b714e..b204531ef710 100644
--- a/drivers/staging/lustre/lustre/obdclass/cl_lock.c
+++ b/drivers/staging/lustre/lustre/obdclass/cl_lock.c
@@ -1938,7 +1938,7 @@ int cl_lock_discard_pages(const struct lu_env *env, struct cl_lock *lock)
io->ci_ignore_layout = 1;
result = cl_io_init(env, io, CIT_MISC, io->ci_obj);
if (result != 0)
- GOTO(out, result);
+ goto out;
cb = descr->cld_mode == CLM_READ ? check_and_discard_cb : discard_cb;
info->clt_fn_index = info->clt_next_index = descr->cld_start;
diff --git a/drivers/staging/lustre/lustre/obdclass/class_obd.c b/drivers/staging/lustre/lustre/obdclass/class_obd.c
index 8b19f3caa68f..7265ecbc6f9d 100644
--- a/drivers/staging/lustre/lustre/obdclass/class_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/class_obd.c
@@ -35,7 +35,7 @@
*/
#define DEBUG_SUBSYSTEM S_CLASS
-# include <asm/atomic.h>
+# include <linux/atomic.h>
#include "../include/obd_support.h"
#include "../include/obd_class.h"
@@ -177,18 +177,21 @@ int class_resolve_dev_name(__u32 len, const char *name)
if (!len || !name) {
CERROR("No name passed,!\n");
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
}
if (name[len - 1] != 0) {
CERROR("Name not nul terminated!\n");
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
}
CDEBUG(D_IOCTL, "device name %s\n", name);
dev = class_name2dev(name);
if (dev == -1) {
CDEBUG(D_IOCTL, "No device for name %s!\n", name);
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
}
CDEBUG(D_IOCTL, "device name %s, dev %d\n", name, dev);
@@ -208,7 +211,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
/* only for debugging */
if (cmd == LIBCFS_IOC_DEBUG_MASK) {
- debug_data = (struct libcfs_debug_ioctl_data*)arg;
+ debug_data = (struct libcfs_debug_ioctl_data *)arg;
libcfs_subsystem_debug = debug_data->subs;
libcfs_debug = debug_data->debug;
return 0;
@@ -227,11 +230,14 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
if (!data->ioc_plen1 || !data->ioc_pbuf1) {
CERROR("No config buffer passed!\n");
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
OBD_ALLOC(lcfg, data->ioc_plen1);
- if (lcfg == NULL)
- GOTO(out, err = -ENOMEM);
+ if (lcfg == NULL) {
+ err = -ENOMEM;
+ goto out;
+ }
err = copy_from_user(lcfg, data->ioc_pbuf1,
data->ioc_plen1);
if (!err)
@@ -240,18 +246,20 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
err = class_process_config(lcfg);
OBD_FREE(lcfg, data->ioc_plen1);
- GOTO(out, err);
+ goto out;
}
case OBD_GET_VERSION:
if (!data->ioc_inlbuf1) {
CERROR("No buffer passed in ioctl\n");
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
if (strlen(BUILD_VERSION) + 1 > data->ioc_inllen1) {
CERROR("ioctl buffer too small to hold version\n");
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
memcpy(data->ioc_bulk, BUILD_VERSION,
@@ -260,7 +268,7 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
err = obd_ioctl_popdata((void *)arg, data, len);
if (err)
err = -EFAULT;
- GOTO(out, err);
+ goto out;
case OBD_IOC_NAME2DEV: {
/* Resolve a device name. This does not change the
@@ -271,13 +279,15 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
dev = class_resolve_dev_name(data->ioc_inllen1,
data->ioc_inlbuf1);
data->ioc_dev = dev;
- if (dev < 0)
- GOTO(out, err = -EINVAL);
+ if (dev < 0) {
+ err = -EINVAL;
+ goto out;
+ }
err = obd_ioctl_popdata((void *)arg, data, sizeof(*data));
if (err)
err = -EFAULT;
- GOTO(out, err);
+ goto out;
}
case OBD_IOC_UUID2DEV: {
@@ -289,11 +299,13 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
if (!data->ioc_inllen1 || !data->ioc_inlbuf1) {
CERROR("No UUID passed!\n");
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
if (data->ioc_inlbuf1[data->ioc_inllen1 - 1] != 0) {
CERROR("UUID not NUL terminated!\n");
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
CDEBUG(D_IOCTL, "device name %s\n", data->ioc_inlbuf1);
@@ -303,7 +315,8 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
if (dev == -1) {
CDEBUG(D_IOCTL, "No device for UUID %s!\n",
data->ioc_inlbuf1);
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
CDEBUG(D_IOCTL, "device name %s, dev %d\n", data->ioc_inlbuf1,
@@ -311,13 +324,14 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
err = obd_ioctl_popdata((void *)arg, data, sizeof(*data));
if (err)
err = -EFAULT;
- GOTO(out, err);
+ goto out;
}
case OBD_IOC_CLOSE_UUID: {
CDEBUG(D_IOCTL, "closing all connections to uuid %s (NOOP)\n",
data->ioc_inlbuf1);
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case OBD_IOC_GETDEVICE: {
@@ -326,16 +340,20 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
if (!data->ioc_inlbuf1) {
CERROR("No buffer passed in ioctl\n");
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
if (data->ioc_inllen1 < 128) {
CERROR("ioctl buffer too small to hold version\n");
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
obd = class_num2obd(index);
- if (!obd)
- GOTO(out, err = -ENOENT);
+ if (!obd) {
+ err = -ENOENT;
+ goto out;
+ }
if (obd->obd_stopping)
status = "ST";
@@ -352,56 +370,66 @@ int class_handle_ioctl(unsigned int cmd, unsigned long arg)
atomic_read(&obd->obd_refcount));
err = obd_ioctl_popdata((void *)arg, data, len);
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
}
if (data->ioc_dev == OBD_DEV_BY_DEVNAME) {
- if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL)
- GOTO(out, err = -EINVAL);
- if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME)
- GOTO(out, err = -EINVAL);
+ if (data->ioc_inllen4 <= 0 || data->ioc_inlbuf4 == NULL) {
+ err = -EINVAL;
+ goto out;
+ }
+ if (strnlen(data->ioc_inlbuf4, MAX_OBD_NAME) >= MAX_OBD_NAME) {
+ err = -EINVAL;
+ goto out;
+ }
obd = class_name2obd(data->ioc_inlbuf4);
} else if (data->ioc_dev < class_devno_max()) {
obd = class_num2obd(data->ioc_dev);
} else {
CERROR("OBD ioctl: No device\n");
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
if (obd == NULL) {
CERROR("OBD ioctl : No Device %d\n", data->ioc_dev);
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
LASSERT(obd->obd_magic == OBD_DEVICE_MAGIC);
if (!obd->obd_set_up || obd->obd_stopping) {
- CERROR("OBD ioctl: device not setup %d \n", data->ioc_dev);
- GOTO(out, err = -EINVAL);
+ CERROR("OBD ioctl: device not setup %d\n", data->ioc_dev);
+ err = -EINVAL;
+ goto out;
}
- switch(cmd) {
+ switch (cmd) {
case OBD_IOC_NO_TRANSNO: {
if (!obd->obd_attached) {
CERROR("Device %d not attached\n", obd->obd_minor);
- GOTO(out, err = -ENODEV);
+ err = -ENODEV;
+ goto out;
}
CDEBUG(D_HA, "%s: disabling committed-transno notification\n",
obd->obd_name);
obd->obd_no_transno = 1;
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
default: {
err = obd_iocontrol(cmd, obd->obd_self_export, len, data, NULL);
if (err)
- GOTO(out, err);
+ goto out;
err = obd_ioctl_popdata((void *)arg, data, len);
if (err)
err = -EFAULT;
- GOTO(out, err);
+ goto out;
}
}
@@ -506,20 +534,23 @@ static int __init init_obdclass(void)
spin_lock_init(&obd_types_lock);
obd_zombie_impexp_init();
- obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
- LPROCFS_STATS_FLAG_NONE |
- LPROCFS_STATS_FLAG_IRQ_SAFE);
- if (obd_memory == NULL) {
- CERROR("kmalloc of 'obd_memory' failed\n");
- return -ENOMEM;
- }
+ if (IS_ENABLED(CONFIG_PROC_FS)) {
+ obd_memory = lprocfs_alloc_stats(OBD_STATS_NUM,
+ LPROCFS_STATS_FLAG_NONE |
+ LPROCFS_STATS_FLAG_IRQ_SAFE);
- lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
- LPROCFS_CNTR_AVGMINMAX,
- "memused", "bytes");
- lprocfs_counter_init(obd_memory, OBD_MEMORY_PAGES_STAT,
- LPROCFS_CNTR_AVGMINMAX,
- "pagesused", "pages");
+ if (obd_memory == NULL) {
+ CERROR("kmalloc of 'obd_memory' failed\n");
+ return -ENOMEM;
+ }
+
+ lprocfs_counter_init(obd_memory, OBD_MEMORY_STAT,
+ LPROCFS_CNTR_AVGMINMAX,
+ "memused", "bytes");
+ lprocfs_counter_init(obd_memory, OBD_MEMORY_PAGES_STAT,
+ LPROCFS_CNTR_AVGMINMAX,
+ "pagesused", "pages");
+ }
err = obd_init_checks();
if (err == -EOVERFLOW)
diff --git a/drivers/staging/lustre/lustre/obdclass/debug.c b/drivers/staging/lustre/lustre/obdclass/debug.c
index e8aa42beb3c7..d0f8f875ddd6 100644
--- a/drivers/staging/lustre/lustre/obdclass/debug.c
+++ b/drivers/staging/lustre/lustre/obdclass/debug.c
@@ -41,7 +41,6 @@
#define DEBUG_SUBSYSTEM D_OTHER
-#include "../include/obd_ost.h"
#include "../include/obd_support.h"
#include "../include/lustre_debug.h"
#include "../include/lustre_net.h"
diff --git a/drivers/staging/lustre/lustre/obdclass/dt_object.c b/drivers/staging/lustre/lustre/obdclass/dt_object.c
index 130b8dd0b418..52256c26bf07 100644
--- a/drivers/staging/lustre/lustre/obdclass/dt_object.c
+++ b/drivers/staging/lustre/lustre/obdclass/dt_object.c
@@ -384,26 +384,30 @@ struct dt_object *dt_find_or_create(const struct lu_env *env,
return dto;
th = dt_trans_create(env, dt);
- if (IS_ERR(th))
- GOTO(out, rc = PTR_ERR(th));
+ if (IS_ERR(th)) {
+ rc = PTR_ERR(th);
+ goto out;
+ }
rc = dt_declare_create(env, dto, at, NULL, dof, th);
if (rc)
- GOTO(trans_stop, rc);
+ goto trans_stop;
rc = dt_trans_start_local(env, dt, th);
if (rc)
- GOTO(trans_stop, rc);
+ goto trans_stop;
dt_write_lock(env, dto, 0);
- if (dt_object_exists(dto))
- GOTO(unlock, rc = 0);
+ if (dt_object_exists(dto)) {
+ rc = 0;
+ goto unlock;
+ }
CDEBUG(D_OTHER, "create new object "DFID"\n", PFID(fid));
rc = dt_create(env, dto, at, NULL, dof, th);
if (rc)
- GOTO(unlock, rc);
+ goto unlock;
LASSERT(dt_object_exists(dto));
unlock:
dt_write_unlock(env, dto);
@@ -683,14 +687,18 @@ static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
ii->ii_hash_end = hash;
if (OBD_FAIL_CHECK(OBD_FAIL_OBD_IDX_READ_BREAK)) {
- if (lip->lip_nr != 0)
- GOTO(out, rc = 0);
+ if (lip->lip_nr != 0) {
+ rc = 0;
+ goto out;
+ }
}
if (nob < size) {
if (lip->lip_nr == 0)
- GOTO(out, rc = -EINVAL);
- GOTO(out, rc = 0);
+ rc = -EINVAL;
+ else
+ rc = 0;
+ goto out;
}
if ((ii->ii_flags & II_FL_NOHASH) == 0) {
@@ -710,7 +718,7 @@ static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
rc = iops->rec(env, it, (struct dt_rec *)tmp_entry, attr);
if (rc != -ESTALE) {
if (rc != 0)
- GOTO(out, rc);
+ goto out;
/* hash/key/record successfully copied! */
lip->lip_nr++;
@@ -727,7 +735,7 @@ static int dt_index_page_build(const struct lu_env *env, union lu_page *lp,
} while (rc == 0);
- GOTO(out, rc);
+ goto out;
out:
if (rc >= 0 && lip->lip_nr > 0)
/* one more container */
@@ -869,20 +877,24 @@ int dt_index_read(const struct lu_env *env, struct dt_device *dev,
obj = dt_locate(env, dev, &ii->ii_fid);
if (IS_ERR(obj))
return PTR_ERR(obj);
- if (dt_object_exists(obj) == 0)
- GOTO(out, rc = -ENOENT);
+ if (dt_object_exists(obj) == 0) {
+ rc = -ENOENT;
+ goto out;
+ }
/* fetch index features associated with index object */
feat = dt_index_feat_select(fid_seq(&ii->ii_fid),
lu_object_attr(&obj->do_lu));
- if (IS_ERR(feat))
- GOTO(out, rc = PTR_ERR(feat));
+ if (IS_ERR(feat)) {
+ rc = PTR_ERR(feat);
+ goto out;
+ }
/* load index feature if not done already */
if (obj->do_index_ops == NULL) {
rc = obj->do_ops->do_index_try(env, obj, feat);
if (rc)
- GOTO(out, rc);
+ goto out;
}
/* fill ii_flags with supported index features */
@@ -893,7 +905,8 @@ int dt_index_read(const struct lu_env *env, struct dt_device *dev,
/* key size is variable */
ii->ii_flags |= II_FL_VARKEY;
/* we don't support variable key size for the time being */
- GOTO(out, rc = -EOPNOTSUPP);
+ rc = -EOPNOTSUPP;
+ goto out;
}
ii->ii_recsize = feat->dif_recsize_max;
@@ -901,7 +914,8 @@ int dt_index_read(const struct lu_env *env, struct dt_device *dev,
/* record size is variable */
ii->ii_flags |= II_FL_VARREC;
/* we don't support variable record size for the time being */
- GOTO(out, rc = -EOPNOTSUPP);
+ rc = -EOPNOTSUPP;
+ goto out;
}
if ((feat->dif_flags & DT_IND_NONUNQ) != 0)
@@ -922,7 +936,7 @@ int dt_index_read(const struct lu_env *env, struct dt_device *dev,
ii->ii_hash_end = II_END_OFF;
}
- GOTO(out, rc);
+ goto out;
out:
lu_object_put(env, &obj->do_lu);
return rc;
diff --git a/drivers/staging/lustre/lustre/obdclass/genops.c b/drivers/staging/lustre/lustre/obdclass/genops.c
index 504c59aabaef..c314e9c2343e 100644
--- a/drivers/staging/lustre/lustre/obdclass/genops.c
+++ b/drivers/staging/lustre/lustre/obdclass/genops.c
@@ -40,7 +40,6 @@
*/
#define DEBUG_SUBSYSTEM S_CLASS
-#include "../include/obd_ost.h"
#include "../include/obd_class.h"
#include "../include/lprocfs_status.h"
@@ -184,7 +183,7 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
if (type->typ_dt_ops == NULL ||
type->typ_md_ops == NULL ||
type->typ_name == NULL)
- GOTO (failed, rc);
+ goto failed;
*(type->typ_dt_ops) = *dt_ops;
/* md_ops is optional */
@@ -198,14 +197,14 @@ int class_register_type(struct obd_ops *dt_ops, struct md_ops *md_ops,
if (IS_ERR(type->typ_procroot)) {
rc = PTR_ERR(type->typ_procroot);
type->typ_procroot = NULL;
- GOTO (failed, rc);
+ goto failed;
}
if (ldt != NULL) {
type->typ_lu = ldt;
rc = lu_device_type_init(ldt);
if (rc != 0)
- GOTO (failed, rc);
+ goto failed;
}
spin_lock(&obd_types_lock);
@@ -295,8 +294,10 @@ struct obd_device *class_newdev(const char *type_name, const char *name)
}
newdev = obd_device_alloc();
- if (newdev == NULL)
- GOTO(out_type, result = ERR_PTR(-ENOMEM));
+ if (newdev == NULL) {
+ result = ERR_PTR(-ENOMEM);
+ goto out_type;
+ }
LASSERT(newdev->obd_magic == OBD_DEVICE_MAGIC);
@@ -336,11 +337,12 @@ struct obd_device *class_newdev(const char *type_name, const char *name)
if (result == NULL && i >= class_devno_max()) {
CERROR("all %u OBD devices used, increase MAX_OBD_DEVICES\n",
class_devno_max());
- GOTO(out, result = ERR_PTR(-EOVERFLOW));
+ result = ERR_PTR(-EOVERFLOW);
+ goto out;
}
if (IS_ERR(result))
- GOTO(out, result);
+ goto out;
CDEBUG(D_IOCTL, "Adding new device %s (%p)\n",
result->obd_name, result);
@@ -656,26 +658,26 @@ int obd_init_caches(void)
sizeof(struct obd_device),
0, 0, NULL);
if (!obd_device_cachep)
- GOTO(out, -ENOMEM);
+ goto out;
LASSERT(obdo_cachep == NULL);
obdo_cachep = kmem_cache_create("ll_obdo_cache", sizeof(struct obdo),
0, 0, NULL);
if (!obdo_cachep)
- GOTO(out, -ENOMEM);
+ goto out;
LASSERT(import_cachep == NULL);
import_cachep = kmem_cache_create("ll_import_cache",
sizeof(struct obd_import),
0, 0, NULL);
if (!import_cachep)
- GOTO(out, -ENOMEM);
+ goto out;
LASSERT(capa_cachep == NULL);
capa_cachep = kmem_cache_create("capa_cache",
sizeof(struct obd_capa), 0, 0, NULL);
if (!capa_cachep)
- GOTO(out, -ENOMEM);
+ goto out;
return 0;
out:
@@ -857,12 +859,16 @@ struct obd_export *class_new_export(struct obd_device *obd,
spin_lock(&obd->obd_dev_lock);
/* shouldn't happen, but might race */
- if (obd->obd_stopping)
- GOTO(exit_unlock, rc = -ENODEV);
+ if (obd->obd_stopping) {
+ rc = -ENODEV;
+ goto exit_unlock;
+ }
hash = cfs_hash_getref(obd->obd_uuid_hash);
- if (hash == NULL)
- GOTO(exit_unlock, rc = -ENODEV);
+ if (hash == NULL) {
+ rc = -ENODEV;
+ goto exit_unlock;
+ }
spin_unlock(&obd->obd_dev_lock);
if (!obd_uuid_equals(cluuid, &obd->obd_uuid)) {
@@ -870,14 +876,16 @@ struct obd_export *class_new_export(struct obd_device *obd,
if (rc != 0) {
LCONSOLE_WARN("%s: denying duplicate export for %s, %d\n",
obd->obd_name, cluuid->uuid, rc);
- GOTO(exit_err, rc = -EALREADY);
+ rc = -EALREADY;
+ goto exit_err;
}
}
spin_lock(&obd->obd_dev_lock);
if (obd->obd_stopping) {
cfs_hash_del(hash, cluuid, &export->exp_uuid_hash);
- GOTO(exit_unlock, rc = -ENODEV);
+ rc = -ENODEV;
+ goto exit_unlock;
}
class_incref(obd, "export", export);
@@ -1187,7 +1195,7 @@ int class_disconnect(struct obd_export *export)
* call extra class_export_puts(). */
if (already_disconnected) {
LASSERT(hlist_unhashed(&export->exp_nid_hash));
- GOTO(no_disconn, already_disconnected);
+ goto no_disconn;
}
CDEBUG(D_IOCTL, "disconnect: cookie %#llx\n",
@@ -1425,7 +1433,8 @@ int obd_export_evict_by_nid(struct obd_device *obd, const char *nid)
cfs_hash_putref(nid_hash);
if (!exports_evicted)
- CDEBUG(D_HA,"%s: can't disconnect NID '%s': no exports found\n",
+ CDEBUG(D_HA,
+ "%s: can't disconnect NID '%s': no exports found\n",
obd->obd_name, nid);
return exports_evicted;
}
diff --git a/drivers/staging/lustre/lustre/obdclass/idmap.c b/drivers/staging/lustre/lustre/obdclass/idmap.c
deleted file mode 100644
index 1190885c06b6..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/idmap.c
+++ /dev/null
@@ -1,477 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/obdclass/idmap.c
- *
- * Lustre user identity mapping.
- *
- * Author: Fan Yong <fanyong@clusterfs.com>
- */
-
-#define DEBUG_SUBSYSTEM S_SEC
-
-#include "../include/lustre_idmap.h"
-#include "../include/md_object.h"
-#include "../include/obd_support.h"
-
-#define lustre_get_group_info(group_info) do { \
- atomic_inc(&(group_info)->usage); \
-} while (0)
-
-#define lustre_put_group_info(group_info) do { \
- if (atomic_dec_and_test(&(group_info)->usage)) \
- groups_free(group_info); \
-} while (0)
-
-/*
- * groups_search() is copied from linux kernel!
- * A simple bsearch.
- */
-static int lustre_groups_search(const struct group_info *group_info, gid_t grp)
-{
- int left, right;
-
- if (!group_info)
- return 0;
-
- left = 0;
- right = group_info->ngroups;
- while (left < right) {
- int mid = (left + right) / 2;
- int cmp = grp -
- from_kgid(&init_user_ns, CFS_GROUP_AT(group_info, mid));
-
- if (cmp > 0)
- left = mid + 1;
- else if (cmp < 0)
- right = mid;
- else
- return 1;
- }
- return 0;
-}
-
-void lustre_groups_from_list(struct group_info *ginfo, gid_t *glist)
-{
- int i;
- int count = ginfo->ngroups;
-
- /* fill group_info from gid array */
- for (i = 0; i < ginfo->nblocks && count > 0; i++) {
- int cp_count = min(CFS_NGROUPS_PER_BLOCK, count);
- int off = i * CFS_NGROUPS_PER_BLOCK;
- int len = cp_count * sizeof(*glist);
-
- memcpy(ginfo->blocks[i], glist + off, len);
- count -= cp_count;
- }
-}
-EXPORT_SYMBOL(lustre_groups_from_list);
-
-/* groups_sort() is copied from linux kernel! */
-/* a simple shell-metzner sort */
-void lustre_groups_sort(struct group_info *group_info)
-{
- int base, max, stride;
- int gidsetsize = group_info->ngroups;
-
- for (stride = 1; stride < gidsetsize; stride = 3 * stride + 1)
- ; /* nothing */
- stride /= 3;
-
- while (stride) {
- max = gidsetsize - stride;
- for (base = 0; base < max; base++) {
- int left = base;
- int right = left + stride;
- gid_t tmp = from_kgid(&init_user_ns,
- CFS_GROUP_AT(group_info, right));
-
- while (left >= 0 &&
- tmp < from_kgid(&init_user_ns,
- CFS_GROUP_AT(group_info, left))) {
- CFS_GROUP_AT(group_info, right) =
- CFS_GROUP_AT(group_info, left);
- right = left;
- left -= stride;
- }
- CFS_GROUP_AT(group_info, right) =
- make_kgid(&init_user_ns, tmp);
- }
- stride /= 3;
- }
-}
-EXPORT_SYMBOL(lustre_groups_sort);
-
-int lustre_in_group_p(struct lu_ucred *mu, gid_t grp)
-{
- int rc = 1;
-
- if (grp != mu->uc_fsgid) {
- struct group_info *group_info = NULL;
-
- if (mu->uc_ginfo || !mu->uc_identity ||
- mu->uc_valid == UCRED_OLD)
- if (grp == mu->uc_suppgids[0] ||
- grp == mu->uc_suppgids[1])
- return 1;
-
- if (mu->uc_ginfo)
- group_info = mu->uc_ginfo;
- else if (mu->uc_identity)
- group_info = mu->uc_identity->mi_ginfo;
-
- if (!group_info)
- return 0;
-
- lustre_get_group_info(group_info);
- rc = lustre_groups_search(group_info, grp);
- lustre_put_group_info(group_info);
- }
- return rc;
-}
-EXPORT_SYMBOL(lustre_in_group_p);
-
-struct lustre_idmap_entry {
- struct list_head lie_rmt_uid_hash; /* hashed as lie_rmt_uid; */
- struct list_head lie_lcl_uid_hash; /* hashed as lie_lcl_uid; */
- struct list_head lie_rmt_gid_hash; /* hashed as lie_rmt_gid; */
- struct list_head lie_lcl_gid_hash; /* hashed as lie_lcl_gid; */
- uid_t lie_rmt_uid; /* remote uid */
- uid_t lie_lcl_uid; /* local uid */
- gid_t lie_rmt_gid; /* remote gid */
- gid_t lie_lcl_gid; /* local gid */
-};
-
-static inline __u32 lustre_idmap_hashfunc(__u32 id)
-{
- return id & (CFS_IDMAP_HASHSIZE - 1);
-}
-
-static
-struct lustre_idmap_entry *idmap_entry_alloc(uid_t rmt_uid, uid_t lcl_uid,
- gid_t rmt_gid, gid_t lcl_gid)
-{
- struct lustre_idmap_entry *e;
-
- OBD_ALLOC_PTR(e);
- if (e == NULL)
- return NULL;
-
- INIT_LIST_HEAD(&e->lie_rmt_uid_hash);
- INIT_LIST_HEAD(&e->lie_lcl_uid_hash);
- INIT_LIST_HEAD(&e->lie_rmt_gid_hash);
- INIT_LIST_HEAD(&e->lie_lcl_gid_hash);
- e->lie_rmt_uid = rmt_uid;
- e->lie_lcl_uid = lcl_uid;
- e->lie_rmt_gid = rmt_gid;
- e->lie_lcl_gid = lcl_gid;
-
- return e;
-}
-
-static void idmap_entry_free(struct lustre_idmap_entry *e)
-{
- if (!list_empty(&e->lie_rmt_uid_hash))
- list_del(&e->lie_rmt_uid_hash);
- if (!list_empty(&e->lie_lcl_uid_hash))
- list_del(&e->lie_lcl_uid_hash);
- if (!list_empty(&e->lie_rmt_gid_hash))
- list_del(&e->lie_rmt_gid_hash);
- if (!list_empty(&e->lie_lcl_gid_hash))
- list_del(&e->lie_lcl_gid_hash);
- OBD_FREE_PTR(e);
-}
-
-/*
- * return value
- * NULL: not found entry
- * ERR_PTR(-EACCES): found 1(remote):N(local) mapped entry
- * others: found normal entry
- */
-static
-struct lustre_idmap_entry *idmap_search_entry(struct lustre_idmap_table *t,
- uid_t rmt_uid, uid_t lcl_uid,
- gid_t rmt_gid, gid_t lcl_gid)
-{
- struct list_head *head;
- struct lustre_idmap_entry *e;
-
- head = &t->lit_idmaps[RMT_UIDMAP_IDX][lustre_idmap_hashfunc(rmt_uid)];
- list_for_each_entry(e, head, lie_rmt_uid_hash)
- if (e->lie_rmt_uid == rmt_uid) {
- if (e->lie_lcl_uid == lcl_uid) {
- if (e->lie_rmt_gid == rmt_gid &&
- e->lie_lcl_gid == lcl_gid)
- /* must be quaternion match */
- return e;
- } else {
- /* 1:N uid mapping */
- CERROR("rmt uid %u already be mapped to %u"
- " (new %u)\n", e->lie_rmt_uid,
- e->lie_lcl_uid, lcl_uid);
- return ERR_PTR(-EACCES);
- }
- }
-
- head = &t->lit_idmaps[RMT_GIDMAP_IDX][lustre_idmap_hashfunc(rmt_gid)];
- list_for_each_entry(e, head, lie_rmt_gid_hash)
- if (e->lie_rmt_gid == rmt_gid) {
- if (e->lie_lcl_gid == lcl_gid) {
- if (unlikely(e->lie_rmt_uid == rmt_uid &&
- e->lie_lcl_uid == lcl_uid))
- /* after uid mapping search above,
- * we should never come here */
- LBUG();
- } else {
- /* 1:N gid mapping */
- CERROR("rmt gid %u already be mapped to %u"
- " (new %u)\n", e->lie_rmt_gid,
- e->lie_lcl_gid, lcl_gid);
- return ERR_PTR(-EACCES);
- }
- }
-
- return NULL;
-}
-
-static __u32 idmap_lookup_uid(struct list_head *hash, int reverse,
- __u32 uid)
-{
- struct list_head *head = &hash[lustre_idmap_hashfunc(uid)];
- struct lustre_idmap_entry *e;
-
- if (!reverse) {
- list_for_each_entry(e, head, lie_rmt_uid_hash)
- if (e->lie_rmt_uid == uid)
- return e->lie_lcl_uid;
- } else {
- list_for_each_entry(e, head, lie_lcl_uid_hash)
- if (e->lie_lcl_uid == uid)
- return e->lie_rmt_uid;
- }
-
- return CFS_IDMAP_NOTFOUND;
-}
-
-static __u32 idmap_lookup_gid(struct list_head *hash, int reverse, __u32 gid)
-{
- struct list_head *head = &hash[lustre_idmap_hashfunc(gid)];
- struct lustre_idmap_entry *e;
-
- if (!reverse) {
- list_for_each_entry(e, head, lie_rmt_gid_hash)
- if (e->lie_rmt_gid == gid)
- return e->lie_lcl_gid;
- } else {
- list_for_each_entry(e, head, lie_lcl_gid_hash)
- if (e->lie_lcl_gid == gid)
- return e->lie_rmt_gid;
- }
-
- return CFS_IDMAP_NOTFOUND;
-}
-
-int lustre_idmap_add(struct lustre_idmap_table *t,
- uid_t ruid, uid_t luid,
- gid_t rgid, gid_t lgid)
-{
- struct lustre_idmap_entry *e0, *e1;
-
- LASSERT(t);
-
- spin_lock(&t->lit_lock);
- e0 = idmap_search_entry(t, ruid, luid, rgid, lgid);
- spin_unlock(&t->lit_lock);
- if (!e0) {
- e0 = idmap_entry_alloc(ruid, luid, rgid, lgid);
- if (!e0)
- return -ENOMEM;
-
- spin_lock(&t->lit_lock);
- e1 = idmap_search_entry(t, ruid, luid, rgid, lgid);
- if (e1 == NULL) {
- list_add_tail(&e0->lie_rmt_uid_hash,
- &t->lit_idmaps[RMT_UIDMAP_IDX]
- [lustre_idmap_hashfunc(ruid)]);
- list_add_tail(&e0->lie_lcl_uid_hash,
- &t->lit_idmaps[LCL_UIDMAP_IDX]
- [lustre_idmap_hashfunc(luid)]);
- list_add_tail(&e0->lie_rmt_gid_hash,
- &t->lit_idmaps[RMT_GIDMAP_IDX]
- [lustre_idmap_hashfunc(rgid)]);
- list_add_tail(&e0->lie_lcl_gid_hash,
- &t->lit_idmaps[LCL_GIDMAP_IDX]
- [lustre_idmap_hashfunc(lgid)]);
- }
- spin_unlock(&t->lit_lock);
- if (e1 != NULL) {
- idmap_entry_free(e0);
- if (IS_ERR(e1))
- return PTR_ERR(e1);
- }
- } else if (IS_ERR(e0)) {
- return PTR_ERR(e0);
- }
-
- return 0;
-}
-EXPORT_SYMBOL(lustre_idmap_add);
-
-int lustre_idmap_del(struct lustre_idmap_table *t,
- uid_t ruid, uid_t luid,
- gid_t rgid, gid_t lgid)
-{
- struct lustre_idmap_entry *e;
- int rc = 0;
-
- LASSERT(t);
-
- spin_lock(&t->lit_lock);
- e = idmap_search_entry(t, ruid, luid, rgid, lgid);
- if (IS_ERR(e))
- rc = PTR_ERR(e);
- else if (e)
- idmap_entry_free(e);
- spin_unlock(&t->lit_lock);
-
- return rc;
-}
-EXPORT_SYMBOL(lustre_idmap_del);
-
-int lustre_idmap_lookup_uid(struct lu_ucred *mu,
- struct lustre_idmap_table *t,
- int reverse, uid_t uid)
-{
- struct list_head *hash;
-
- if (mu && (mu->uc_valid == UCRED_OLD || mu->uc_valid == UCRED_NEW)) {
- if (!reverse) {
- if (uid == mu->uc_o_uid)
- return mu->uc_uid;
- else if (uid == mu->uc_o_fsuid)
- return mu->uc_fsuid;
- } else {
- if (uid == mu->uc_uid)
- return mu->uc_o_uid;
- else if (uid == mu->uc_fsuid)
- return mu->uc_o_fsuid;
- }
- }
-
- if (t == NULL)
- return CFS_IDMAP_NOTFOUND;
-
- hash = t->lit_idmaps[reverse ? LCL_UIDMAP_IDX : RMT_UIDMAP_IDX];
-
- spin_lock(&t->lit_lock);
- uid = idmap_lookup_uid(hash, reverse, uid);
- spin_unlock(&t->lit_lock);
-
- return uid;
-}
-EXPORT_SYMBOL(lustre_idmap_lookup_uid);
-
-int lustre_idmap_lookup_gid(struct lu_ucred *mu, struct lustre_idmap_table *t,
- int reverse, gid_t gid)
-{
- struct list_head *hash;
-
- if (mu && (mu->uc_valid == UCRED_OLD || mu->uc_valid == UCRED_NEW)) {
- if (!reverse) {
- if (gid == mu->uc_o_gid)
- return mu->uc_gid;
- else if (gid == mu->uc_o_fsgid)
- return mu->uc_fsgid;
- } else {
- if (gid == mu->uc_gid)
- return mu->uc_o_gid;
- else if (gid == mu->uc_fsgid)
- return mu->uc_o_fsgid;
- }
- }
-
- if (t == NULL)
- return CFS_IDMAP_NOTFOUND;
-
- hash = t->lit_idmaps[reverse ? LCL_GIDMAP_IDX : RMT_GIDMAP_IDX];
-
- spin_lock(&t->lit_lock);
- gid = idmap_lookup_gid(hash, reverse, gid);
- spin_unlock(&t->lit_lock);
-
- return gid;
-}
-EXPORT_SYMBOL(lustre_idmap_lookup_gid);
-
-struct lustre_idmap_table *lustre_idmap_init(void)
-{
- struct lustre_idmap_table *t;
- int i, j;
-
- OBD_ALLOC_PTR(t);
- if(unlikely(t == NULL))
- return (ERR_PTR(-ENOMEM));
-
- spin_lock_init(&t->lit_lock);
- for (i = 0; i < ARRAY_SIZE(t->lit_idmaps); i++)
- for (j = 0; j < ARRAY_SIZE(t->lit_idmaps[i]); j++)
- INIT_LIST_HEAD(&t->lit_idmaps[i][j]);
-
- return t;
-}
-EXPORT_SYMBOL(lustre_idmap_init);
-
-void lustre_idmap_fini(struct lustre_idmap_table *t)
-{
- struct list_head *list;
- struct lustre_idmap_entry *e;
- int i;
- LASSERT(t);
-
- list = t->lit_idmaps[RMT_UIDMAP_IDX];
- spin_lock(&t->lit_lock);
- for (i = 0; i < CFS_IDMAP_HASHSIZE; i++)
- while (!list_empty(&list[i])) {
- e = list_entry(list[i].next,
- struct lustre_idmap_entry,
- lie_rmt_uid_hash);
- idmap_entry_free(e);
- }
- spin_unlock(&t->lit_lock);
-
- OBD_FREE_PTR(t);
-}
-EXPORT_SYMBOL(lustre_idmap_fini);
diff --git a/drivers/staging/lustre/lustre/obdclass/linkea.c b/drivers/staging/lustre/lustre/obdclass/linkea.c
deleted file mode 100644
index 8a1c7b6fefe9..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/linkea.c
+++ /dev/null
@@ -1,194 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2013, Intel Corporation.
- * Use is subject to license terms.
- *
- * Author: Di Wang <di.wang@intel.com>
- */
-
-#include "../include/lustre/lustre_idl.h"
-#include "../include/obd.h"
-#include "../include/lustre_linkea.h"
-
-int linkea_data_new(struct linkea_data *ldata, struct lu_buf *buf)
-{
- ldata->ld_buf = lu_buf_check_and_alloc(buf, PAGE_CACHE_SIZE);
- if (ldata->ld_buf->lb_buf == NULL)
- return -ENOMEM;
- ldata->ld_leh = ldata->ld_buf->lb_buf;
- ldata->ld_leh->leh_magic = LINK_EA_MAGIC;
- ldata->ld_leh->leh_len = sizeof(struct link_ea_header);
- ldata->ld_leh->leh_reccount = 0;
- return 0;
-}
-EXPORT_SYMBOL(linkea_data_new);
-
-int linkea_init(struct linkea_data *ldata)
-{
- struct link_ea_header *leh;
-
- LASSERT(ldata->ld_buf != NULL);
- leh = ldata->ld_buf->lb_buf;
- if (leh->leh_magic == __swab32(LINK_EA_MAGIC)) {
- leh->leh_magic = LINK_EA_MAGIC;
- leh->leh_reccount = __swab32(leh->leh_reccount);
- leh->leh_len = __swab64(leh->leh_len);
- /* entries are swabbed by linkea_entry_unpack */
- }
- if (leh->leh_magic != LINK_EA_MAGIC)
- return -EINVAL;
- if (leh->leh_reccount == 0)
- return -ENODATA;
-
- ldata->ld_leh = leh;
- return 0;
-}
-EXPORT_SYMBOL(linkea_init);
-
-/**
- * Pack a link_ea_entry.
- * All elements are stored as chars to avoid alignment issues.
- * Numbers are always big-endian
- * \retval record length
- */
-static int linkea_entry_pack(struct link_ea_entry *lee,
- const struct lu_name *lname,
- const struct lu_fid *pfid)
-{
- struct lu_fid tmpfid;
- int reclen;
-
- fid_cpu_to_be(&tmpfid, pfid);
- if (OBD_FAIL_CHECK(OBD_FAIL_LFSCK_LINKEA_CRASH))
- tmpfid.f_ver = ~0;
- memcpy(&lee->lee_parent_fid, &tmpfid, sizeof(tmpfid));
- memcpy(lee->lee_name, lname->ln_name, lname->ln_namelen);
- reclen = sizeof(struct link_ea_entry) + lname->ln_namelen;
-
- lee->lee_reclen[0] = (reclen >> 8) & 0xff;
- lee->lee_reclen[1] = reclen & 0xff;
- return reclen;
-}
-
-void linkea_entry_unpack(const struct link_ea_entry *lee, int *reclen,
- struct lu_name *lname, struct lu_fid *pfid)
-{
- *reclen = (lee->lee_reclen[0] << 8) | lee->lee_reclen[1];
- memcpy(pfid, &lee->lee_parent_fid, sizeof(*pfid));
- fid_be_to_cpu(pfid, pfid);
- lname->ln_name = lee->lee_name;
- lname->ln_namelen = *reclen - sizeof(struct link_ea_entry);
-}
-EXPORT_SYMBOL(linkea_entry_unpack);
-
-/**
- * Add a record to the end of link ea buf
- **/
-int linkea_add_buf(struct linkea_data *ldata, const struct lu_name *lname,
- const struct lu_fid *pfid)
-{
- LASSERT(ldata->ld_leh != NULL);
-
- if (lname == NULL || pfid == NULL)
- return -EINVAL;
-
- ldata->ld_reclen = lname->ln_namelen + sizeof(struct link_ea_entry);
- if (ldata->ld_leh->leh_len + ldata->ld_reclen >
- ldata->ld_buf->lb_len) {
- if (lu_buf_check_and_grow(ldata->ld_buf,
- ldata->ld_leh->leh_len +
- ldata->ld_reclen) < 0)
- return -ENOMEM;
- }
-
- ldata->ld_leh = ldata->ld_buf->lb_buf;
- ldata->ld_lee = ldata->ld_buf->lb_buf + ldata->ld_leh->leh_len;
- ldata->ld_reclen = linkea_entry_pack(ldata->ld_lee, lname, pfid);
- ldata->ld_leh->leh_len += ldata->ld_reclen;
- ldata->ld_leh->leh_reccount++;
- CDEBUG(D_INODE, "New link_ea name '%.*s' is added\n",
- lname->ln_namelen, lname->ln_name);
- return 0;
-}
-EXPORT_SYMBOL(linkea_add_buf);
-
-/** Del the current record from the link ea buf */
-void linkea_del_buf(struct linkea_data *ldata, const struct lu_name *lname)
-{
- LASSERT(ldata->ld_leh != NULL && ldata->ld_lee != NULL);
-
- ldata->ld_leh->leh_reccount--;
- ldata->ld_leh->leh_len -= ldata->ld_reclen;
- memmove(ldata->ld_lee, (char *)ldata->ld_lee + ldata->ld_reclen,
- (char *)ldata->ld_leh + ldata->ld_leh->leh_len -
- (char *)ldata->ld_lee);
- CDEBUG(D_INODE, "Old link_ea name '%.*s' is removed\n",
- lname->ln_namelen, lname->ln_name);
-}
-EXPORT_SYMBOL(linkea_del_buf);
-
-/**
- * Check if such a link exists in linkEA.
- *
- * \param ldata link data the search to be done on
- * \param lname name in the parent's directory entry pointing to this object
- * \param pfid parent fid the link to be found for
- *
- * \retval 0 success
- * \retval -ENOENT link does not exist
- * \retval -ve on error
- */
-int linkea_links_find(struct linkea_data *ldata, const struct lu_name *lname,
- const struct lu_fid *pfid)
-{
- struct lu_name tmpname;
- struct lu_fid tmpfid;
- int count;
-
- LASSERT(ldata->ld_leh != NULL);
-
- /* link #0 */
- ldata->ld_lee = (struct link_ea_entry *)(ldata->ld_leh + 1);
-
- for (count = 0; count < ldata->ld_leh->leh_reccount; count++) {
- linkea_entry_unpack(ldata->ld_lee, &ldata->ld_reclen,
- &tmpname, &tmpfid);
- if (tmpname.ln_namelen == lname->ln_namelen &&
- lu_fid_eq(&tmpfid, pfid) &&
- (strncmp(tmpname.ln_name, lname->ln_name,
- tmpname.ln_namelen) == 0))
- break;
- ldata->ld_lee = (struct link_ea_entry *)((char *)ldata->ld_lee +
- ldata->ld_reclen);
- }
-
- if (count == ldata->ld_leh->leh_reccount) {
- CDEBUG(D_INODE, "Old link_ea name '%.*s' not found\n",
- lname->ln_namelen, lname->ln_name);
- ldata->ld_lee = NULL;
- return -ENOENT;
- }
- return 0;
-}
-EXPORT_SYMBOL(linkea_links_find);
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
index 9ce3d36c685d..7eaaaa648dfb 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-module.c
@@ -58,10 +58,10 @@
#include <linux/poll.h>
#include <linux/list.h>
#include <linux/highmem.h>
-#include <asm/io.h>
+#include <linux/io.h>
#include <asm/ioctls.h>
-#include <asm/poll.h>
-#include <asm/uaccess.h>
+#include <linux/poll.h>
+#include <linux/uaccess.h>
#include <linux/miscdevice.h>
#include <linux/seq_file.h>
@@ -84,7 +84,7 @@ int obd_ioctl_getdata(char **buf, int *len, void *arg)
int offset = 0;
err = copy_from_user(&hdr, (void *)arg, sizeof(hdr));
- if ( err )
+ if (err)
return err;
if (hdr.ioc_version != OBD_IOCTL_VERSION) {
@@ -118,7 +118,7 @@ int obd_ioctl_getdata(char **buf, int *len, void *arg)
data = (struct obd_ioctl_data *)*buf;
err = copy_from_user(*buf, (void *)arg, hdr.ioc_len);
- if ( err ) {
+ if (err) {
OBD_FREE_LARGE(*buf, hdr.ioc_len);
return err;
}
diff --git a/drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c b/drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c
index bb15202f1aae..62ed706b136d 100644
--- a/drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c
+++ b/drivers/staging/lustre/lustre/obdclass/linux/linux-obdo.c
@@ -52,7 +52,7 @@
/*FIXME: Just copy from obdo_from_inode*/
void obdo_from_la(struct obdo *dst, struct lu_attr *la, __u64 valid)
{
- obd_flag newvalid = 0;
+ u32 newvalid = 0;
if (valid & LA_ATIME) {
dst->o_atime = la->la_atime;
@@ -97,7 +97,7 @@ void obdo_from_la(struct obdo *dst, struct lu_attr *la, __u64 valid)
EXPORT_SYMBOL(obdo_from_la);
/*FIXME: Just copy from obdo_from_inode*/
-void la_from_obdo(struct lu_attr *dst, struct obdo *obdo, obd_flag valid)
+void la_from_obdo(struct lu_attr *dst, struct obdo *obdo, u32 valid)
{
__u64 newvalid = 0;
@@ -145,7 +145,7 @@ void la_from_obdo(struct lu_attr *dst, struct obdo *obdo, obd_flag valid)
}
EXPORT_SYMBOL(la_from_obdo);
-void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid)
+void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid)
{
valid &= src->o_valid;
@@ -180,7 +180,7 @@ void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid)
}
EXPORT_SYMBOL(obdo_refresh_inode);
-void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid)
+void obdo_to_inode(struct inode *dst, struct obdo *src, u32 valid)
{
valid &= src->o_valid;
diff --git a/drivers/staging/lustre/lustre/obdclass/llog.c b/drivers/staging/lustre/lustre/obdclass/llog.c
index cce86890c563..3ab05292152c 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog.c
@@ -56,7 +56,7 @@
* Allocate a new log or catalog handle
* Used inside llog_open().
*/
-struct llog_handle *llog_alloc_handle(void)
+static struct llog_handle *llog_alloc_handle(void)
{
struct llog_handle *loghandle;
@@ -75,7 +75,7 @@ struct llog_handle *llog_alloc_handle(void)
/*
* Free llog handle and header data if exists. Used in llog_close() only
*/
-void llog_free_handle(struct llog_handle *loghandle)
+static void llog_free_handle(struct llog_handle *loghandle)
{
LASSERT(loghandle != NULL);
@@ -140,7 +140,7 @@ int llog_cancel_rec(const struct lu_env *env, struct llog_handle *loghandle,
loghandle->lgh_ctxt->loc_obd->obd_name,
POSTID(&loghandle->lgh_id.lgl_oi),
loghandle->lgh_id.lgl_ogen, rc);
- GOTO(out_err, rc);
+ goto out_err;
}
return 1;
}
@@ -153,7 +153,7 @@ int llog_cancel_rec(const struct lu_env *env, struct llog_handle *loghandle,
loghandle->lgh_ctxt->loc_obd->obd_name,
POSTID(&loghandle->lgh_id.lgl_oi),
loghandle->lgh_id.lgl_ogen, rc);
- GOTO(out_err, rc);
+ goto out_err;
}
return 0;
out_err:
@@ -224,7 +224,8 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
llh->llh_flags & LLOG_F_IS_CAT ?
"catalog" : "plain",
flags & LLOG_F_IS_CAT ? "catalog" : "plain");
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
} else if (llh->llh_flags &
(LLOG_F_IS_PLAIN | LLOG_F_IS_CAT)) {
/*
@@ -235,7 +236,8 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
} else {
/* for some reason the llh_flags has no type set */
CERROR("llog type is not specified!\n");
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
}
if (unlikely(uuid &&
!obd_uuid_equals(uuid, &llh->llh_tgtuuid))) {
@@ -243,7 +245,8 @@ int llog_init_handle(const struct lu_env *env, struct llog_handle *handle,
handle->lgh_ctxt->loc_obd->obd_name,
(char *)uuid->uuid,
(char *)llh->llh_tgtuuid.uuid);
- GOTO(out, rc = -EEXIST);
+ rc = -EEXIST;
+ goto out;
}
}
if (flags & LLOG_F_IS_CAT) {
@@ -316,7 +319,7 @@ repeat:
rc = llog_next_block(lpi->lpi_env, loghandle, &saved_index,
index, &cur_offset, buf, LLOG_CHUNK_SIZE);
if (rc)
- GOTO(out, rc);
+ goto out;
/* NB: when rec->lrh_len is accessed it is already swabbed
* since it is used at the "end" of the loop and the rec
@@ -336,16 +339,18 @@ repeat:
if (rec->lrh_index == 0) {
/* probably another rec just got added? */
+ rc = 0;
if (index <= loghandle->lgh_last_idx)
- GOTO(repeat, rc = 0);
- GOTO(out, rc = 0); /* no more records */
+ goto repeat;
+ goto out; /* no more records */
}
if (rec->lrh_len == 0 ||
rec->lrh_len > LLOG_CHUNK_SIZE) {
CWARN("invalid length %d in llog record for "
"index %d/%d\n", rec->lrh_len,
rec->lrh_index, index);
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
}
if (rec->lrh_index < index) {
@@ -369,7 +374,7 @@ repeat:
lpi->lpi_cbdata);
last_called_index = index;
if (rc == LLOG_PROC_BREAK) {
- GOTO(out, rc);
+ goto out;
} else if (rc == LLOG_DEL_RECORD) {
llog_cancel_rec(lpi->lpi_env,
loghandle,
@@ -377,15 +382,17 @@ repeat:
rc = 0;
}
if (rc)
- GOTO(out, rc);
+ goto out;
} else {
CDEBUG(D_OTHER, "Skipped index %d\n", index);
}
/* next record, still in buffer? */
++index;
- if (index > last_index)
- GOTO(out, rc = 0);
+ if (index > last_index) {
+ rc = 0;
+ goto out;
+ }
}
}
@@ -506,7 +513,7 @@ int llog_reverse_process(const struct lu_env *env,
rc = llog_prev_block(env, loghandle, index, buf,
LLOG_CHUNK_SIZE);
if (rc)
- GOTO(out, rc);
+ goto out;
rec = buf;
idx = rec->lrh_index;
@@ -522,8 +529,11 @@ int llog_reverse_process(const struct lu_env *env,
/* process records in buffer, starting where we found one */
while ((void *)tail > buf) {
- if (tail->lrt_index == 0)
- GOTO(out, rc = 0); /* no more records */
+ if (tail->lrt_index == 0) {
+ /* no more records */
+ rc = 0;
+ goto out;
+ }
/* if set, process the callback on this record */
if (ext2_test_bit(index, llh->llh_bitmap)) {
@@ -532,20 +542,22 @@ int llog_reverse_process(const struct lu_env *env,
rc = cb(env, loghandle, rec, data);
if (rc == LLOG_PROC_BREAK) {
- GOTO(out, rc);
+ goto out;
} else if (rc == LLOG_DEL_RECORD) {
llog_cancel_rec(env, loghandle,
tail->lrt_index);
rc = 0;
}
if (rc)
- GOTO(out, rc);
+ goto out;
}
/* previous record, still in buffer? */
--index;
- if (index < first_index)
- GOTO(out, rc = 0);
+ if (index < first_index) {
+ rc = 0;
+ goto out;
+ }
tail = (void *)tail - tail->lrt_len;
}
}
@@ -750,8 +762,10 @@ int llog_open_create(const struct lu_env *env, struct llog_ctxt *ctxt,
d = lu2dt_dev((*res)->lgh_obj->do_lu.lo_dev);
th = dt_trans_create(env, d);
- if (IS_ERR(th))
- GOTO(out, rc = PTR_ERR(th));
+ if (IS_ERR(th)) {
+ rc = PTR_ERR(th);
+ goto out;
+ }
rc = llog_declare_create(env, *res, th);
if (rc == 0) {
@@ -820,11 +834,11 @@ int llog_write(const struct lu_env *env, struct llog_handle *loghandle,
rc = llog_declare_write_rec(env, loghandle, rec, idx, th);
if (rc)
- GOTO(out_trans, rc);
+ goto out_trans;
rc = dt_trans_start_local(env, dt, th);
if (rc)
- GOTO(out_trans, rc);
+ goto out_trans;
down_write(&loghandle->lgh_lock);
rc = llog_write_rec(env, loghandle, rec, reccookie,
@@ -878,9 +892,11 @@ int llog_close(const struct lu_env *env, struct llog_handle *loghandle)
rc = llog_handle2ops(loghandle, &lop);
if (rc)
- GOTO(out, rc);
- if (lop->lop_close == NULL)
- GOTO(out, rc = -EOPNOTSUPP);
+ goto out;
+ if (lop->lop_close == NULL) {
+ rc = -EOPNOTSUPP;
+ goto out;
+ }
rc = lop->lop_close(env, loghandle);
out:
llog_handle_put(loghandle);
@@ -898,12 +914,12 @@ int llog_is_empty(const struct lu_env *env, struct llog_ctxt *ctxt,
if (rc < 0) {
if (likely(rc == -ENOENT))
rc = 0;
- GOTO(out, rc);
+ goto out;
}
rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
if (rc)
- GOTO(out_close, rc);
+ goto out_close;
rc = llog_get_size(llh);
out_close:
@@ -948,19 +964,19 @@ int llog_backup(const struct lu_env *env, struct obd_device *obd,
rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
if (rc)
- GOTO(out_close, rc);
+ goto out_close;
/* Make sure there's no old backup log */
rc = llog_erase(env, bctxt, NULL, backup);
if (rc < 0 && rc != -ENOENT)
- GOTO(out_close, rc);
+ goto out_close;
/* open backup log */
rc = llog_open_create(env, bctxt, &bllh, NULL, backup);
if (rc) {
CERROR("%s: failed to open backup logfile %s: rc = %d\n",
obd->obd_name, backup, rc);
- GOTO(out_close, rc);
+ goto out_close;
}
/* check that backup llog is not the same object as original one */
@@ -968,12 +984,13 @@ int llog_backup(const struct lu_env *env, struct obd_device *obd,
CERROR("%s: backup llog %s to itself (%s), objects %p/%p\n",
obd->obd_name, name, backup, llh->lgh_obj,
bllh->lgh_obj);
- GOTO(out_backup, rc = -EEXIST);
+ rc = -EEXIST;
+ goto out_backup;
}
rc = llog_init_handle(env, bllh, LLOG_F_IS_PLAIN, NULL);
if (rc)
- GOTO(out_backup, rc);
+ goto out_backup;
/* Copy log record by record */
rc = llog_process_or_fork(env, llh, llog_copy_handler, (void *)bllh,
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_cat.c b/drivers/staging/lustre/lustre/obdclass/llog_cat.c
index ca9927ccde68..6e139cf372c4 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_cat.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_cat.c
@@ -96,7 +96,7 @@ static int llog_cat_new_log(const struct lu_env *env,
LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
&cathandle->lgh_hdr->llh_tgtuuid);
if (rc)
- GOTO(out_destroy, rc);
+ goto out_destroy;
if (index == 0)
index = 1;
@@ -114,7 +114,8 @@ static int llog_cat_new_log(const struct lu_env *env,
cathandle->lgh_last_idx = index;
llh->llh_tail.lrt_index = index;
- CDEBUG(D_RPCTRACE,"new recovery log "DOSTID":%x for index %u of catalog"
+ CDEBUG(D_RPCTRACE,
+ "new recovery log "DOSTID":%x for index %u of catalog"
DOSTID"\n", POSTID(&loghandle->lgh_id.lgl_oi),
loghandle->lgh_id.lgl_ogen, index,
POSTID(&cathandle->lgh_id.lgl_oi));
@@ -130,7 +131,7 @@ static int llog_cat_new_log(const struct lu_env *env,
rc = llog_write_rec(env, cathandle, &rec.lid_hdr,
&loghandle->u.phd.phd_cookie, 1, NULL, index, th);
if (rc < 0)
- GOTO(out_destroy, rc);
+ goto out_destroy;
loghandle->lgh_hdr->llh_cat_idx = index;
return 0;
@@ -173,7 +174,8 @@ int llog_cat_id2handle(const struct lu_env *env, struct llog_handle *cathandle,
}
loghandle->u.phd.phd_cat_handle = cathandle;
up_write(&cathandle->lgh_lock);
- GOTO(out, rc = 0);
+ rc = 0;
+ goto out;
}
}
up_write(&cathandle->lgh_lock);
@@ -403,20 +405,20 @@ int llog_cat_declare_add_rec(const struct lu_env *env,
up_write(&cathandle->lgh_lock);
}
if (rc)
- GOTO(out, rc);
+ goto out;
if (!llog_exist(cathandle->u.chd.chd_current_log)) {
rc = llog_declare_create(env, cathandle->u.chd.chd_current_log,
th);
if (rc)
- GOTO(out, rc);
+ goto out;
llog_declare_write_rec(env, cathandle, NULL, -1, th);
}
/* declare records in the llogs */
rc = llog_declare_write_rec(env, cathandle->u.chd.chd_current_log,
rec, -1, th);
if (rc)
- GOTO(out, rc);
+ goto out;
next = cathandle->u.chd.chd_next_log;
if (next) {
@@ -454,11 +456,11 @@ int llog_cat_add(const struct lu_env *env, struct llog_handle *cathandle,
rc = llog_cat_declare_add_rec(env, cathandle, rec, th);
if (rc)
- GOTO(out_trans, rc);
+ goto out_trans;
rc = dt_trans_start_local(env, dt, th);
if (rc)
- GOTO(out_trans, rc);
+ goto out_trans;
rc = llog_cat_add_rec(env, cathandle, rec, reccookie, buf, th);
out_trans:
dt_trans_stop(env, dt, th);
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_ioctl.c b/drivers/staging/lustre/lustre/obdclass/llog_ioctl.c
deleted file mode 100644
index 9b7fa1d5e79a..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/llog_ioctl.c
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- */
-
-#define DEBUG_SUBSYSTEM S_LOG
-
-#include "../include/obd_class.h"
-#include "../include/lustre_log.h"
-#include "llog_internal.h"
-
-static int str2logid(struct llog_logid *logid, char *str, int len)
-{
- char *start, *end, *endp;
- __u64 id, seq;
-
- start = str;
- if (*start != '#')
- return -EINVAL;
-
- start++;
- if (start - str >= len - 1)
- return -EINVAL;
- end = strchr(start, '#');
- if (end == NULL || end == start)
- return -EINVAL;
-
- *end = '\0';
- id = simple_strtoull(start, &endp, 0);
- if (endp != end)
- return -EINVAL;
-
- start = ++end;
- if (start - str >= len - 1)
- return -EINVAL;
- end = strchr(start, '#');
- if (end == NULL || end == start)
- return -EINVAL;
-
- *end = '\0';
- seq = simple_strtoull(start, &endp, 0);
- if (endp != end)
- return -EINVAL;
-
- ostid_set_seq(&logid->lgl_oi, seq);
- ostid_set_id(&logid->lgl_oi, id);
-
- start = ++end;
- if (start - str >= len - 1)
- return -EINVAL;
- logid->lgl_ogen = simple_strtoul(start, &endp, 16);
- if (*endp != '\0')
- return -EINVAL;
-
- return 0;
-}
-
-static int llog_check_cb(const struct lu_env *env, struct llog_handle *handle,
- struct llog_rec_hdr *rec, void *data)
-{
- struct obd_ioctl_data *ioc_data = (struct obd_ioctl_data *)data;
- static int l, remains, from, to;
- static char *out;
- char *endp;
- int cur_index, rc = 0;
-
- if (ioc_data && ioc_data->ioc_inllen1 > 0) {
- l = 0;
- remains = ioc_data->ioc_inllen4 +
- cfs_size_round(ioc_data->ioc_inllen1) +
- cfs_size_round(ioc_data->ioc_inllen2) +
- cfs_size_round(ioc_data->ioc_inllen3);
- from = simple_strtol(ioc_data->ioc_inlbuf2, &endp, 0);
- if (*endp != '\0')
- return -EINVAL;
- to = simple_strtol(ioc_data->ioc_inlbuf3, &endp, 0);
- if (*endp != '\0')
- return -EINVAL;
- ioc_data->ioc_inllen1 = 0;
- out = ioc_data->ioc_bulk;
- }
-
- cur_index = rec->lrh_index;
- if (cur_index < from)
- return 0;
- if (to > 0 && cur_index > to)
- return -LLOG_EEMPTY;
-
- if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) {
- struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
- struct llog_handle *loghandle;
-
- if (rec->lrh_type != LLOG_LOGID_MAGIC) {
- l = snprintf(out, remains, "[index]: %05d [type]: "
- "%02x [len]: %04d failed\n",
- cur_index, rec->lrh_type,
- rec->lrh_len);
- }
- if (handle->lgh_ctxt == NULL)
- return -EOPNOTSUPP;
- rc = llog_cat_id2handle(env, handle, &loghandle, &lir->lid_id);
- if (rc) {
- CDEBUG(D_IOCTL, "cannot find log #"DOSTID"#%08x\n",
- POSTID(&lir->lid_id.lgl_oi),
- lir->lid_id.lgl_ogen);
- return rc;
- }
- rc = llog_process(env, loghandle, llog_check_cb, NULL, NULL);
- llog_handle_put(loghandle);
- } else {
- bool ok;
-
- switch (rec->lrh_type) {
- case OST_SZ_REC:
- case MDS_UNLINK_REC:
- case MDS_UNLINK64_REC:
- case MDS_SETATTR64_REC:
- case OBD_CFG_REC:
- case LLOG_GEN_REC:
- case LLOG_HDR_MAGIC:
- ok = true;
- break;
- default:
- ok = false;
- }
-
- l = snprintf(out, remains, "[index]: %05d [type]: "
- "%02x [len]: %04d %s\n",
- cur_index, rec->lrh_type, rec->lrh_len,
- ok ? "ok" : "failed");
- out += l;
- remains -= l;
- if (remains <= 0) {
- CERROR("%s: no space to print log records\n",
- handle->lgh_ctxt->loc_obd->obd_name);
- return -LLOG_EEMPTY;
- }
- }
- return rc;
-}
-
-static int llog_print_cb(const struct lu_env *env, struct llog_handle *handle,
- struct llog_rec_hdr *rec, void *data)
-{
- struct obd_ioctl_data *ioc_data = (struct obd_ioctl_data *)data;
- static int l, remains, from, to;
- static char *out;
- char *endp;
- int cur_index;
-
- if (ioc_data != NULL && ioc_data->ioc_inllen1 > 0) {
- l = 0;
- remains = ioc_data->ioc_inllen4 +
- cfs_size_round(ioc_data->ioc_inllen1) +
- cfs_size_round(ioc_data->ioc_inllen2) +
- cfs_size_round(ioc_data->ioc_inllen3);
- from = simple_strtol(ioc_data->ioc_inlbuf2, &endp, 0);
- if (*endp != '\0')
- return -EINVAL;
- to = simple_strtol(ioc_data->ioc_inlbuf3, &endp, 0);
- if (*endp != '\0')
- return -EINVAL;
- out = ioc_data->ioc_bulk;
- ioc_data->ioc_inllen1 = 0;
- }
-
- cur_index = rec->lrh_index;
- if (cur_index < from)
- return 0;
- if (to > 0 && cur_index > to)
- return -LLOG_EEMPTY;
-
- if (handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT) {
- struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
-
- if (rec->lrh_type != LLOG_LOGID_MAGIC) {
- CERROR("invalid record in catalog\n");
- return -EINVAL;
- }
-
- l = snprintf(out, remains,
- "[index]: %05d [logid]: #"DOSTID"#%08x\n",
- cur_index, POSTID(&lir->lid_id.lgl_oi),
- lir->lid_id.lgl_ogen);
- } else if (rec->lrh_type == OBD_CFG_REC) {
- int rc;
-
- rc = class_config_parse_rec(rec, out, remains);
- if (rc < 0)
- return rc;
- l = rc;
- } else {
- l = snprintf(out, remains,
- "[index]: %05d [type]: %02x [len]: %04d\n",
- cur_index, rec->lrh_type, rec->lrh_len);
- }
- out += l;
- remains -= l;
- if (remains <= 0) {
- CERROR("not enough space for print log records\n");
- return -LLOG_EEMPTY;
- }
-
- return 0;
-}
-static int llog_remove_log(const struct lu_env *env, struct llog_handle *cat,
- struct llog_logid *logid)
-{
- struct llog_handle *log;
- int rc;
-
- rc = llog_cat_id2handle(env, cat, &log, logid);
- if (rc) {
- CDEBUG(D_IOCTL, "cannot find log #"DOSTID"#%08x\n",
- POSTID(&logid->lgl_oi), logid->lgl_ogen);
- return -ENOENT;
- }
-
- rc = llog_destroy(env, log);
- if (rc) {
- CDEBUG(D_IOCTL, "cannot destroy log\n");
- GOTO(out, rc);
- }
- llog_cat_cleanup(env, cat, log, log->u.phd.phd_cookie.lgc_index);
-out:
- llog_handle_put(log);
- return rc;
-
-}
-
-static int llog_delete_cb(const struct lu_env *env, struct llog_handle *handle,
- struct llog_rec_hdr *rec, void *data)
-{
- struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
- int rc;
-
- if (rec->lrh_type != LLOG_LOGID_MAGIC)
- return -EINVAL;
- rc = llog_remove_log(env, handle, &lir->lid_id);
-
- return rc;
-}
-
-
-int llog_ioctl(const struct lu_env *env, struct llog_ctxt *ctxt, int cmd,
- struct obd_ioctl_data *data)
-{
- struct llog_logid logid;
- int rc = 0;
- struct llog_handle *handle = NULL;
-
- if (*data->ioc_inlbuf1 == '#') {
- rc = str2logid(&logid, data->ioc_inlbuf1, data->ioc_inllen1);
- if (rc)
- return rc;
- rc = llog_open(env, ctxt, &handle, &logid, NULL,
- LLOG_OPEN_EXISTS);
- if (rc)
- return rc;
- } else if (*data->ioc_inlbuf1 == '$') {
- char *name = data->ioc_inlbuf1 + 1;
-
- rc = llog_open(env, ctxt, &handle, NULL, name,
- LLOG_OPEN_EXISTS);
- if (rc)
- return rc;
- } else {
- return -EINVAL;
- }
-
- rc = llog_init_handle(env, handle, 0, NULL);
- if (rc)
- GOTO(out_close, rc = -ENOENT);
-
- switch (cmd) {
- case OBD_IOC_LLOG_INFO: {
- int l;
- int remains = data->ioc_inllen2 +
- cfs_size_round(data->ioc_inllen1);
- char *out = data->ioc_bulk;
-
- l = snprintf(out, remains,
- "logid: #"DOSTID"#%08x\n"
- "flags: %x (%s)\n"
- "records count: %d\n"
- "last index: %d\n",
- POSTID(&handle->lgh_id.lgl_oi),
- handle->lgh_id.lgl_ogen,
- handle->lgh_hdr->llh_flags,
- handle->lgh_hdr->llh_flags &
- LLOG_F_IS_CAT ? "cat" : "plain",
- handle->lgh_hdr->llh_count,
- handle->lgh_last_idx);
- out += l;
- remains -= l;
- if (remains <= 0) {
- CERROR("%s: not enough space for log header info\n",
- ctxt->loc_obd->obd_name);
- rc = -ENOSPC;
- }
- break;
- }
- case OBD_IOC_LLOG_CHECK:
- LASSERT(data->ioc_inllen1 > 0);
- rc = llog_process(env, handle, llog_check_cb, data, NULL);
- if (rc == -LLOG_EEMPTY)
- rc = 0;
- else if (rc)
- GOTO(out_close, rc);
- break;
- case OBD_IOC_LLOG_PRINT:
- LASSERT(data->ioc_inllen1 > 0);
- rc = llog_process(env, handle, llog_print_cb, data, NULL);
- if (rc == -LLOG_EEMPTY)
- rc = 0;
- else if (rc)
- GOTO(out_close, rc);
- break;
- case OBD_IOC_LLOG_CANCEL: {
- struct llog_cookie cookie;
- struct llog_logid plain;
- char *endp;
-
- cookie.lgc_index = simple_strtoul(data->ioc_inlbuf3, &endp, 0);
- if (*endp != '\0')
- GOTO(out_close, rc = -EINVAL);
-
- if (handle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN) {
- rc = llog_cancel_rec(NULL, handle, cookie.lgc_index);
- GOTO(out_close, rc);
- } else if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
- GOTO(out_close, rc = -EINVAL);
- }
-
- if (data->ioc_inlbuf2 == NULL) /* catalog but no logid */
- GOTO(out_close, rc = -ENOTTY);
-
- rc = str2logid(&plain, data->ioc_inlbuf2, data->ioc_inllen2);
- if (rc)
- GOTO(out_close, rc);
- cookie.lgc_lgl = plain;
- rc = llog_cat_cancel_records(env, handle, 1, &cookie);
- if (rc)
- GOTO(out_close, rc);
- break;
- }
- case OBD_IOC_LLOG_REMOVE: {
- struct llog_logid plain;
-
- if (handle->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN) {
- rc = llog_destroy(env, handle);
- GOTO(out_close, rc);
- } else if (!(handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)) {
- GOTO(out_close, rc = -EINVAL);
- }
-
- if (data->ioc_inllen2 > 0) {
- /* remove indicate log from the catalog */
- rc = str2logid(&plain, data->ioc_inlbuf2,
- data->ioc_inllen2);
- if (rc)
- GOTO(out_close, rc);
- rc = llog_remove_log(env, handle, &plain);
- } else {
- /* remove all the log of the catalog */
- rc = llog_process(env, handle, llog_delete_cb, NULL,
- NULL);
- if (rc)
- GOTO(out_close, rc);
- }
- break;
- }
- default:
- CERROR("%s: Unknown ioctl cmd %#x\n",
- ctxt->loc_obd->obd_name, cmd);
- GOTO(out_close, rc = -ENOTTY);
- }
-
-out_close:
- if (handle->lgh_hdr &&
- handle->lgh_hdr->llh_flags & LLOG_F_IS_CAT)
- llog_cat_close(env, handle);
- else
- llog_close(env, handle);
- return rc;
-}
-EXPORT_SYMBOL(llog_ioctl);
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_lvfs.c b/drivers/staging/lustre/lustre/obdclass/llog_lvfs.c
deleted file mode 100644
index fd48d59cf315..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/llog_lvfs.c
+++ /dev/null
@@ -1,847 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/obdclass/llog_lvfs.c
- *
- * OST<->MDS recovery logging infrastructure.
- * Invariants in implementation:
- * - we do not share logs among different OST<->MDS connections, so that
- * if an OST or MDS fails it need only look at log(s) relevant to itself
- *
- * Author: Andreas Dilger <adilger@clusterfs.com>
- */
-
-#define DEBUG_SUBSYSTEM S_LOG
-
-
-#include "../include/obd.h"
-#include "../include/obd_class.h"
-#include "../include/lustre_log.h"
-#include "../include/obd_ost.h"
-#include <linux/list.h>
-#include "../include/lvfs.h"
-#include "../include/lustre_fsfilt.h"
-#include "../include/lustre_disk.h"
-#include "llog_internal.h"
-
-#if defined(LLOG_LVFS)
-
-static int llog_lvfs_pad(struct obd_device *obd, struct file *file, int len,
- int index)
-{
- struct llog_rec_hdr rec = { 0 };
- struct llog_rec_tail tail;
- int rc;
-
- LASSERT(len >= LLOG_MIN_REC_SIZE && (len & 0x7) == 0);
-
- tail.lrt_len = rec.lrh_len = len;
- tail.lrt_index = rec.lrh_index = index;
- rec.lrh_type = LLOG_PAD_MAGIC;
-
- rc = fsfilt_write_record(obd, file, &rec, sizeof(rec), &file->f_pos, 0);
- if (rc) {
- CERROR("error writing padding record: rc %d\n", rc);
- goto out;
- }
-
- file->f_pos += len - sizeof(rec) - sizeof(tail);
- rc = fsfilt_write_record(obd, file, &tail, sizeof(tail),&file->f_pos,0);
- if (rc) {
- CERROR("error writing padding record: rc %d\n", rc);
- goto out;
- }
-
- out:
- return rc;
-}
-
-static int llog_lvfs_write_blob(struct obd_device *obd, struct file *file,
- struct llog_rec_hdr *rec, void *buf, loff_t off)
-{
- int rc;
- struct llog_rec_tail end;
- loff_t saved_off = file->f_pos;
- int buflen = rec->lrh_len;
-
- file->f_pos = off;
-
- if (buflen == 0)
- CWARN("0-length record\n");
-
- if (!buf) {
- rc = fsfilt_write_record(obd, file, rec, buflen,&file->f_pos,0);
- if (rc) {
- CERROR("error writing log record: rc %d\n", rc);
- goto out;
- }
- GOTO(out, rc = 0);
- }
-
- /* the buf case */
- rec->lrh_len = sizeof(*rec) + buflen + sizeof(end);
- rc = fsfilt_write_record(obd, file, rec, sizeof(*rec), &file->f_pos, 0);
- if (rc) {
- CERROR("error writing log hdr: rc %d\n", rc);
- goto out;
- }
-
- rc = fsfilt_write_record(obd, file, buf, buflen, &file->f_pos, 0);
- if (rc) {
- CERROR("error writing log buffer: rc %d\n", rc);
- goto out;
- }
-
- end.lrt_len = rec->lrh_len;
- end.lrt_index = rec->lrh_index;
- rc = fsfilt_write_record(obd, file, &end, sizeof(end), &file->f_pos, 0);
- if (rc) {
- CERROR("error writing log tail: rc %d\n", rc);
- goto out;
- }
-
- rc = 0;
- out:
- if (saved_off > file->f_pos)
- file->f_pos = saved_off;
- LASSERT(rc <= 0);
- return rc;
-}
-
-static int llog_lvfs_read_blob(struct obd_device *obd, struct file *file,
- void *buf, int size, loff_t off)
-{
- loff_t offset = off;
- int rc;
-
- rc = fsfilt_read_record(obd, file, buf, size, &offset);
- if (rc) {
- CERROR("error reading log record: rc %d\n", rc);
- return rc;
- }
- return 0;
-}
-
-static int llog_lvfs_read_header(const struct lu_env *env,
- struct llog_handle *handle)
-{
- struct obd_device *obd;
- int rc;
-
- LASSERT(sizeof(*handle->lgh_hdr) == LLOG_CHUNK_SIZE);
-
- obd = handle->lgh_ctxt->loc_exp->exp_obd;
-
- if (i_size_read(handle->lgh_file->f_dentry->d_inode) == 0) {
- CDEBUG(D_HA, "not reading header from 0-byte log\n");
- return LLOG_EEMPTY;
- }
-
- rc = llog_lvfs_read_blob(obd, handle->lgh_file, handle->lgh_hdr,
- LLOG_CHUNK_SIZE, 0);
- if (rc) {
- CERROR("error reading log header from %.*s\n",
- handle->lgh_file->f_dentry->d_name.len,
- handle->lgh_file->f_dentry->d_name.name);
- } else {
- struct llog_rec_hdr *llh_hdr = &handle->lgh_hdr->llh_hdr;
-
- if (LLOG_REC_HDR_NEEDS_SWABBING(llh_hdr))
- lustre_swab_llog_hdr(handle->lgh_hdr);
-
- if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
- CERROR("bad log %.*s header magic: %#x (expected %#x)\n",
- handle->lgh_file->f_dentry->d_name.len,
- handle->lgh_file->f_dentry->d_name.name,
- llh_hdr->lrh_type, LLOG_HDR_MAGIC);
- rc = -EIO;
- } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
- CERROR("incorrectly sized log %.*s header: %#x "
- "(expected %#x)\n",
- handle->lgh_file->f_dentry->d_name.len,
- handle->lgh_file->f_dentry->d_name.name,
- llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
- CERROR("you may need to re-run lconf --write_conf.\n");
- rc = -EIO;
- }
- }
-
- handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
- handle->lgh_file->f_pos = i_size_read(handle->lgh_file->f_dentry->d_inode);
-
- return rc;
-}
-
-/* returns negative in on error; 0 if success && reccookie == 0; 1 otherwise */
-/* appends if idx == -1, otherwise overwrites record idx. */
-static int llog_lvfs_write_rec(const struct lu_env *env,
- struct llog_handle *loghandle,
- struct llog_rec_hdr *rec,
- struct llog_cookie *reccookie, int cookiecount,
- void *buf, int idx, struct thandle *th)
-{
- struct llog_log_hdr *llh;
- int reclen = rec->lrh_len, index, rc;
- struct llog_rec_tail *lrt;
- struct obd_device *obd;
- struct file *file;
- size_t left;
-
- llh = loghandle->lgh_hdr;
- file = loghandle->lgh_file;
- obd = loghandle->lgh_ctxt->loc_exp->exp_obd;
-
- /* record length should not bigger than LLOG_CHUNK_SIZE */
- if (buf)
- rc = (reclen > LLOG_CHUNK_SIZE - sizeof(struct llog_rec_hdr) -
- sizeof(struct llog_rec_tail)) ? -E2BIG : 0;
- else
- rc = (reclen > LLOG_CHUNK_SIZE) ? -E2BIG : 0;
- if (rc)
- return rc;
-
- if (buf)
- /* write_blob adds header and tail to lrh_len. */
- reclen = sizeof(*rec) + rec->lrh_len +
- sizeof(struct llog_rec_tail);
-
- if (idx != -1) {
- loff_t saved_offset;
-
- /* no header: only allowed to insert record 1 */
- if (idx != 1 && !i_size_read(file->f_dentry->d_inode)) {
- CERROR("idx != -1 in empty log\n");
- LBUG();
- }
-
- if (idx && llh->llh_size && llh->llh_size != rec->lrh_len)
- return -EINVAL;
-
- if (!ext2_test_bit(idx, llh->llh_bitmap))
- CERROR("Modify unset record %u\n", idx);
- if (idx != rec->lrh_index)
- CERROR("Index mismatch %d %u\n", idx, rec->lrh_index);
-
- rc = llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0);
- /* we are done if we only write the header or on error */
- if (rc || idx == 0)
- return rc;
-
- if (buf) {
- /* We assume that caller has set lgh_cur_* */
- saved_offset = loghandle->lgh_cur_offset;
- CDEBUG(D_OTHER,
- "modify record "DOSTID": idx:%d/%u/%d, len:%u "
- "offset %llu\n",
- POSTID(&loghandle->lgh_id.lgl_oi), idx, rec->lrh_index,
- loghandle->lgh_cur_idx, rec->lrh_len,
- (long long)(saved_offset - sizeof(*llh)));
- if (rec->lrh_index != loghandle->lgh_cur_idx) {
- CERROR("modify idx mismatch %u/%d\n",
- idx, loghandle->lgh_cur_idx);
- return -EFAULT;
- }
- } else {
- /* Assumes constant lrh_len */
- saved_offset = sizeof(*llh) + (idx - 1) * reclen;
- }
-
- rc = llog_lvfs_write_blob(obd, file, rec, buf, saved_offset);
- if (rc == 0 && reccookie) {
- reccookie->lgc_lgl = loghandle->lgh_id;
- reccookie->lgc_index = idx;
- rc = 1;
- }
- return rc;
- }
-
- /* Make sure that records don't cross a chunk boundary, so we can
- * process them page-at-a-time if needed. If it will cross a chunk
- * boundary, write in a fake (but referenced) entry to pad the chunk.
- *
- * We know that llog_current_log() will return a loghandle that is
- * big enough to hold reclen, so all we care about is padding here.
- */
- left = LLOG_CHUNK_SIZE - (file->f_pos & (LLOG_CHUNK_SIZE - 1));
-
- /* NOTE: padding is a record, but no bit is set */
- if (left != 0 && left != reclen &&
- left < (reclen + LLOG_MIN_REC_SIZE)) {
- index = loghandle->lgh_last_idx + 1;
- rc = llog_lvfs_pad(obd, file, left, index);
- if (rc)
- return rc;
- loghandle->lgh_last_idx++; /*for pad rec*/
- }
- /* if it's the last idx in log file, then return -ENOSPC */
- if (loghandle->lgh_last_idx >= LLOG_BITMAP_SIZE(llh) - 1)
- return -ENOSPC;
- loghandle->lgh_last_idx++;
- index = loghandle->lgh_last_idx;
- LASSERT(index < LLOG_BITMAP_SIZE(llh));
- rec->lrh_index = index;
- if (buf == NULL) {
- lrt = (struct llog_rec_tail *)
- ((char *)rec + rec->lrh_len - sizeof(*lrt));
- lrt->lrt_len = rec->lrh_len;
- lrt->lrt_index = rec->lrh_index;
- }
- /*The caller should make sure only 1 process access the lgh_last_idx,
- *Otherwise it might hit the assert.*/
- LASSERT(index < LLOG_BITMAP_SIZE(llh));
- spin_lock(&loghandle->lgh_hdr_lock);
- if (ext2_set_bit(index, llh->llh_bitmap)) {
- CERROR("argh, index %u already set in log bitmap?\n", index);
- spin_unlock(&loghandle->lgh_hdr_lock);
- LBUG(); /* should never happen */
- }
- llh->llh_count++;
- spin_unlock(&loghandle->lgh_hdr_lock);
- llh->llh_tail.lrt_index = index;
-
- rc = llog_lvfs_write_blob(obd, file, &llh->llh_hdr, NULL, 0);
- if (rc)
- return rc;
-
- rc = llog_lvfs_write_blob(obd, file, rec, buf, file->f_pos);
- if (rc)
- return rc;
-
- CDEBUG(D_RPCTRACE, "added record "DOSTID": idx: %u, %u \n",
- POSTID(&loghandle->lgh_id.lgl_oi), index, rec->lrh_len);
- if (rc == 0 && reccookie) {
- reccookie->lgc_lgl = loghandle->lgh_id;
- reccookie->lgc_index = index;
- if ((rec->lrh_type == MDS_UNLINK_REC) ||
- (rec->lrh_type == MDS_SETATTR64_REC))
- reccookie->lgc_subsys = LLOG_MDS_OST_ORIG_CTXT;
- else if (rec->lrh_type == OST_SZ_REC)
- reccookie->lgc_subsys = LLOG_SIZE_ORIG_CTXT;
- else
- reccookie->lgc_subsys = -1;
- rc = 1;
- }
- if (rc == 0 && rec->lrh_type == LLOG_GEN_REC)
- rc = 1;
-
- return rc;
-}
-
-/* We can skip reading at least as many log blocks as the number of
-* minimum sized log records we are skipping. If it turns out
-* that we are not far enough along the log (because the
-* actual records are larger than minimum size) we just skip
-* some more records. */
-
-static void llog_skip_over(__u64 *off, int curr, int goal)
-{
- if (goal <= curr)
- return;
- *off = (*off + (goal-curr-1) * LLOG_MIN_REC_SIZE) &
- ~(LLOG_CHUNK_SIZE - 1);
-}
-
-
-/* sets:
- * - cur_offset to the furthest point read in the log file
- * - cur_idx to the log index preceding cur_offset
- * returns -EIO/-EINVAL on error
- */
-static int llog_lvfs_next_block(const struct lu_env *env,
- struct llog_handle *loghandle, int *cur_idx,
- int next_idx, __u64 *cur_offset, void *buf,
- int len)
-{
- int rc;
-
- if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
- return -EINVAL;
-
- CDEBUG(D_OTHER, "looking for log index %u (cur idx %u off %llu)\n",
- next_idx, *cur_idx, *cur_offset);
-
- while (*cur_offset < i_size_read(loghandle->lgh_file->f_dentry->d_inode)) {
- struct llog_rec_hdr *rec, *last_rec;
- struct llog_rec_tail *tail;
- loff_t ppos;
- int llen;
-
- llog_skip_over(cur_offset, *cur_idx, next_idx);
-
- /* read up to next LLOG_CHUNK_SIZE block */
- ppos = *cur_offset;
- llen = LLOG_CHUNK_SIZE - (*cur_offset & (LLOG_CHUNK_SIZE - 1));
- rc = fsfilt_read_record(loghandle->lgh_ctxt->loc_exp->exp_obd,
- loghandle->lgh_file, buf, llen,
- cur_offset);
- if (rc < 0) {
- CERROR("Cant read llog block at log id "DOSTID
- "/%u offset %llu\n",
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen,
- *cur_offset);
- return rc;
- }
-
- /* put number of bytes read into rc to make code simpler */
- rc = *cur_offset - ppos;
- if (rc < len) {
- /* signal the end of the valid buffer to llog_process */
- memset(buf + rc, 0, len - rc);
- }
-
- if (rc == 0) /* end of file, nothing to do */
- return 0;
-
- if (rc < sizeof(*tail)) {
- CERROR("Invalid llog block at log id "DOSTID"/%u offset%llu\n",
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen, *cur_offset);
- return -EINVAL;
- }
-
- rec = buf;
- if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
- lustre_swab_llog_rec(rec);
-
- tail = (struct llog_rec_tail *)(buf + rc -
- sizeof(struct llog_rec_tail));
-
- /* get the last record in block */
- last_rec = (struct llog_rec_hdr *)(buf + rc -
- le32_to_cpu(tail->lrt_len));
-
- if (LLOG_REC_HDR_NEEDS_SWABBING(last_rec))
- lustre_swab_llog_rec(last_rec);
- LASSERT(last_rec->lrh_index == tail->lrt_index);
-
- *cur_idx = tail->lrt_index;
-
- /* this shouldn't happen */
- if (tail->lrt_index == 0) {
- CERROR("Invalid llog tail at log id "DOSTID"/%u offset %llu\n",
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen, *cur_offset);
- return -EINVAL;
- }
- if (tail->lrt_index < next_idx)
- continue;
-
- /* sanity check that the start of the new buffer is no farther
- * than the record that we wanted. This shouldn't happen. */
- if (rec->lrh_index > next_idx) {
- CERROR("missed desired record? %u > %u\n",
- rec->lrh_index, next_idx);
- return -ENOENT;
- }
- return 0;
- }
- return -EIO;
-}
-
-static int llog_lvfs_prev_block(const struct lu_env *env,
- struct llog_handle *loghandle,
- int prev_idx, void *buf, int len)
-{
- __u64 cur_offset;
- int rc;
-
- if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
- return -EINVAL;
-
- CDEBUG(D_OTHER, "looking for log index %u\n", prev_idx);
-
- cur_offset = LLOG_CHUNK_SIZE;
- llog_skip_over(&cur_offset, 0, prev_idx);
-
- while (cur_offset < i_size_read(loghandle->lgh_file->f_dentry->d_inode)) {
- struct llog_rec_hdr *rec, *last_rec;
- struct llog_rec_tail *tail;
- loff_t ppos = cur_offset;
-
- rc = fsfilt_read_record(loghandle->lgh_ctxt->loc_exp->exp_obd,
- loghandle->lgh_file, buf, len,
- &cur_offset);
- if (rc < 0) {
- CERROR("Cant read llog block at log id "DOSTID
- "/%u offset %llu\n",
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen,
- cur_offset);
- return rc;
- }
-
- /* put number of bytes read into rc to make code simpler */
- rc = cur_offset - ppos;
-
- if (rc == 0) /* end of file, nothing to do */
- return 0;
-
- if (rc < sizeof(*tail)) {
- CERROR("Invalid llog block at log id "DOSTID"/%u offset%llu\n",
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen, cur_offset);
- return -EINVAL;
- }
-
- rec = buf;
- if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
- lustre_swab_llog_rec(rec);
-
- tail = (struct llog_rec_tail *)(buf + rc -
- sizeof(struct llog_rec_tail));
-
- /* get the last record in block */
- last_rec = (struct llog_rec_hdr *)(buf + rc -
- le32_to_cpu(tail->lrt_len));
-
- if (LLOG_REC_HDR_NEEDS_SWABBING(last_rec))
- lustre_swab_llog_rec(last_rec);
- LASSERT(last_rec->lrh_index == tail->lrt_index);
-
- /* this shouldn't happen */
- if (tail->lrt_index == 0) {
- CERROR("Invalid llog tail at log id "DOSTID"/%u offset%llu\n",
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen, cur_offset);
- return -EINVAL;
- }
- if (tail->lrt_index < prev_idx)
- continue;
-
- /* sanity check that the start of the new buffer is no farther
- * than the record that we wanted. This shouldn't happen. */
- if (rec->lrh_index > prev_idx) {
- CERROR("missed desired record? %u > %u\n",
- rec->lrh_index, prev_idx);
- return -ENOENT;
- }
- return 0;
- }
- return -EIO;
-}
-
-static struct file *llog_filp_open(char *dir, char *name, int flags, int mode)
-{
- char *logname;
- struct file *filp;
- int len;
-
- OBD_ALLOC(logname, PATH_MAX);
- if (logname == NULL)
- return ERR_PTR(-ENOMEM);
-
- len = snprintf(logname, PATH_MAX, "%s/%s", dir, name);
- if (len >= PATH_MAX - 1) {
- filp = ERR_PTR(-ENAMETOOLONG);
- } else {
- filp = filp_open(logname, flags, mode);
- if (IS_ERR(filp) && PTR_ERR(filp) != -ENOENT)
- CERROR("logfile creation %s: %ld\n", logname,
- PTR_ERR(filp));
- }
- OBD_FREE(logname, PATH_MAX);
- return filp;
-}
-
-static int llog_lvfs_open(const struct lu_env *env, struct llog_handle *handle,
- struct llog_logid *logid, char *name,
- enum llog_open_param open_param)
-{
- struct llog_ctxt *ctxt = handle->lgh_ctxt;
- struct dentry *dchild = NULL;
- struct obd_device *obd;
- int rc = 0;
-
- LASSERT(ctxt);
- LASSERT(ctxt->loc_exp);
- LASSERT(ctxt->loc_exp->exp_obd);
- obd = ctxt->loc_exp->exp_obd;
-
- LASSERT(handle);
- if (logid != NULL) {
- dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, &logid->lgl_oi,
- logid->lgl_ogen);
- if (IS_ERR(dchild)) {
- rc = PTR_ERR(dchild);
- CERROR("%s: error looking up logfile #"DOSTID "#%08x:"
- " rc = %d\n", ctxt->loc_obd->obd_name,
- POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
- GOTO(out, rc);
- }
- if (dchild->d_inode == NULL) {
- l_dput(dchild);
- rc = -ENOENT;
- CERROR("%s: nonexistent llog #"DOSTID"#%08x:"
- "rc = %d\n", ctxt->loc_obd->obd_name,
- POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
- GOTO(out, rc);
- }
- handle->lgh_file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild,
- O_RDWR | O_LARGEFILE);
- l_dput(dchild);
- if (IS_ERR(handle->lgh_file)) {
- rc = PTR_ERR(handle->lgh_file);
- handle->lgh_file = NULL;
- CERROR("%s: error opening llog #"DOSTID"#%08x:"
- "rc = %d\n", ctxt->loc_obd->obd_name,
- POSTID(&logid->lgl_oi), logid->lgl_ogen, rc);
- GOTO(out, rc);
- }
- handle->lgh_id = *logid;
- } else if (name) {
- handle->lgh_file = llog_filp_open(MOUNT_CONFIGS_DIR, name,
- O_RDWR | O_LARGEFILE, 0644);
- if (IS_ERR(handle->lgh_file)) {
- rc = PTR_ERR(handle->lgh_file);
- handle->lgh_file = NULL;
- if (rc == -ENOENT && open_param == LLOG_OPEN_NEW) {
- OBD_ALLOC(handle->lgh_name, strlen(name) + 1);
- if (handle->lgh_name)
- strcpy(handle->lgh_name, name);
- else
- GOTO(out, rc = -ENOMEM);
- rc = 0;
- } else {
- GOTO(out, rc);
- }
- } else {
- lustre_build_llog_lvfs_oid(&handle->lgh_id,
- handle->lgh_file->f_dentry->d_inode->i_ino,
- handle->lgh_file->f_dentry->d_inode->i_generation);
- }
- } else {
- LASSERTF(open_param == LLOG_OPEN_NEW, "%#x\n", open_param);
- handle->lgh_file = NULL;
- }
-
- /* No new llog is expected but doesn't exist */
- if (open_param != LLOG_OPEN_NEW && handle->lgh_file == NULL)
- GOTO(out_name, rc = -ENOENT);
-
- return 0;
-out_name:
- if (handle->lgh_name != NULL)
- OBD_FREE(handle->lgh_name, strlen(name) + 1);
-out:
- return rc;
-}
-
-static int llog_lvfs_exist(struct llog_handle *handle)
-{
- return (handle->lgh_file != NULL);
-}
-
-/* This is a callback from the llog_* functions.
- * Assumes caller has already pushed us into the kernel context. */
-static int llog_lvfs_create(const struct lu_env *env,
- struct llog_handle *handle,
- struct thandle *th)
-{
- struct llog_ctxt *ctxt = handle->lgh_ctxt;
- struct obd_device *obd;
- struct dentry *dchild = NULL;
- struct file *file;
- struct obdo *oa = NULL;
- int rc = 0;
- int open_flags = O_RDWR | O_CREAT | O_LARGEFILE;
-
- LASSERT(ctxt);
- LASSERT(ctxt->loc_exp);
- obd = ctxt->loc_exp->exp_obd;
- LASSERT(handle->lgh_file == NULL);
-
- if (handle->lgh_name) {
- file = llog_filp_open(MOUNT_CONFIGS_DIR, handle->lgh_name,
- open_flags, 0644);
- if (IS_ERR(file))
- return PTR_ERR(file);
-
- lustre_build_llog_lvfs_oid(&handle->lgh_id,
- file->f_dentry->d_inode->i_ino,
- file->f_dentry->d_inode->i_generation);
- handle->lgh_file = file;
- } else {
- OBDO_ALLOC(oa);
- if (oa == NULL)
- return -ENOMEM;
-
- ostid_set_seq_llog(&oa->o_oi);
- oa->o_valid = OBD_MD_FLGENER | OBD_MD_FLGROUP;
-
- rc = obd_create(NULL, ctxt->loc_exp, oa, NULL, NULL);
- if (rc)
- GOTO(out, rc);
-
- /* FIXME: rationalize the misuse of o_generation in
- * this API along with mds_obd_{create,destroy}.
- * Hopefully it is only an internal API issue. */
-#define o_generation o_parent_oid
- dchild = obd_lvfs_fid2dentry(ctxt->loc_exp, &oa->o_oi,
- oa->o_generation);
- if (IS_ERR(dchild))
- GOTO(out, rc = PTR_ERR(dchild));
-
- file = l_dentry_open(&obd->obd_lvfs_ctxt, dchild, open_flags);
- l_dput(dchild);
- if (IS_ERR(file))
- GOTO(out, rc = PTR_ERR(file));
- handle->lgh_id.lgl_oi = oa->o_oi;
- handle->lgh_id.lgl_ogen = oa->o_generation;
- handle->lgh_file = file;
-out:
- OBDO_FREE(oa);
- }
- return rc;
-}
-
-static int llog_lvfs_close(const struct lu_env *env,
- struct llog_handle *handle)
-{
- int rc;
-
- if (handle->lgh_file == NULL)
- return 0;
- rc = filp_close(handle->lgh_file, 0);
- if (rc)
- CERROR("%s: error closing llog #"DOSTID"#%08x: "
- "rc = %d\n", handle->lgh_ctxt->loc_obd->obd_name,
- POSTID(&handle->lgh_id.lgl_oi),
- handle->lgh_id.lgl_ogen, rc);
- handle->lgh_file = NULL;
- if (handle->lgh_name) {
- OBD_FREE(handle->lgh_name, strlen(handle->lgh_name) + 1);
- handle->lgh_name = NULL;
- }
- return rc;
-}
-
-static int llog_lvfs_destroy(const struct lu_env *env,
- struct llog_handle *handle)
-{
- struct dentry *fdentry;
- struct obdo *oa;
- struct obd_device *obd = handle->lgh_ctxt->loc_exp->exp_obd;
- char *dir;
- void *th;
- struct inode *inode;
- int rc, rc1;
-
- dir = MOUNT_CONFIGS_DIR;
-
- LASSERT(handle->lgh_file);
- fdentry = handle->lgh_file->f_dentry;
- inode = fdentry->d_parent->d_inode;
- if (strcmp(fdentry->d_parent->d_name.name, dir) == 0) {
- struct lvfs_run_ctxt saved;
- struct vfsmount *mnt = mntget(handle->lgh_file->f_vfsmnt);
-
- push_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
- dget(fdentry);
- rc = llog_lvfs_close(env, handle);
- if (rc == 0) {
- mutex_lock_nested(&inode->i_mutex, I_MUTEX_PARENT);
- rc = ll_vfs_unlink(inode, fdentry, mnt);
- mutex_unlock(&inode->i_mutex);
- }
- mntput(mnt);
-
- dput(fdentry);
- pop_ctxt(&saved, &obd->obd_lvfs_ctxt, NULL);
- return rc;
- }
-
- OBDO_ALLOC(oa);
- if (oa == NULL)
- return -ENOMEM;
-
- oa->o_oi = handle->lgh_id.lgl_oi;
- oa->o_generation = handle->lgh_id.lgl_ogen;
-#undef o_generation
- oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLGENER;
-
- rc = llog_lvfs_close(env, handle);
- if (rc)
- GOTO(out, rc);
-
- th = fsfilt_start_log(obd, inode, FSFILT_OP_UNLINK, NULL, 1);
- if (IS_ERR(th)) {
- CERROR("fsfilt_start failed: %ld\n", PTR_ERR(th));
- GOTO(out, rc = PTR_ERR(th));
- }
-
- rc = obd_destroy(NULL, handle->lgh_ctxt->loc_exp, oa,
- NULL, NULL, NULL, NULL);
-
- rc1 = fsfilt_commit(obd, inode, th, 0);
- if (rc == 0 && rc1 != 0)
- rc = rc1;
- out:
- OBDO_FREE(oa);
- return rc;
-}
-
-static int llog_lvfs_declare_create(const struct lu_env *env,
- struct llog_handle *res,
- struct thandle *th)
-{
- return 0;
-}
-
-static int llog_lvfs_declare_write_rec(const struct lu_env *env,
- struct llog_handle *loghandle,
- struct llog_rec_hdr *rec,
- int idx, struct thandle *th)
-{
- return 0;
-}
-
-struct llog_operations llog_lvfs_ops = {
- .lop_write_rec = llog_lvfs_write_rec,
- .lop_next_block = llog_lvfs_next_block,
- .lop_prev_block = llog_lvfs_prev_block,
- .lop_read_header = llog_lvfs_read_header,
- .lop_create = llog_lvfs_create,
- .lop_destroy = llog_lvfs_destroy,
- .lop_close = llog_lvfs_close,
- .lop_open = llog_lvfs_open,
- .lop_exist = llog_lvfs_exist,
- .lop_declare_create = llog_lvfs_declare_create,
- .lop_declare_write_rec = llog_lvfs_declare_write_rec,
-};
-EXPORT_SYMBOL(llog_lvfs_ops);
-#else /* !__KERNEL__ */
-struct llog_operations llog_lvfs_ops = {};
-#endif
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_obd.c b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
index 8ff01d3f90b4..da769db0af77 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_obd.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_obd.c
@@ -242,31 +242,6 @@ int llog_cancel(const struct lu_env *env, struct llog_ctxt *ctxt,
}
EXPORT_SYMBOL(llog_cancel);
-int obd_llog_init(struct obd_device *obd, struct obd_llog_group *olg,
- struct obd_device *disk_obd, int *index)
-{
- int rc;
-
- OBD_CHECK_DT_OP(obd, llog_init, 0);
- OBD_COUNTER_INCREMENT(obd, llog_init);
-
- rc = OBP(obd, llog_init)(obd, olg, disk_obd, index);
- return rc;
-}
-EXPORT_SYMBOL(obd_llog_init);
-
-int obd_llog_finish(struct obd_device *obd, int count)
-{
- int rc;
-
- OBD_CHECK_DT_OP(obd, llog_finish, 0);
- OBD_COUNTER_INCREMENT(obd, llog_finish);
-
- rc = OBP(obd, llog_finish)(obd, count);
- return rc;
-}
-EXPORT_SYMBOL(obd_llog_finish);
-
/* context key constructor/destructor: llog_key_init, llog_key_fini */
LU_KEY_INIT_FINI(llog, struct llog_thread_info);
/* context key: llog_thread_key */
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_osd.c b/drivers/staging/lustre/lustre/obdclass/llog_osd.c
deleted file mode 100644
index 2c6a51e90697..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/llog_osd.c
+++ /dev/null
@@ -1,1290 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/obdclass/llog_osd.c - low level llog routines on top of OSD API
- *
- * Author: Alexey Zhuravlev <alexey.zhuravlev@intel.com>
- * Author: Mikhail Pershin <mike.pershin@intel.com>
- */
-
-#define DEBUG_SUBSYSTEM S_LOG
-
-#include "../include/obd.h"
-#include "../include/obd_class.h"
-#include "../include/lustre_fid.h"
-#include "../include/dt_object.h"
-
-#include "llog_internal.h"
-#include "local_storage.h"
-
-/*
- * - multi-chunks or big-declaration approach
- * - use unique sequence instead of llog sb tracking unique ids
- * - re-use existing environment
- * - named llog support (can be used for testing only at the present)
- * - llog_origin_connect() work with OSD API
- */
-
-static int llog_osd_declare_new_object(const struct lu_env *env,
- struct local_oid_storage *los,
- struct dt_object *o,
- struct thandle *th)
-{
- struct llog_thread_info *lgi = llog_info(env);
-
- lgi->lgi_attr.la_valid = LA_MODE;
- lgi->lgi_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
- lgi->lgi_dof.dof_type = dt_mode_to_dft(S_IFREG);
-
- return local_object_declare_create(env, los, o, &lgi->lgi_attr,
- &lgi->lgi_dof, th);
-}
-
-static int llog_osd_create_new_object(const struct lu_env *env,
- struct local_oid_storage *los,
- struct dt_object *o,
- struct thandle *th)
-{
- struct llog_thread_info *lgi = llog_info(env);
-
- lgi->lgi_attr.la_valid = LA_MODE;
- lgi->lgi_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
- lgi->lgi_dof.dof_type = dt_mode_to_dft(S_IFREG);
-
- return local_object_create(env, los, o, &lgi->lgi_attr,
- &lgi->lgi_dof, th);
-}
-
-static int llog_osd_pad(const struct lu_env *env, struct dt_object *o,
- loff_t *off, int len, int index, struct thandle *th)
-{
- struct llog_thread_info *lgi = llog_info(env);
- int rc;
-
- LASSERT(th);
- LASSERT(off);
- LASSERT(len >= LLOG_MIN_REC_SIZE && (len & 0x7) == 0);
-
- lgi->lgi_tail.lrt_len = lgi->lgi_lrh.lrh_len = len;
- lgi->lgi_tail.lrt_index = lgi->lgi_lrh.lrh_index = index;
- lgi->lgi_lrh.lrh_type = LLOG_PAD_MAGIC;
-
- lgi->lgi_buf.lb_buf = &lgi->lgi_lrh;
- lgi->lgi_buf.lb_len = sizeof(lgi->lgi_lrh);
- dt_write_lock(env, o, 0);
- rc = dt_record_write(env, o, &lgi->lgi_buf, off, th);
- if (rc) {
- CERROR("%s: error writing padding record: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name, rc);
- GOTO(out, rc);
- }
-
- lgi->lgi_buf.lb_buf = &lgi->lgi_tail;
- lgi->lgi_buf.lb_len = sizeof(lgi->lgi_tail);
- *off += len - sizeof(lgi->lgi_lrh) - sizeof(lgi->lgi_tail);
- rc = dt_record_write(env, o, &lgi->lgi_buf, off, th);
- if (rc)
- CERROR("%s: error writing padding record: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name, rc);
-out:
- dt_write_unlock(env, o);
- return rc;
-}
-
-static int llog_osd_write_blob(const struct lu_env *env, struct dt_object *o,
- struct llog_rec_hdr *rec, void *buf,
- loff_t *off, struct thandle *th)
-{
- struct llog_thread_info *lgi = llog_info(env);
- int buflen = rec->lrh_len;
- int rc;
-
- LASSERT(env);
- LASSERT(o);
-
- if (buflen == 0)
- CWARN("0-length record\n");
-
- CDEBUG(D_OTHER, "write blob with type %x, buf %p/%u at off %llu\n",
- rec->lrh_type, buf, buflen, *off);
-
- lgi->lgi_attr.la_valid = LA_SIZE;
- lgi->lgi_attr.la_size = *off;
-
- if (!buf) {
- lgi->lgi_buf.lb_len = buflen;
- lgi->lgi_buf.lb_buf = rec;
- rc = dt_record_write(env, o, &lgi->lgi_buf, off, th);
- if (rc)
- CERROR("%s: error writing log record: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name, rc);
- GOTO(out, rc);
- }
-
- /* the buf case */
- /* protect the following 3 writes from concurrent read */
- dt_write_lock(env, o, 0);
- rec->lrh_len = sizeof(*rec) + buflen + sizeof(lgi->lgi_tail);
- lgi->lgi_buf.lb_len = sizeof(*rec);
- lgi->lgi_buf.lb_buf = rec;
- rc = dt_record_write(env, o, &lgi->lgi_buf, off, th);
- if (rc) {
- CERROR("%s: error writing log hdr: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name, rc);
- GOTO(out_unlock, rc);
- }
-
- lgi->lgi_buf.lb_len = buflen;
- lgi->lgi_buf.lb_buf = buf;
- rc = dt_record_write(env, o, &lgi->lgi_buf, off, th);
- if (rc) {
- CERROR("%s: error writing log buffer: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name, rc);
- GOTO(out_unlock, rc);
- }
-
- lgi->lgi_tail.lrt_len = rec->lrh_len;
- lgi->lgi_tail.lrt_index = rec->lrh_index;
- lgi->lgi_buf.lb_len = sizeof(lgi->lgi_tail);
- lgi->lgi_buf.lb_buf = &lgi->lgi_tail;
- rc = dt_record_write(env, o, &lgi->lgi_buf, off, th);
- if (rc)
- CERROR("%s: error writing log tail: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name, rc);
-
-out_unlock:
- dt_write_unlock(env, o);
-
-out:
- /* cleanup the content written above */
- if (rc) {
- dt_punch(env, o, lgi->lgi_attr.la_size, OBD_OBJECT_EOF, th,
- BYPASS_CAPA);
- dt_attr_set(env, o, &lgi->lgi_attr, th, BYPASS_CAPA);
- }
-
- return rc;
-}
-
-static int llog_osd_read_header(const struct lu_env *env,
- struct llog_handle *handle)
-{
- struct llog_rec_hdr *llh_hdr;
- struct dt_object *o;
- struct llog_thread_info *lgi;
- int rc;
-
- LASSERT(sizeof(*handle->lgh_hdr) == LLOG_CHUNK_SIZE);
-
- o = handle->lgh_obj;
- LASSERT(o);
-
- lgi = llog_info(env);
-
- rc = dt_attr_get(env, o, &lgi->lgi_attr, NULL);
- if (rc)
- return rc;
-
- LASSERT(lgi->lgi_attr.la_valid & LA_SIZE);
-
- if (lgi->lgi_attr.la_size == 0) {
- CDEBUG(D_HA, "not reading header from 0-byte log\n");
- return LLOG_EEMPTY;
- }
-
- lgi->lgi_off = 0;
- lgi->lgi_buf.lb_buf = handle->lgh_hdr;
- lgi->lgi_buf.lb_len = LLOG_CHUNK_SIZE;
-
- rc = dt_record_read(env, o, &lgi->lgi_buf, &lgi->lgi_off);
- if (rc) {
- CERROR("%s: error reading log header from "DFID": rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- PFID(lu_object_fid(&o->do_lu)), rc);
- return rc;
- }
-
- llh_hdr = &handle->lgh_hdr->llh_hdr;
- if (LLOG_REC_HDR_NEEDS_SWABBING(llh_hdr))
- lustre_swab_llog_hdr(handle->lgh_hdr);
-
- if (llh_hdr->lrh_type != LLOG_HDR_MAGIC) {
- CERROR("%s: bad log %s "DFID" header magic: %#x "
- "(expected %#x)\n", o->do_lu.lo_dev->ld_obd->obd_name,
- handle->lgh_name ? handle->lgh_name : "",
- PFID(lu_object_fid(&o->do_lu)),
- llh_hdr->lrh_type, LLOG_HDR_MAGIC);
- return -EIO;
- } else if (llh_hdr->lrh_len != LLOG_CHUNK_SIZE) {
- CERROR("%s: incorrectly sized log %s "DFID" header: "
- "%#x (expected %#x)\n"
- "you may need to re-run lconf --write_conf.\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- handle->lgh_name ? handle->lgh_name : "",
- PFID(lu_object_fid(&o->do_lu)),
- llh_hdr->lrh_len, LLOG_CHUNK_SIZE);
- return -EIO;
- }
-
- handle->lgh_last_idx = handle->lgh_hdr->llh_tail.lrt_index;
-
- return 0;
-}
-
-static int llog_osd_declare_write_rec(const struct lu_env *env,
- struct llog_handle *loghandle,
- struct llog_rec_hdr *rec,
- int idx, struct thandle *th)
-{
- struct llog_thread_info *lgi = llog_info(env);
- struct dt_object *o;
- int rc;
-
- LASSERT(env);
- LASSERT(th);
- LASSERT(loghandle);
-
- o = loghandle->lgh_obj;
- LASSERT(o);
-
- /* each time we update header */
- rc = dt_declare_record_write(env, o, sizeof(struct llog_log_hdr), 0,
- th);
- if (rc || idx == 0) /* if error or just header */
- return rc;
-
- if (dt_object_exists(o)) {
- rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA);
- lgi->lgi_off = lgi->lgi_attr.la_size;
- LASSERT(ergo(rc == 0, lgi->lgi_attr.la_valid & LA_SIZE));
- if (rc)
- return rc;
-
- rc = dt_declare_punch(env, o, lgi->lgi_off, OBD_OBJECT_EOF, th);
- if (rc)
- return rc;
- } else {
- lgi->lgi_off = 0;
- }
-
- /* XXX: implement declared window or multi-chunks approach */
- rc = dt_declare_record_write(env, o, 32 * 1024, lgi->lgi_off, th);
-
- return rc;
-}
-
-/* returns negative in on error; 0 if success && reccookie == 0; 1 otherwise */
-/* appends if idx == -1, otherwise overwrites record idx. */
-static int llog_osd_write_rec(const struct lu_env *env,
- struct llog_handle *loghandle,
- struct llog_rec_hdr *rec,
- struct llog_cookie *reccookie, int cookiecount,
- void *buf, int idx, struct thandle *th)
-{
- struct llog_thread_info *lgi = llog_info(env);
- struct llog_log_hdr *llh;
- int reclen = rec->lrh_len;
- int index, rc, old_tail_idx;
- struct llog_rec_tail *lrt;
- struct dt_object *o;
- size_t left;
-
- LASSERT(env);
- llh = loghandle->lgh_hdr;
- LASSERT(llh);
- o = loghandle->lgh_obj;
- LASSERT(o);
- LASSERT(th);
-
- CDEBUG(D_OTHER, "new record %x to "DFID"\n",
- rec->lrh_type, PFID(lu_object_fid(&o->do_lu)));
-
- /* record length should not bigger than LLOG_CHUNK_SIZE */
- if (buf)
- rc = (reclen > LLOG_CHUNK_SIZE - sizeof(struct llog_rec_hdr) -
- sizeof(struct llog_rec_tail)) ? -E2BIG : 0;
- else
- rc = (reclen > LLOG_CHUNK_SIZE) ? -E2BIG : 0;
- if (rc)
- return rc;
-
- rc = dt_attr_get(env, o, &lgi->lgi_attr, NULL);
- if (rc)
- return rc;
-
- if (buf)
- /* write_blob adds header and tail to lrh_len. */
- reclen = sizeof(*rec) + rec->lrh_len +
- sizeof(struct llog_rec_tail);
-
- if (idx != -1) {
- /* no header: only allowed to insert record 1 */
- if (idx != 1 && lgi->lgi_attr.la_size == 0)
- LBUG();
-
- if (idx && llh->llh_size && llh->llh_size != rec->lrh_len)
- return -EINVAL;
-
- if (!ext2_test_bit(idx, llh->llh_bitmap))
- CERROR("%s: modify unset record %u\n",
- o->do_lu.lo_dev->ld_obd->obd_name, idx);
- if (idx != rec->lrh_index)
- CERROR("%s: index mismatch %d %u\n",
- o->do_lu.lo_dev->ld_obd->obd_name, idx,
- rec->lrh_index);
-
- lgi->lgi_off = 0;
- rc = llog_osd_write_blob(env, o, &llh->llh_hdr, NULL,
- &lgi->lgi_off, th);
- /* we are done if we only write the header or on error */
- if (rc || idx == 0)
- return rc;
-
- if (buf) {
- /* We assume that caller has set lgh_cur_* */
- lgi->lgi_off = loghandle->lgh_cur_offset;
- CDEBUG(D_OTHER,
- "modify record "DOSTID": idx:%d/%u/%d, len:%u "
- "offset %llu\n",
- POSTID(&loghandle->lgh_id.lgl_oi), idx,
- rec->lrh_index,
- loghandle->lgh_cur_idx, rec->lrh_len,
- (long long)(lgi->lgi_off - sizeof(*llh)));
- if (rec->lrh_index != loghandle->lgh_cur_idx) {
- CERROR("%s: modify idx mismatch %u/%d\n",
- o->do_lu.lo_dev->ld_obd->obd_name, idx,
- loghandle->lgh_cur_idx);
- return -EFAULT;
- }
- } else {
- /* Assumes constant lrh_len */
- lgi->lgi_off = sizeof(*llh) + (idx - 1) * reclen;
- }
-
- rc = llog_osd_write_blob(env, o, rec, buf, &lgi->lgi_off, th);
- if (rc == 0 && reccookie) {
- reccookie->lgc_lgl = loghandle->lgh_id;
- reccookie->lgc_index = idx;
- rc = 1;
- }
- return rc;
- }
-
- /* Make sure that records don't cross a chunk boundary, so we can
- * process them page-at-a-time if needed. If it will cross a chunk
- * boundary, write in a fake (but referenced) entry to pad the chunk.
- *
- * We know that llog_current_log() will return a loghandle that is
- * big enough to hold reclen, so all we care about is padding here.
- */
- LASSERT(lgi->lgi_attr.la_valid & LA_SIZE);
- lgi->lgi_off = lgi->lgi_attr.la_size;
- left = LLOG_CHUNK_SIZE - (lgi->lgi_off & (LLOG_CHUNK_SIZE - 1));
- /* NOTE: padding is a record, but no bit is set */
- if (left != 0 && left != reclen &&
- left < (reclen + LLOG_MIN_REC_SIZE)) {
- index = loghandle->lgh_last_idx + 1;
- rc = llog_osd_pad(env, o, &lgi->lgi_off, left, index, th);
- if (rc)
- return rc;
- loghandle->lgh_last_idx++; /*for pad rec*/
- }
- /* if it's the last idx in log file, then return -ENOSPC */
- if (loghandle->lgh_last_idx >= LLOG_BITMAP_SIZE(llh) - 1)
- return -ENOSPC;
-
- loghandle->lgh_last_idx++;
- index = loghandle->lgh_last_idx;
- LASSERT(index < LLOG_BITMAP_SIZE(llh));
- rec->lrh_index = index;
- if (buf == NULL) {
- lrt = (struct llog_rec_tail *)((char *)rec + rec->lrh_len -
- sizeof(*lrt));
- lrt->lrt_len = rec->lrh_len;
- lrt->lrt_index = rec->lrh_index;
- }
- /* The caller should make sure only 1 process access the lgh_last_idx,
- * Otherwise it might hit the assert.*/
- LASSERT(index < LLOG_BITMAP_SIZE(llh));
- spin_lock(&loghandle->lgh_hdr_lock);
- if (ext2_set_bit(index, llh->llh_bitmap)) {
- CERROR("%s: index %u already set in log bitmap\n",
- o->do_lu.lo_dev->ld_obd->obd_name, index);
- spin_unlock(&loghandle->lgh_hdr_lock);
- LBUG(); /* should never happen */
- }
- llh->llh_count++;
- spin_unlock(&loghandle->lgh_hdr_lock);
- old_tail_idx = llh->llh_tail.lrt_index;
- llh->llh_tail.lrt_index = index;
-
- lgi->lgi_off = 0;
- rc = llog_osd_write_blob(env, o, &llh->llh_hdr, NULL, &lgi->lgi_off,
- th);
- if (rc)
- GOTO(out, rc);
-
- rc = dt_attr_get(env, o, &lgi->lgi_attr, NULL);
- if (rc)
- GOTO(out, rc);
-
- LASSERT(lgi->lgi_attr.la_valid & LA_SIZE);
- lgi->lgi_off = lgi->lgi_attr.la_size;
-
- rc = llog_osd_write_blob(env, o, rec, buf, &lgi->lgi_off, th);
-
-out:
- /* cleanup llog for error case */
- if (rc) {
- spin_lock(&loghandle->lgh_hdr_lock);
- ext2_clear_bit(index, llh->llh_bitmap);
- llh->llh_count--;
- spin_unlock(&loghandle->lgh_hdr_lock);
-
- /* restore the header */
- loghandle->lgh_last_idx--;
- llh->llh_tail.lrt_index = old_tail_idx;
- lgi->lgi_off = 0;
- llog_osd_write_blob(env, o, &llh->llh_hdr, NULL,
- &lgi->lgi_off, th);
- }
-
- CDEBUG(D_RPCTRACE, "added record "DOSTID": idx: %u, %u\n",
- POSTID(&loghandle->lgh_id.lgl_oi), index, rec->lrh_len);
- if (rc == 0 && reccookie) {
- reccookie->lgc_lgl = loghandle->lgh_id;
- reccookie->lgc_index = index;
- if ((rec->lrh_type == MDS_UNLINK_REC) ||
- (rec->lrh_type == MDS_SETATTR64_REC))
- reccookie->lgc_subsys = LLOG_MDS_OST_ORIG_CTXT;
- else if (rec->lrh_type == OST_SZ_REC)
- reccookie->lgc_subsys = LLOG_SIZE_ORIG_CTXT;
- else
- reccookie->lgc_subsys = -1;
- rc = 1;
- }
- return rc;
-}
-
-/* We can skip reading at least as many log blocks as the number of
- * minimum sized log records we are skipping. If it turns out
- * that we are not far enough along the log (because the
- * actual records are larger than minimum size) we just skip
- * some more records.
- */
-static void llog_skip_over(__u64 *off, int curr, int goal)
-{
- if (goal <= curr)
- return;
- *off = (*off + (goal - curr - 1) * LLOG_MIN_REC_SIZE) &
- ~(LLOG_CHUNK_SIZE - 1);
-}
-
-/* sets:
- * - cur_offset to the furthest point read in the log file
- * - cur_idx to the log index preceding cur_offset
- * returns -EIO/-EINVAL on error
- */
-static int llog_osd_next_block(const struct lu_env *env,
- struct llog_handle *loghandle, int *cur_idx,
- int next_idx, __u64 *cur_offset, void *buf,
- int len)
-{
- struct llog_thread_info *lgi = llog_info(env);
- struct dt_object *o;
- struct dt_device *dt;
- int rc;
-
- LASSERT(env);
- LASSERT(lgi);
-
- if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
- return -EINVAL;
-
- CDEBUG(D_OTHER, "looking for log index %u (cur idx %u off %llu)\n",
- next_idx, *cur_idx, *cur_offset);
-
- LASSERT(loghandle);
- LASSERT(loghandle->lgh_ctxt);
-
- o = loghandle->lgh_obj;
- LASSERT(o);
- LASSERT(dt_object_exists(o));
- dt = lu2dt_dev(o->do_lu.lo_dev);
- LASSERT(dt);
-
- rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA);
- if (rc)
- GOTO(out, rc);
-
- while (*cur_offset < lgi->lgi_attr.la_size) {
- struct llog_rec_hdr *rec, *last_rec;
- struct llog_rec_tail *tail;
-
- llog_skip_over(cur_offset, *cur_idx, next_idx);
-
- /* read up to next LLOG_CHUNK_SIZE block */
- lgi->lgi_buf.lb_len = LLOG_CHUNK_SIZE -
- (*cur_offset & (LLOG_CHUNK_SIZE - 1));
- lgi->lgi_buf.lb_buf = buf;
-
- /* Note: read lock is not needed around la_size get above at
- * the time of dt_attr_get(). There are only two cases that
- * matter. Either la_size == cur_offset, in which case the
- * entire read is skipped, or la_size > cur_offset and the loop
- * is entered and this thread is blocked at dt_read_lock()
- * until the write is completed. When the write completes, then
- * the dt_read() will be done with the full length, and will
- * get the full data.
- */
- dt_read_lock(env, o, 0);
- rc = dt_read(env, o, &lgi->lgi_buf, cur_offset);
- dt_read_unlock(env, o);
- if (rc < 0) {
- CERROR("%s: can't read llog block from log "DFID
- " offset %llu: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- PFID(lu_object_fid(&o->do_lu)), *cur_offset,
- rc);
- GOTO(out, rc);
- }
-
- if (rc < len) {
- /* signal the end of the valid buffer to
- * llog_process */
- memset(buf + rc, 0, len - rc);
- }
-
- if (rc == 0) /* end of file, nothing to do */
- GOTO(out, rc);
-
- if (rc < sizeof(*tail)) {
- CERROR("%s: invalid llog block at log id "DOSTID"/%u "
- "offset %llu\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen, *cur_offset);
- GOTO(out, rc = -EINVAL);
- }
-
- rec = buf;
- if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
- lustre_swab_llog_rec(rec);
-
- tail = (struct llog_rec_tail *)((char *)buf + rc -
- sizeof(struct llog_rec_tail));
- /* get the last record in block */
- last_rec = (struct llog_rec_hdr *)((char *)buf + rc -
- le32_to_cpu(tail->lrt_len));
-
- if (LLOG_REC_HDR_NEEDS_SWABBING(last_rec))
- lustre_swab_llog_rec(last_rec);
- LASSERT(last_rec->lrh_index == tail->lrt_index);
-
- *cur_idx = tail->lrt_index;
-
- /* this shouldn't happen */
- if (tail->lrt_index == 0) {
- CERROR("%s: invalid llog tail at log id "DOSTID"/%u "
- "offset %llu\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen, *cur_offset);
- GOTO(out, rc = -EINVAL);
- }
- if (tail->lrt_index < next_idx)
- continue;
-
- /* sanity check that the start of the new buffer is no farther
- * than the record that we wanted. This shouldn't happen. */
- if (rec->lrh_index > next_idx) {
- CERROR("%s: missed desired record? %u > %u\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- rec->lrh_index, next_idx);
- GOTO(out, rc = -ENOENT);
- }
- GOTO(out, rc = 0);
- }
- GOTO(out, rc = -EIO);
-out:
- return rc;
-}
-
-static int llog_osd_prev_block(const struct lu_env *env,
- struct llog_handle *loghandle,
- int prev_idx, void *buf, int len)
-{
- struct llog_thread_info *lgi = llog_info(env);
- struct dt_object *o;
- struct dt_device *dt;
- loff_t cur_offset;
- int rc;
-
- if (len == 0 || len & (LLOG_CHUNK_SIZE - 1))
- return -EINVAL;
-
- CDEBUG(D_OTHER, "looking for log index %u\n", prev_idx);
-
- LASSERT(loghandle);
- LASSERT(loghandle->lgh_ctxt);
-
- o = loghandle->lgh_obj;
- LASSERT(o);
- LASSERT(dt_object_exists(o));
- dt = lu2dt_dev(o->do_lu.lo_dev);
- LASSERT(dt);
-
- cur_offset = LLOG_CHUNK_SIZE;
- llog_skip_over(&cur_offset, 0, prev_idx);
-
- rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA);
- if (rc)
- GOTO(out, rc);
-
- while (cur_offset < lgi->lgi_attr.la_size) {
- struct llog_rec_hdr *rec, *last_rec;
- struct llog_rec_tail *tail;
-
- lgi->lgi_buf.lb_len = len;
- lgi->lgi_buf.lb_buf = buf;
- /* It is OK to have locking around dt_read() only, see
- * comment in llog_osd_next_block for details
- */
- dt_read_lock(env, o, 0);
- rc = dt_read(env, o, &lgi->lgi_buf, &cur_offset);
- dt_read_unlock(env, o);
- if (rc < 0) {
- CERROR("%s: can't read llog block from log "DFID
- " offset %llu: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- PFID(lu_object_fid(&o->do_lu)), cur_offset, rc);
- GOTO(out, rc);
- }
-
- if (rc == 0) /* end of file, nothing to do */
- GOTO(out, rc);
-
- if (rc < sizeof(*tail)) {
- CERROR("%s: invalid llog block at log id "DOSTID"/%u "
- "offset %llu\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen, cur_offset);
- GOTO(out, rc = -EINVAL);
- }
-
- rec = buf;
- if (LLOG_REC_HDR_NEEDS_SWABBING(rec))
- lustre_swab_llog_rec(rec);
-
- tail = (struct llog_rec_tail *)((char *)buf + rc -
- sizeof(struct llog_rec_tail));
- /* get the last record in block */
- last_rec = (struct llog_rec_hdr *)((char *)buf + rc -
- le32_to_cpu(tail->lrt_len));
-
- if (LLOG_REC_HDR_NEEDS_SWABBING(last_rec))
- lustre_swab_llog_rec(last_rec);
- LASSERT(last_rec->lrh_index == tail->lrt_index);
-
- /* this shouldn't happen */
- if (tail->lrt_index == 0) {
- CERROR("%s: invalid llog tail at log id "DOSTID"/%u "
- "offset %llu\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- POSTID(&loghandle->lgh_id.lgl_oi),
- loghandle->lgh_id.lgl_ogen, cur_offset);
- GOTO(out, rc = -EINVAL);
- }
- if (tail->lrt_index < prev_idx)
- continue;
-
- /* sanity check that the start of the new buffer is no farther
- * than the record that we wanted. This shouldn't happen. */
- if (rec->lrh_index > prev_idx) {
- CERROR("%s: missed desired record? %u > %u\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- rec->lrh_index, prev_idx);
- GOTO(out, rc = -ENOENT);
- }
- GOTO(out, rc = 0);
- }
- GOTO(out, rc = -EIO);
-out:
- return rc;
-}
-
-struct dt_object *llog_osd_dir_get(const struct lu_env *env,
- struct llog_ctxt *ctxt)
-{
- struct dt_device *dt;
- struct dt_thread_info *dti = dt_info(env);
- struct dt_object *dir;
- int rc;
-
- dt = ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt;
- if (ctxt->loc_dir == NULL) {
- rc = dt_root_get(env, dt, &dti->dti_fid);
- if (rc)
- return ERR_PTR(rc);
- dir = dt_locate(env, dt, &dti->dti_fid);
- } else {
- lu_object_get(&ctxt->loc_dir->do_lu);
- dir = ctxt->loc_dir;
- }
-
- return dir;
-}
-
-static int llog_osd_open(const struct lu_env *env, struct llog_handle *handle,
- struct llog_logid *logid, char *name,
- enum llog_open_param open_param)
-{
- struct llog_thread_info *lgi = llog_info(env);
- struct llog_ctxt *ctxt = handle->lgh_ctxt;
- struct dt_object *o;
- struct dt_device *dt;
- struct ls_device *ls;
- struct local_oid_storage *los;
- int rc = 0;
-
- LASSERT(env);
- LASSERT(ctxt);
- LASSERT(ctxt->loc_exp);
- LASSERT(ctxt->loc_exp->exp_obd);
- dt = ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt;
- LASSERT(dt);
-
- ls = ls_device_get(dt);
- if (IS_ERR(ls))
- return PTR_ERR(ls);
-
- mutex_lock(&ls->ls_los_mutex);
- los = dt_los_find(ls, name != NULL ? FID_SEQ_LLOG_NAME : FID_SEQ_LLOG);
- mutex_unlock(&ls->ls_los_mutex);
- LASSERT(los);
- ls_device_put(env, ls);
-
- LASSERT(handle);
-
- if (logid != NULL) {
- logid_to_fid(logid, &lgi->lgi_fid);
- } else if (name) {
- struct dt_object *llog_dir;
-
- llog_dir = llog_osd_dir_get(env, ctxt);
- if (IS_ERR(llog_dir))
- GOTO(out, rc = PTR_ERR(llog_dir));
- dt_read_lock(env, llog_dir, 0);
- rc = dt_lookup_dir(env, llog_dir, name, &lgi->lgi_fid);
- dt_read_unlock(env, llog_dir);
- lu_object_put(env, &llog_dir->do_lu);
- if (rc == -ENOENT && open_param == LLOG_OPEN_NEW) {
- /* generate fid for new llog */
- rc = local_object_fid_generate(env, los,
- &lgi->lgi_fid);
- }
- if (rc < 0)
- GOTO(out, rc);
- OBD_ALLOC(handle->lgh_name, strlen(name) + 1);
- if (handle->lgh_name)
- strcpy(handle->lgh_name, name);
- else
- GOTO(out, rc = -ENOMEM);
- } else {
- LASSERTF(open_param & LLOG_OPEN_NEW, "%#x\n", open_param);
- /* generate fid for new llog */
- rc = local_object_fid_generate(env, los, &lgi->lgi_fid);
- if (rc < 0)
- GOTO(out, rc);
- }
-
- o = ls_locate(env, ls, &lgi->lgi_fid);
- if (IS_ERR(o))
- GOTO(out_name, rc = PTR_ERR(o));
-
- /* No new llog is expected but doesn't exist */
- if (open_param != LLOG_OPEN_NEW && !dt_object_exists(o))
- GOTO(out_put, rc = -ENOENT);
-
- fid_to_logid(&lgi->lgi_fid, &handle->lgh_id);
- handle->lgh_obj = o;
- handle->private_data = los;
- LASSERT(handle->lgh_ctxt);
-
- return rc;
-
-out_put:
- lu_object_put(env, &o->do_lu);
-out_name:
- if (handle->lgh_name != NULL)
- OBD_FREE(handle->lgh_name, strlen(name) + 1);
-out:
- dt_los_put(los);
- return rc;
-}
-
-static int llog_osd_exist(struct llog_handle *handle)
-{
- LASSERT(handle->lgh_obj);
- return (dt_object_exists(handle->lgh_obj) &&
- !lu_object_is_dying(handle->lgh_obj->do_lu.lo_header));
-}
-
-static int llog_osd_declare_create(const struct lu_env *env,
- struct llog_handle *res, struct thandle *th)
-{
- struct llog_thread_info *lgi = llog_info(env);
- struct local_oid_storage *los;
- struct dt_object *o;
- int rc;
-
- LASSERT(res->lgh_obj);
- LASSERT(th);
-
- /* object can be created by another thread */
- o = res->lgh_obj;
- if (dt_object_exists(o))
- return 0;
-
- los = res->private_data;
- LASSERT(los);
-
- rc = llog_osd_declare_new_object(env, los, o, th);
- if (rc)
- return rc;
-
- rc = dt_declare_record_write(env, o, LLOG_CHUNK_SIZE, 0, th);
- if (rc)
- return rc;
-
- if (res->lgh_name) {
- struct dt_object *llog_dir;
-
- llog_dir = llog_osd_dir_get(env, res->lgh_ctxt);
- if (IS_ERR(llog_dir))
- return PTR_ERR(llog_dir);
- logid_to_fid(&res->lgh_id, &lgi->lgi_fid);
- rc = dt_declare_insert(env, llog_dir,
- (struct dt_rec *)&lgi->lgi_fid,
- (struct dt_key *)res->lgh_name, th);
- lu_object_put(env, &llog_dir->do_lu);
- if (rc)
- CERROR("%s: can't declare named llog %s: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- res->lgh_name, rc);
- }
- return rc;
-}
-
-/* This is a callback from the llog_* functions.
- * Assumes caller has already pushed us into the kernel context. */
-static int llog_osd_create(const struct lu_env *env, struct llog_handle *res,
- struct thandle *th)
-{
- struct llog_thread_info *lgi = llog_info(env);
- struct local_oid_storage *los;
- struct dt_object *o;
- int rc = 0;
-
- LASSERT(env);
- o = res->lgh_obj;
- LASSERT(o);
-
- /* llog can be already created */
- if (dt_object_exists(o))
- return -EEXIST;
-
- los = res->private_data;
- LASSERT(los);
-
- dt_write_lock(env, o, 0);
- if (!dt_object_exists(o))
- rc = llog_osd_create_new_object(env, los, o, th);
- else
- rc = -EEXIST;
-
- dt_write_unlock(env, o);
- if (rc)
- return rc;
-
- if (res->lgh_name) {
- struct dt_object *llog_dir;
-
- llog_dir = llog_osd_dir_get(env, res->lgh_ctxt);
- if (IS_ERR(llog_dir))
- return PTR_ERR(llog_dir);
-
- logid_to_fid(&res->lgh_id, &lgi->lgi_fid);
- dt_read_lock(env, llog_dir, 0);
- rc = dt_insert(env, llog_dir,
- (struct dt_rec *)&lgi->lgi_fid,
- (struct dt_key *)res->lgh_name,
- th, BYPASS_CAPA, 1);
- dt_read_unlock(env, llog_dir);
- lu_object_put(env, &llog_dir->do_lu);
- if (rc)
- CERROR("%s: can't create named llog %s: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- res->lgh_name, rc);
- }
- return rc;
-}
-
-static int llog_osd_close(const struct lu_env *env, struct llog_handle *handle)
-{
- struct local_oid_storage *los;
- int rc = 0;
-
- LASSERT(handle->lgh_obj);
-
- lu_object_put(env, &handle->lgh_obj->do_lu);
-
- los = handle->private_data;
- LASSERT(los);
- dt_los_put(los);
-
- if (handle->lgh_name)
- OBD_FREE(handle->lgh_name, strlen(handle->lgh_name) + 1);
-
- return rc;
-}
-
-static int llog_osd_destroy(const struct lu_env *env,
- struct llog_handle *loghandle)
-{
- struct llog_ctxt *ctxt;
- struct dt_object *o, *llog_dir = NULL;
- struct dt_device *d;
- struct thandle *th;
- char *name = NULL;
- int rc;
-
- ctxt = loghandle->lgh_ctxt;
- LASSERT(ctxt);
-
- o = loghandle->lgh_obj;
- LASSERT(o);
-
- d = lu2dt_dev(o->do_lu.lo_dev);
- LASSERT(d);
- LASSERT(d == ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt);
-
- th = dt_trans_create(env, d);
- if (IS_ERR(th))
- return PTR_ERR(th);
-
- if (loghandle->lgh_name) {
- llog_dir = llog_osd_dir_get(env, ctxt);
- if (IS_ERR(llog_dir))
- GOTO(out_trans, rc = PTR_ERR(llog_dir));
-
- name = loghandle->lgh_name;
- rc = dt_declare_delete(env, llog_dir,
- (struct dt_key *)name, th);
- if (rc)
- GOTO(out_trans, rc);
- }
-
- dt_declare_ref_del(env, o, th);
-
- rc = dt_declare_destroy(env, o, th);
- if (rc)
- GOTO(out_trans, rc);
-
- rc = dt_trans_start_local(env, d, th);
- if (rc)
- GOTO(out_trans, rc);
-
- dt_write_lock(env, o, 0);
- if (dt_object_exists(o)) {
- if (name) {
- dt_read_lock(env, llog_dir, 0);
- rc = dt_delete(env, llog_dir,
- (struct dt_key *) name,
- th, BYPASS_CAPA);
- dt_read_unlock(env, llog_dir);
- if (rc) {
- CERROR("%s: can't remove llog %s: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- name, rc);
- GOTO(out_unlock, rc);
- }
- }
- dt_ref_del(env, o, th);
- rc = dt_destroy(env, o, th);
- if (rc)
- GOTO(out_unlock, rc);
- }
-out_unlock:
- dt_write_unlock(env, o);
-out_trans:
- dt_trans_stop(env, d, th);
- if (llog_dir != NULL)
- lu_object_put(env, &llog_dir->do_lu);
- return rc;
-}
-
-static int llog_osd_setup(const struct lu_env *env, struct obd_device *obd,
- struct obd_llog_group *olg, int ctxt_idx,
- struct obd_device *disk_obd)
-{
- struct local_oid_storage *los;
- struct llog_thread_info *lgi = llog_info(env);
- struct llog_ctxt *ctxt;
- int rc = 0;
-
- LASSERT(obd);
- LASSERT(olg->olg_ctxts[ctxt_idx]);
-
- ctxt = llog_ctxt_get(olg->olg_ctxts[ctxt_idx]);
- LASSERT(ctxt);
-
- /* initialize data allowing to generate new fids,
- * literally we need a sequence */
- lgi->lgi_fid.f_seq = FID_SEQ_LLOG;
- lgi->lgi_fid.f_oid = 1;
- lgi->lgi_fid.f_ver = 0;
- rc = local_oid_storage_init(env, disk_obd->obd_lvfs_ctxt.dt,
- &lgi->lgi_fid, &los);
- if (rc < 0)
- return rc;
-
- lgi->lgi_fid.f_seq = FID_SEQ_LLOG_NAME;
- lgi->lgi_fid.f_oid = 1;
- lgi->lgi_fid.f_ver = 0;
- rc = local_oid_storage_init(env, disk_obd->obd_lvfs_ctxt.dt,
- &lgi->lgi_fid, &los);
- llog_ctxt_put(ctxt);
- return rc;
-}
-
-static int llog_osd_cleanup(const struct lu_env *env, struct llog_ctxt *ctxt)
-{
- struct dt_device *dt;
- struct ls_device *ls;
- struct local_oid_storage *los, *nlos;
-
- LASSERT(ctxt->loc_exp->exp_obd);
- dt = ctxt->loc_exp->exp_obd->obd_lvfs_ctxt.dt;
- ls = ls_device_get(dt);
- if (IS_ERR(ls))
- return PTR_ERR(ls);
-
- mutex_lock(&ls->ls_los_mutex);
- los = dt_los_find(ls, FID_SEQ_LLOG);
- nlos = dt_los_find(ls, FID_SEQ_LLOG_NAME);
- mutex_unlock(&ls->ls_los_mutex);
- if (los != NULL) {
- dt_los_put(los);
- local_oid_storage_fini(env, los);
- }
- if (nlos != NULL) {
- dt_los_put(nlos);
- local_oid_storage_fini(env, nlos);
- }
- ls_device_put(env, ls);
- return 0;
-}
-
-struct llog_operations llog_osd_ops = {
- .lop_next_block = llog_osd_next_block,
- .lop_prev_block = llog_osd_prev_block,
- .lop_read_header = llog_osd_read_header,
- .lop_destroy = llog_osd_destroy,
- .lop_setup = llog_osd_setup,
- .lop_cleanup = llog_osd_cleanup,
- .lop_open = llog_osd_open,
- .lop_exist = llog_osd_exist,
- .lop_declare_create = llog_osd_declare_create,
- .lop_create = llog_osd_create,
- .lop_declare_write_rec = llog_osd_declare_write_rec,
- .lop_write_rec = llog_osd_write_rec,
- .lop_close = llog_osd_close,
-};
-EXPORT_SYMBOL(llog_osd_ops);
-
-/* reads the catalog list */
-int llog_osd_get_cat_list(const struct lu_env *env, struct dt_device *d,
- int idx, int count, struct llog_catid *idarray)
-{
- struct llog_thread_info *lgi = llog_info(env);
- struct dt_object *o = NULL;
- struct thandle *th;
- int rc, size;
-
- LASSERT(d);
-
- size = sizeof(*idarray) * count;
- lgi->lgi_off = idx * sizeof(*idarray);
-
- lu_local_obj_fid(&lgi->lgi_fid, LLOG_CATALOGS_OID);
-
- o = dt_locate(env, d, &lgi->lgi_fid);
- if (IS_ERR(o))
- return PTR_ERR(o);
-
- if (!dt_object_exists(o)) {
- th = dt_trans_create(env, d);
- if (IS_ERR(th))
- GOTO(out, rc = PTR_ERR(th));
-
- lgi->lgi_attr.la_valid = LA_MODE;
- lgi->lgi_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
- lgi->lgi_dof.dof_type = dt_mode_to_dft(S_IFREG);
-
- rc = dt_declare_create(env, o, &lgi->lgi_attr, NULL,
- &lgi->lgi_dof, th);
- if (rc)
- GOTO(out_trans, rc);
-
- rc = dt_trans_start_local(env, d, th);
- if (rc)
- GOTO(out_trans, rc);
-
- dt_write_lock(env, o, 0);
- if (!dt_object_exists(o))
- rc = dt_create(env, o, &lgi->lgi_attr, NULL,
- &lgi->lgi_dof, th);
- dt_write_unlock(env, o);
-out_trans:
- dt_trans_stop(env, d, th);
- if (rc)
- GOTO(out, rc);
- }
-
- rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA);
- if (rc)
- GOTO(out, rc);
-
- if (!S_ISREG(lgi->lgi_attr.la_mode)) {
- CERROR("%s: CATALOGS is not a regular file!: mode = %o\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- lgi->lgi_attr.la_mode);
- GOTO(out, rc = -ENOENT);
- }
-
- CDEBUG(D_CONFIG, "cat list: disk size=%d, read=%d\n",
- (int)lgi->lgi_attr.la_size, size);
-
- /* return just number of llogs */
- if (idarray == NULL) {
- rc = lgi->lgi_attr.la_size / sizeof(*idarray);
- GOTO(out, rc);
- }
-
- /* read for new ost index or for empty file */
- memset(idarray, 0, size);
- if (lgi->lgi_attr.la_size < lgi->lgi_off + size)
- GOTO(out, rc = 0);
- if (lgi->lgi_attr.la_size < lgi->lgi_off + size)
- size = lgi->lgi_attr.la_size - lgi->lgi_off;
-
- lgi->lgi_buf.lb_buf = idarray;
- lgi->lgi_buf.lb_len = size;
- rc = dt_record_read(env, o, &lgi->lgi_buf, &lgi->lgi_off);
- if (rc) {
- CERROR("%s: error reading CATALOGS: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name, rc);
- GOTO(out, rc);
- }
-
-out:
- lu_object_put(env, &o->do_lu);
- return rc;
-}
-EXPORT_SYMBOL(llog_osd_get_cat_list);
-
-/* writes the cat list */
-int llog_osd_put_cat_list(const struct lu_env *env, struct dt_device *d,
- int idx, int count, struct llog_catid *idarray)
-{
- struct llog_thread_info *lgi = llog_info(env);
- struct dt_object *o = NULL;
- struct thandle *th;
- int rc, size;
-
- if (!count)
- return 0;
-
- LASSERT(d);
-
- size = sizeof(*idarray) * count;
- lgi->lgi_off = idx * sizeof(*idarray);
-
- lu_local_obj_fid(&lgi->lgi_fid, LLOG_CATALOGS_OID);
-
- o = dt_locate(env, d, &lgi->lgi_fid);
- if (IS_ERR(o))
- return PTR_ERR(o);
-
- if (!dt_object_exists(o))
- GOTO(out, rc = -ENOENT);
-
- rc = dt_attr_get(env, o, &lgi->lgi_attr, BYPASS_CAPA);
- if (rc)
- GOTO(out, rc);
-
- if (!S_ISREG(lgi->lgi_attr.la_mode)) {
- CERROR("%s: CATALOGS is not a regular file!: mode = %o\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- lgi->lgi_attr.la_mode);
- GOTO(out, rc = -ENOENT);
- }
-
- th = dt_trans_create(env, d);
- if (IS_ERR(th))
- GOTO(out, rc = PTR_ERR(th));
-
- rc = dt_declare_record_write(env, o, size, lgi->lgi_off, th);
- if (rc)
- GOTO(out, rc);
-
- rc = dt_trans_start_local(env, d, th);
- if (rc)
- GOTO(out_trans, rc);
-
- lgi->lgi_buf.lb_buf = idarray;
- lgi->lgi_buf.lb_len = size;
- rc = dt_record_write(env, o, &lgi->lgi_buf, &lgi->lgi_off, th);
- if (rc)
- CDEBUG(D_INODE, "error writing CATALOGS: rc = %d\n", rc);
-out_trans:
- dt_trans_stop(env, d, th);
-out:
- lu_object_put(env, &o->do_lu);
- return rc;
-}
-EXPORT_SYMBOL(llog_osd_put_cat_list);
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_swab.c b/drivers/staging/lustre/lustre/obdclass/llog_swab.c
index b3247fb7a35a..bfac8387021e 100644
--- a/drivers/staging/lustre/lustre/obdclass/llog_swab.c
+++ b/drivers/staging/lustre/lustre/obdclass/llog_swab.c
@@ -61,9 +61,9 @@ static void print_llogd_body(struct llogd_body *d)
void lustre_swab_lu_fid(struct lu_fid *fid)
{
- __swab64s (&fid->f_seq);
- __swab32s (&fid->f_oid);
- __swab32s (&fid->f_ver);
+ __swab64s(&fid->f_seq);
+ __swab32s(&fid->f_oid);
+ __swab32s(&fid->f_ver);
}
EXPORT_SYMBOL(lustre_swab_lu_fid);
@@ -82,47 +82,47 @@ void lustre_swab_llog_id(struct llog_logid *log_id)
{
__swab64s(&log_id->lgl_oi.oi.oi_id);
__swab64s(&log_id->lgl_oi.oi.oi_seq);
- __swab32s(&log_id->lgl_ogen);
+ __swab32s(&log_id->lgl_ogen);
}
EXPORT_SYMBOL(lustre_swab_llog_id);
-void lustre_swab_llogd_body (struct llogd_body *d)
+void lustre_swab_llogd_body(struct llogd_body *d)
{
print_llogd_body(d);
lustre_swab_llog_id(&d->lgd_logid);
- __swab32s (&d->lgd_ctxt_idx);
- __swab32s (&d->lgd_llh_flags);
- __swab32s (&d->lgd_index);
- __swab32s (&d->lgd_saved_index);
- __swab32s (&d->lgd_len);
- __swab64s (&d->lgd_cur_offset);
+ __swab32s(&d->lgd_ctxt_idx);
+ __swab32s(&d->lgd_llh_flags);
+ __swab32s(&d->lgd_index);
+ __swab32s(&d->lgd_saved_index);
+ __swab32s(&d->lgd_len);
+ __swab64s(&d->lgd_cur_offset);
print_llogd_body(d);
}
EXPORT_SYMBOL(lustre_swab_llogd_body);
-void lustre_swab_llogd_conn_body (struct llogd_conn_body *d)
+void lustre_swab_llogd_conn_body(struct llogd_conn_body *d)
{
- __swab64s (&d->lgdc_gen.mnt_cnt);
- __swab64s (&d->lgdc_gen.conn_cnt);
+ __swab64s(&d->lgdc_gen.mnt_cnt);
+ __swab64s(&d->lgdc_gen.conn_cnt);
lustre_swab_llog_id(&d->lgdc_logid);
- __swab32s (&d->lgdc_ctxt_idx);
+ __swab32s(&d->lgdc_ctxt_idx);
}
EXPORT_SYMBOL(lustre_swab_llogd_conn_body);
void lustre_swab_ll_fid(struct ll_fid *fid)
{
- __swab64s (&fid->id);
- __swab32s (&fid->generation);
- __swab32s (&fid->f_type);
+ __swab64s(&fid->id);
+ __swab32s(&fid->generation);
+ __swab32s(&fid->f_type);
}
EXPORT_SYMBOL(lustre_swab_ll_fid);
void lustre_swab_lu_seq_range(struct lu_seq_range *range)
{
- __swab64s (&range->lsr_start);
- __swab64s (&range->lsr_end);
- __swab32s (&range->lsr_index);
- __swab32s (&range->lsr_flags);
+ __swab64s(&range->lsr_start);
+ __swab64s(&range->lsr_end);
+ __swab32s(&range->lsr_index);
+ __swab32s(&range->lsr_flags);
}
EXPORT_SYMBOL(lustre_swab_lu_seq_range);
@@ -168,7 +168,7 @@ void lustre_swab_llog_rec(struct llog_rec_hdr *rec)
}
case CHANGELOG_REC:
{
- struct llog_changelog_rec *cr = (struct llog_changelog_rec*)rec;
+ struct llog_changelog_rec *cr = (struct llog_changelog_rec *)rec;
__swab16s(&cr->cr.cr_namelen);
__swab16s(&cr->cr.cr_flags);
@@ -193,7 +193,7 @@ void lustre_swab_llog_rec(struct llog_rec_hdr *rec)
case CHANGELOG_USER_REC:
{
struct llog_changelog_user_rec *cur =
- (struct llog_changelog_user_rec*)rec;
+ (struct llog_changelog_user_rec *)rec;
__swab32s(&cur->cur_id);
__swab64s(&cur->cur_endrec);
@@ -294,7 +294,7 @@ static void print_llog_hdr(struct llog_log_hdr *h)
CDEBUG(D_OTHER, "\tllh_tail.lrt_len: %#x\n", h->llh_tail.lrt_len);
}
-void lustre_swab_llog_hdr (struct llog_log_hdr *h)
+void lustre_swab_llog_hdr(struct llog_log_hdr *h)
{
print_llog_hdr(h);
@@ -367,7 +367,7 @@ struct cfg_marker32 {
void lustre_swab_cfg_marker(struct cfg_marker *marker, int swab, int size)
{
- struct cfg_marker32 *cm32 = (struct cfg_marker32*)marker;
+ struct cfg_marker32 *cm32 = (struct cfg_marker32 *)marker;
if (swab) {
__swab32s(&marker->cm_step);
diff --git a/drivers/staging/lustre/lustre/obdclass/llog_test.c b/drivers/staging/lustre/lustre/obdclass/llog_test.c
deleted file mode 100644
index ef008abd331c..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/llog_test.c
+++ /dev/null
@@ -1,1072 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/obdclass/llog_test.c
- *
- * Author: Phil Schwan <phil@clusterfs.com>
- * Author: Mikhail Pershin <mike.pershin@intel.com>
- */
-
-#define DEBUG_SUBSYSTEM S_CLASS
-
-#include <linux/module.h>
-#include <linux/init.h>
-
-#include "../include/obd_class.h"
-#include "../include/lustre_fid.h"
-#include "../include/lustre_log.h"
-
-/* This is slightly more than the number of records that can fit into a
- * single llog file, because the llog_log_header takes up some of the
- * space in the first block that cannot be used for the bitmap. */
-#define LLOG_TEST_RECNUM (LLOG_CHUNK_SIZE * 8)
-
-static int llog_test_rand;
-static struct obd_uuid uuid = { .uuid = "test_uuid" };
-static struct llog_logid cat_logid;
-
-struct llog_mini_rec {
- struct llog_rec_hdr lmr_hdr;
- struct llog_rec_tail lmr_tail;
-} __attribute__((packed));
-
-static int verify_handle(char *test, struct llog_handle *llh, int num_recs)
-{
- int i;
- int last_idx = 0;
- int active_recs = 0;
-
- for (i = 0; i < LLOG_BITMAP_BYTES * 8; i++) {
- if (ext2_test_bit(i, llh->lgh_hdr->llh_bitmap)) {
- last_idx = i;
- active_recs++;
- }
- }
-
- if (active_recs != num_recs) {
- CERROR("%s: expected %d active recs after write, found %d\n",
- test, num_recs, active_recs);
- return -ERANGE;
- }
-
- if (llh->lgh_hdr->llh_count != num_recs) {
- CERROR("%s: handle->count is %d, expected %d after write\n",
- test, llh->lgh_hdr->llh_count, num_recs);
- return -ERANGE;
- }
-
- if (llh->lgh_last_idx < last_idx) {
- CERROR("%s: handle->last_idx is %d, expected %d after write\n",
- test, llh->lgh_last_idx, last_idx);
- return -ERANGE;
- }
-
- return 0;
-}
-
-/* Test named-log create/open, close */
-static int llog_test_1(const struct lu_env *env,
- struct obd_device *obd, char *name)
-{
- struct llog_handle *llh;
- struct llog_ctxt *ctxt;
- int rc;
- int rc2;
-
- CWARN("1a: create a log with name: %s\n", name);
- ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
- LASSERT(ctxt);
-
- rc = llog_open_create(env, ctxt, &llh, NULL, name);
- if (rc) {
- CERROR("1a: llog_create with name %s failed: %d\n", name, rc);
- GOTO(out, rc);
- }
- rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, &uuid);
- if (rc) {
- CERROR("1a: can't init llog handle: %d\n", rc);
- GOTO(out_close, rc);
- }
-
- rc = verify_handle("1", llh, 1);
-
- CWARN("1b: close newly-created log\n");
-out_close:
- rc2 = llog_close(env, llh);
- if (rc2) {
- CERROR("1b: close log %s failed: %d\n", name, rc2);
- if (rc == 0)
- rc = rc2;
- }
-out:
- llog_ctxt_put(ctxt);
- return rc;
-}
-
-/* Test named-log reopen; returns opened log on success */
-static int llog_test_2(const struct lu_env *env, struct obd_device *obd,
- char *name, struct llog_handle **llh)
-{
- struct llog_ctxt *ctxt;
- struct llog_handle *loghandle;
- struct llog_logid logid;
- int rc;
-
- CWARN("2a: re-open a log with name: %s\n", name);
- ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
- LASSERT(ctxt);
-
- rc = llog_open(env, ctxt, llh, NULL, name, LLOG_OPEN_EXISTS);
- if (rc) {
- CERROR("2a: re-open log with name %s failed: %d\n", name, rc);
- GOTO(out_put, rc);
- }
-
- rc = llog_init_handle(env, *llh, LLOG_F_IS_PLAIN, &uuid);
- if (rc) {
- CERROR("2a: can't init llog handle: %d\n", rc);
- GOTO(out_close_llh, rc);
- }
-
- rc = verify_handle("2", *llh, 1);
- if (rc)
- GOTO(out_close_llh, rc);
-
- /* XXX: there is known issue with tests 2b, MGS is not able to create
- * anonymous llog, exit now to allow following tests run.
- * It is fixed in upcoming llog over OSD code */
- GOTO(out_put, rc);
-
- CWARN("2b: create a log without specified NAME & LOGID\n");
- rc = llog_open_create(env, ctxt, &loghandle, NULL, NULL);
- if (rc) {
- CERROR("2b: create log failed\n");
- GOTO(out_close_llh, rc);
- }
- rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, &uuid);
- if (rc) {
- CERROR("2b: can't init llog handle: %d\n", rc);
- GOTO(out_close, rc);
- }
-
- logid = loghandle->lgh_id;
- llog_close(env, loghandle);
-
- CWARN("2c: re-open the log by LOGID\n");
- rc = llog_open(env, ctxt, &loghandle, &logid, NULL, LLOG_OPEN_EXISTS);
- if (rc) {
- CERROR("2c: re-open log by LOGID failed\n");
- GOTO(out_close_llh, rc);
- }
-
- rc = llog_init_handle(env, loghandle, LLOG_F_IS_PLAIN, &uuid);
- if (rc) {
- CERROR("2c: can't init llog handle: %d\n", rc);
- GOTO(out_close, rc);
- }
-
- CWARN("2b: destroy this log\n");
- rc = llog_destroy(env, loghandle);
- if (rc)
- CERROR("2d: destroy log failed\n");
-out_close:
- llog_close(env, loghandle);
-out_close_llh:
- if (rc)
- llog_close(env, *llh);
-out_put:
- llog_ctxt_put(ctxt);
-
- return rc;
-}
-
-/* Test record writing, single and in bulk */
-static int llog_test_3(const struct lu_env *env, struct obd_device *obd,
- struct llog_handle *llh)
-{
- struct llog_gen_rec lgr;
- int rc, i;
- int num_recs = 1; /* 1 for the header */
-
- lgr.lgr_hdr.lrh_len = lgr.lgr_tail.lrt_len = sizeof(lgr);
- lgr.lgr_hdr.lrh_type = LLOG_GEN_REC;
-
- CWARN("3a: write one create_rec\n");
- rc = llog_write(env, llh, &lgr.lgr_hdr, NULL, 0, NULL, -1);
- num_recs++;
- if (rc < 0) {
- CERROR("3a: write one log record failed: %d\n", rc);
- return rc;
- }
-
- rc = verify_handle("3a", llh, num_recs);
- if (rc)
- return rc;
-
- CWARN("3b: write 10 cfg log records with 8 bytes bufs\n");
- for (i = 0; i < 10; i++) {
- struct llog_rec_hdr hdr;
- char buf[8];
-
- hdr.lrh_len = 8;
- hdr.lrh_type = OBD_CFG_REC;
- memset(buf, 0, sizeof(buf));
- rc = llog_write(env, llh, &hdr, NULL, 0, buf, -1);
- if (rc < 0) {
- CERROR("3b: write 10 records failed at #%d: %d\n",
- i + 1, rc);
- return rc;
- }
- num_recs++;
- }
-
- rc = verify_handle("3b", llh, num_recs);
- if (rc)
- return rc;
-
- CWARN("3c: write 1000 more log records\n");
- for (i = 0; i < 1000; i++) {
- rc = llog_write(env, llh, &lgr.lgr_hdr, NULL, 0, NULL, -1);
- if (rc < 0) {
- CERROR("3c: write 1000 records failed at #%d: %d\n",
- i + 1, rc);
- return rc;
- }
- num_recs++;
- }
-
- rc = verify_handle("3c", llh, num_recs);
- if (rc)
- return rc;
-
- CWARN("3d: write log more than BITMAP_SIZE, return -ENOSPC\n");
- for (i = 0; i < LLOG_BITMAP_SIZE(llh->lgh_hdr) + 1; i++) {
- struct llog_rec_hdr hdr;
- char buf_even[24];
- char buf_odd[32];
-
- memset(buf_odd, 0, sizeof(buf_odd));
- memset(buf_even, 0, sizeof(buf_even));
- if ((i % 2) == 0) {
- hdr.lrh_len = 24;
- hdr.lrh_type = OBD_CFG_REC;
- rc = llog_write(env, llh, &hdr, NULL, 0, buf_even, -1);
- } else {
- hdr.lrh_len = 32;
- hdr.lrh_type = OBD_CFG_REC;
- rc = llog_write(env, llh, &hdr, NULL, 0, buf_odd, -1);
- }
- if (rc == -ENOSPC) {
- break;
- } else if (rc < 0) {
- CERROR("3d: write recs failed at #%d: %d\n",
- i + 1, rc);
- return rc;
- }
- num_recs++;
- }
- if (rc != -ENOSPC) {
- CWARN("3d: write record more than BITMAP size!\n");
- return -EINVAL;
- }
- CWARN("3d: wrote %d more records before end of llog is reached\n",
- num_recs);
-
- rc = verify_handle("3d", llh, num_recs);
-
- return rc;
-}
-
-/* Test catalogue additions */
-static int llog_test_4(const struct lu_env *env, struct obd_device *obd)
-{
- struct llog_handle *cath;
- char name[10];
- int rc, rc2, i, buflen;
- struct llog_mini_rec lmr;
- struct llog_cookie cookie;
- struct llog_ctxt *ctxt;
- int num_recs = 0;
- char *buf;
- struct llog_rec_hdr rec;
-
- ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
- LASSERT(ctxt);
-
- lmr.lmr_hdr.lrh_len = lmr.lmr_tail.lrt_len = LLOG_MIN_REC_SIZE;
- lmr.lmr_hdr.lrh_type = 0xf00f00;
-
- sprintf(name, "%x", llog_test_rand + 1);
- CWARN("4a: create a catalog log with name: %s\n", name);
- rc = llog_open_create(env, ctxt, &cath, NULL, name);
- if (rc) {
- CERROR("4a: llog_create with name %s failed: %d\n", name, rc);
- GOTO(ctxt_release, rc);
- }
- rc = llog_init_handle(env, cath, LLOG_F_IS_CAT, &uuid);
- if (rc) {
- CERROR("4a: can't init llog handle: %d\n", rc);
- GOTO(out, rc);
- }
-
- num_recs++;
- cat_logid = cath->lgh_id;
-
- CWARN("4b: write 1 record into the catalog\n");
- rc = llog_cat_add(env, cath, &lmr.lmr_hdr, &cookie, NULL);
- if (rc != 1) {
- CERROR("4b: write 1 catalog record failed at: %d\n", rc);
- GOTO(out, rc);
- }
- num_recs++;
- rc = verify_handle("4b", cath, 2);
- if (rc)
- GOTO(out, rc);
-
- rc = verify_handle("4b", cath->u.chd.chd_current_log, num_recs);
- if (rc)
- GOTO(out, rc);
-
- CWARN("4c: cancel 1 log record\n");
- rc = llog_cat_cancel_records(env, cath, 1, &cookie);
- if (rc) {
- CERROR("4c: cancel 1 catalog based record failed: %d\n", rc);
- GOTO(out, rc);
- }
- num_recs--;
-
- rc = verify_handle("4c", cath->u.chd.chd_current_log, num_recs);
- if (rc)
- GOTO(out, rc);
-
- CWARN("4d: write %d more log records\n", LLOG_TEST_RECNUM);
- for (i = 0; i < LLOG_TEST_RECNUM; i++) {
- rc = llog_cat_add(env, cath, &lmr.lmr_hdr, NULL, NULL);
- if (rc) {
- CERROR("4d: write %d records failed at #%d: %d\n",
- LLOG_TEST_RECNUM, i + 1, rc);
- GOTO(out, rc);
- }
- num_recs++;
- }
-
- /* make sure new plain llog appears */
- rc = verify_handle("4d", cath, 3);
- if (rc)
- GOTO(out, rc);
-
- CWARN("4e: add 5 large records, one record per block\n");
- buflen = LLOG_CHUNK_SIZE - sizeof(struct llog_rec_hdr) -
- sizeof(struct llog_rec_tail);
- OBD_ALLOC(buf, buflen);
- if (buf == NULL)
- GOTO(out, rc = -ENOMEM);
- for (i = 0; i < 5; i++) {
- rec.lrh_len = buflen;
- rec.lrh_type = OBD_CFG_REC;
- rc = llog_cat_add(env, cath, &rec, NULL, buf);
- if (rc) {
- CERROR("4e: write 5 records failed at #%d: %d\n",
- i + 1, rc);
- GOTO(out_free, rc);
- }
- num_recs++;
- }
-out_free:
- OBD_FREE(buf, buflen);
-out:
- CWARN("4f: put newly-created catalog\n");
- rc2 = llog_cat_close(env, cath);
- if (rc2) {
- CERROR("4: close log %s failed: %d\n", name, rc2);
- if (rc == 0)
- rc = rc2;
- }
-ctxt_release:
- llog_ctxt_put(ctxt);
- return rc;
-}
-
-static int cat_counter;
-
-static int cat_print_cb(const struct lu_env *env, struct llog_handle *llh,
- struct llog_rec_hdr *rec, void *data)
-{
- struct llog_logid_rec *lir = (struct llog_logid_rec *)rec;
- struct lu_fid fid = {0};
-
- if (rec->lrh_type != LLOG_LOGID_MAGIC) {
- CERROR("invalid record in catalog\n");
- return -EINVAL;
- }
-
- logid_to_fid(&lir->lid_id, &fid);
-
- CWARN("seeing record at index %d - "DFID" in log "DFID"\n",
- rec->lrh_index, PFID(&fid),
- PFID(lu_object_fid(&llh->lgh_obj->do_lu)));
-
- cat_counter++;
-
- return 0;
-}
-
-static int plain_counter;
-
-static int plain_print_cb(const struct lu_env *env, struct llog_handle *llh,
- struct llog_rec_hdr *rec, void *data)
-{
- struct lu_fid fid = {0};
-
- if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
- CERROR("log is not plain\n");
- return -EINVAL;
- }
-
- logid_to_fid(&llh->lgh_id, &fid);
-
- CDEBUG(D_INFO, "seeing record at index %d in log "DFID"\n",
- rec->lrh_index, PFID(&fid));
-
- plain_counter++;
-
- return 0;
-}
-
-static int cancel_count;
-
-static int llog_cancel_rec_cb(const struct lu_env *env,
- struct llog_handle *llh,
- struct llog_rec_hdr *rec, void *data)
-{
- struct llog_cookie cookie;
-
- if (!(llh->lgh_hdr->llh_flags & LLOG_F_IS_PLAIN)) {
- CERROR("log is not plain\n");
- return -EINVAL;
- }
-
- cookie.lgc_lgl = llh->lgh_id;
- cookie.lgc_index = rec->lrh_index;
-
- llog_cat_cancel_records(env, llh->u.phd.phd_cat_handle, 1, &cookie);
- cancel_count++;
- if (cancel_count == LLOG_TEST_RECNUM)
- return -LLOG_EEMPTY;
- return 0;
-}
-
-/* Test log and catalogue processing */
-static int llog_test_5(const struct lu_env *env, struct obd_device *obd)
-{
- struct llog_handle *llh = NULL;
- char name[10];
- int rc, rc2;
- struct llog_mini_rec lmr;
- struct llog_ctxt *ctxt;
-
- ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
- LASSERT(ctxt);
-
- lmr.lmr_hdr.lrh_len = lmr.lmr_tail.lrt_len = LLOG_MIN_REC_SIZE;
- lmr.lmr_hdr.lrh_type = 0xf00f00;
-
- CWARN("5a: re-open catalog by id\n");
- rc = llog_open(env, ctxt, &llh, &cat_logid, NULL, LLOG_OPEN_EXISTS);
- if (rc) {
- CERROR("5a: llog_create with logid failed: %d\n", rc);
- GOTO(out_put, rc);
- }
-
- rc = llog_init_handle(env, llh, LLOG_F_IS_CAT, &uuid);
- if (rc) {
- CERROR("5a: can't init llog handle: %d\n", rc);
- GOTO(out, rc);
- }
-
- CWARN("5b: print the catalog entries.. we expect 2\n");
- cat_counter = 0;
- rc = llog_process(env, llh, cat_print_cb, "test 5", NULL);
- if (rc) {
- CERROR("5b: process with cat_print_cb failed: %d\n", rc);
- GOTO(out, rc);
- }
- if (cat_counter != 2) {
- CERROR("5b: %d entries in catalog\n", cat_counter);
- GOTO(out, rc = -EINVAL);
- }
-
- CWARN("5c: Cancel %d records, see one log zapped\n", LLOG_TEST_RECNUM);
- cancel_count = 0;
- rc = llog_cat_process(env, llh, llog_cancel_rec_cb, "foobar", 0, 0);
- if (rc != -LLOG_EEMPTY) {
- CERROR("5c: process with cat_cancel_cb failed: %d\n", rc);
- GOTO(out, rc);
- }
-
- CWARN("5c: print the catalog entries.. we expect 1\n");
- cat_counter = 0;
- rc = llog_process(env, llh, cat_print_cb, "test 5", NULL);
- if (rc) {
- CERROR("5c: process with cat_print_cb failed: %d\n", rc);
- GOTO(out, rc);
- }
- if (cat_counter != 1) {
- CERROR("5c: %d entries in catalog\n", cat_counter);
- GOTO(out, rc = -EINVAL);
- }
-
- CWARN("5d: add 1 record to the log with many canceled empty pages\n");
- rc = llog_cat_add(env, llh, &lmr.lmr_hdr, NULL, NULL);
- if (rc) {
- CERROR("5d: add record to the log with many canceled empty "
- "pages failed\n");
- GOTO(out, rc);
- }
-
- CWARN("5e: print plain log entries.. expect 6\n");
- plain_counter = 0;
- rc = llog_cat_process(env, llh, plain_print_cb, "foobar", 0, 0);
- if (rc) {
- CERROR("5e: process with plain_print_cb failed: %d\n", rc);
- GOTO(out, rc);
- }
- if (plain_counter != 6) {
- CERROR("5e: found %d records\n", plain_counter);
- GOTO(out, rc = -EINVAL);
- }
-
- CWARN("5f: print plain log entries reversely.. expect 6\n");
- plain_counter = 0;
- rc = llog_cat_reverse_process(env, llh, plain_print_cb, "foobar");
- if (rc) {
- CERROR("5f: reversely process with plain_print_cb failed:"
- "%d\n", rc);
- GOTO(out, rc);
- }
- if (plain_counter != 6) {
- CERROR("5f: found %d records\n", plain_counter);
- GOTO(out, rc = -EINVAL);
- }
-
-out:
- CWARN("5g: close re-opened catalog\n");
- rc2 = llog_cat_close(env, llh);
- if (rc2) {
- CERROR("5g: close log %s failed: %d\n", name, rc2);
- if (rc == 0)
- rc = rc2;
- }
-out_put:
- llog_ctxt_put(ctxt);
-
- return rc;
-}
-
-/* Test client api; open log by name and process */
-static int llog_test_6(const struct lu_env *env, struct obd_device *obd,
- char *name)
-{
- struct obd_device *mgc_obd;
- struct llog_ctxt *ctxt;
- struct obd_uuid *mgs_uuid;
- struct obd_export *exp;
- struct obd_uuid uuid = { "LLOG_TEST6_UUID" };
- struct llog_handle *llh = NULL;
- struct llog_ctxt *nctxt;
- int rc, rc2;
-
- ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
- LASSERT(ctxt);
- mgs_uuid = &ctxt->loc_exp->exp_obd->obd_uuid;
-
- CWARN("6a: re-open log %s using client API\n", name);
- mgc_obd = class_find_client_obd(mgs_uuid, LUSTRE_MGC_NAME, NULL);
- if (mgc_obd == NULL) {
- CERROR("6a: no MGC devices connected to %s found.\n",
- mgs_uuid->uuid);
- GOTO(ctxt_release, rc = -ENOENT);
- }
-
- rc = obd_connect(NULL, &exp, mgc_obd, &uuid,
- NULL /* obd_connect_data */, NULL);
- if (rc != -EALREADY) {
- CERROR("6a: connect on connected MGC (%s) failed to return"
- " -EALREADY", mgc_obd->obd_name);
- if (rc == 0)
- obd_disconnect(exp);
- GOTO(ctxt_release, rc = -EINVAL);
- }
-
- nctxt = llog_get_context(mgc_obd, LLOG_CONFIG_REPL_CTXT);
- rc = llog_open(env, nctxt, &llh, NULL, name, LLOG_OPEN_EXISTS);
- if (rc) {
- CERROR("6a: llog_open failed %d\n", rc);
- GOTO(nctxt_put, rc);
- }
-
- rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
- if (rc) {
- CERROR("6a: llog_init_handle failed %d\n", rc);
- GOTO(parse_out, rc);
- }
-
- plain_counter = 1; /* llog header is first record */
- CWARN("6b: process log %s using client API\n", name);
- rc = llog_process(env, llh, plain_print_cb, NULL, NULL);
- if (rc)
- CERROR("6b: llog_process failed %d\n", rc);
- CWARN("6b: processed %d records\n", plain_counter);
-
- rc = verify_handle("6b", llh, plain_counter);
- if (rc)
- GOTO(parse_out, rc);
-
- plain_counter = 1; /* llog header is first record */
- CWARN("6c: process log %s reversely using client API\n", name);
- rc = llog_reverse_process(env, llh, plain_print_cb, NULL, NULL);
- if (rc)
- CERROR("6c: llog_reverse_process failed %d\n", rc);
- CWARN("6c: processed %d records\n", plain_counter);
-
- rc = verify_handle("6c", llh, plain_counter);
- if (rc)
- GOTO(parse_out, rc);
-
-parse_out:
- rc2 = llog_close(env, llh);
- if (rc2) {
- CERROR("6: llog_close failed: rc = %d\n", rc2);
- if (rc == 0)
- rc = rc2;
- }
-nctxt_put:
- llog_ctxt_put(nctxt);
-ctxt_release:
- llog_ctxt_put(ctxt);
- return rc;
-}
-
-static union {
- struct llog_rec_hdr lrh; /* common header */
- struct llog_logid_rec llr; /* LLOG_LOGID_MAGIC */
- struct llog_unlink64_rec lur; /* MDS_UNLINK64_REC */
- struct llog_setattr64_rec lsr64; /* MDS_SETATTR64_REC */
- struct llog_size_change_rec lscr; /* OST_SZ_REC */
- struct llog_changelog_rec lcr; /* CHANGELOG_REC */
- struct llog_changelog_user_rec lcur; /* CHANGELOG_USER_REC */
- struct llog_gen_rec lgr; /* LLOG_GEN_REC */
-} llog_records;
-
-static int test_7_print_cb(const struct lu_env *env, struct llog_handle *llh,
- struct llog_rec_hdr *rec, void *data)
-{
- struct lu_fid fid = {0};
-
- logid_to_fid(&llh->lgh_id, &fid);
-
- CDEBUG(D_OTHER, "record type %#x at index %d in log "DFID"\n",
- rec->lrh_type, rec->lrh_index, PFID(&fid));
-
- plain_counter++;
- return 0;
-}
-
-static int test_7_cancel_cb(const struct lu_env *env, struct llog_handle *llh,
- struct llog_rec_hdr *rec, void *data)
-{
- plain_counter++;
- /* test LLOG_DEL_RECORD is working */
- return LLOG_DEL_RECORD;
-}
-
-static int llog_test_7_sub(const struct lu_env *env, struct llog_ctxt *ctxt)
-{
- struct llog_handle *llh;
- int rc = 0, i, process_count;
- int num_recs = 0;
-
- rc = llog_open_create(env, ctxt, &llh, NULL, NULL);
- if (rc) {
- CERROR("7_sub: create log failed\n");
- return rc;
- }
-
- rc = llog_init_handle(env, llh,
- LLOG_F_IS_PLAIN | LLOG_F_ZAP_WHEN_EMPTY,
- &uuid);
- if (rc) {
- CERROR("7_sub: can't init llog handle: %d\n", rc);
- GOTO(out_close, rc);
- }
- for (i = 0; i < LLOG_BITMAP_SIZE(llh->lgh_hdr); i++) {
- rc = llog_write(env, llh, &llog_records.lrh, NULL, 0,
- NULL, -1);
- if (rc == -ENOSPC) {
- break;
- } else if (rc < 0) {
- CERROR("7_sub: write recs failed at #%d: %d\n",
- i + 1, rc);
- GOTO(out_close, rc);
- }
- num_recs++;
- }
- if (rc != -ENOSPC) {
- CWARN("7_sub: write record more than BITMAP size!\n");
- GOTO(out_close, rc = -EINVAL);
- }
-
- rc = verify_handle("7_sub", llh, num_recs + 1);
- if (rc) {
- CERROR("7_sub: verify handle failed: %d\n", rc);
- GOTO(out_close, rc);
- }
- if (num_recs < LLOG_BITMAP_SIZE(llh->lgh_hdr) - 1)
- CWARN("7_sub: records are not aligned, written %d from %u\n",
- num_recs, LLOG_BITMAP_SIZE(llh->lgh_hdr) - 1);
-
- plain_counter = 0;
- rc = llog_process(env, llh, test_7_print_cb, "test 7", NULL);
- if (rc) {
- CERROR("7_sub: llog process failed: %d\n", rc);
- GOTO(out_close, rc);
- }
- process_count = plain_counter;
- if (process_count != num_recs) {
- CERROR("7_sub: processed %d records from %d total\n",
- process_count, num_recs);
- GOTO(out_close, rc = -EINVAL);
- }
-
- plain_counter = 0;
- rc = llog_reverse_process(env, llh, test_7_cancel_cb, "test 7", NULL);
- if (rc) {
- CERROR("7_sub: reverse llog process failed: %d\n", rc);
- GOTO(out_close, rc);
- }
- if (process_count != plain_counter) {
- CERROR("7_sub: Reverse/direct processing found different"
- "number of records: %d/%d\n",
- plain_counter, process_count);
- GOTO(out_close, rc = -EINVAL);
- }
- if (llog_exist(llh)) {
- CERROR("7_sub: llog exists but should be zapped\n");
- GOTO(out_close, rc = -EEXIST);
- }
-
- rc = verify_handle("7_sub", llh, 1);
-out_close:
- if (rc)
- llog_destroy(env, llh);
- llog_close(env, llh);
- return rc;
-}
-
-/* Test all llog records writing and processing */
-static int llog_test_7(const struct lu_env *env, struct obd_device *obd)
-{
- struct llog_ctxt *ctxt;
- int rc;
-
- ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
-
- CWARN("7a: test llog_logid_rec\n");
- llog_records.llr.lid_hdr.lrh_len = sizeof(llog_records.llr);
- llog_records.llr.lid_tail.lrt_len = sizeof(llog_records.llr);
- llog_records.llr.lid_hdr.lrh_type = LLOG_LOGID_MAGIC;
-
- rc = llog_test_7_sub(env, ctxt);
- if (rc) {
- CERROR("7a: llog_logid_rec test failed\n");
- GOTO(out, rc);
- }
-
- CWARN("7b: test llog_unlink64_rec\n");
- llog_records.lur.lur_hdr.lrh_len = sizeof(llog_records.lur);
- llog_records.lur.lur_tail.lrt_len = sizeof(llog_records.lur);
- llog_records.lur.lur_hdr.lrh_type = MDS_UNLINK64_REC;
-
- rc = llog_test_7_sub(env, ctxt);
- if (rc) {
- CERROR("7b: llog_unlink_rec test failed\n");
- GOTO(out, rc);
- }
-
- CWARN("7c: test llog_setattr64_rec\n");
- llog_records.lsr64.lsr_hdr.lrh_len = sizeof(llog_records.lsr64);
- llog_records.lsr64.lsr_tail.lrt_len = sizeof(llog_records.lsr64);
- llog_records.lsr64.lsr_hdr.lrh_type = MDS_SETATTR64_REC;
-
- rc = llog_test_7_sub(env, ctxt);
- if (rc) {
- CERROR("7c: llog_setattr64_rec test failed\n");
- GOTO(out, rc);
- }
-
- CWARN("7d: test llog_size_change_rec\n");
- llog_records.lscr.lsc_hdr.lrh_len = sizeof(llog_records.lscr);
- llog_records.lscr.lsc_tail.lrt_len = sizeof(llog_records.lscr);
- llog_records.lscr.lsc_hdr.lrh_type = OST_SZ_REC;
-
- rc = llog_test_7_sub(env, ctxt);
- if (rc) {
- CERROR("7d: llog_size_change_rec test failed\n");
- GOTO(out, rc);
- }
-
- CWARN("7e: test llog_changelog_rec\n");
- llog_records.lcr.cr_hdr.lrh_len = sizeof(llog_records.lcr);
- llog_records.lcr.cr_tail.lrt_len = sizeof(llog_records.lcr);
- llog_records.lcr.cr_hdr.lrh_type = CHANGELOG_REC;
-
- rc = llog_test_7_sub(env, ctxt);
- if (rc) {
- CERROR("7e: llog_changelog_rec test failed\n");
- GOTO(out, rc);
- }
-
- CWARN("7f: test llog_changelog_user_rec\n");
- llog_records.lcur.cur_hdr.lrh_len = sizeof(llog_records.lcur);
- llog_records.lcur.cur_tail.lrt_len = sizeof(llog_records.lcur);
- llog_records.lcur.cur_hdr.lrh_type = CHANGELOG_USER_REC;
-
- rc = llog_test_7_sub(env, ctxt);
- if (rc) {
- CERROR("7f: llog_changelog_user_rec test failed\n");
- GOTO(out, rc);
- }
-
- CWARN("7g: test llog_gen_rec\n");
- llog_records.lgr.lgr_hdr.lrh_len = sizeof(llog_records.lgr);
- llog_records.lgr.lgr_tail.lrt_len = sizeof(llog_records.lgr);
- llog_records.lgr.lgr_hdr.lrh_type = LLOG_GEN_REC;
-
- rc = llog_test_7_sub(env, ctxt);
- if (rc) {
- CERROR("7g: llog_size_change_rec test failed\n");
- GOTO(out, rc);
- }
-out:
- llog_ctxt_put(ctxt);
- return rc;
-}
-
-/* -------------------------------------------------------------------------
- * Tests above, boring obd functions below
- * ------------------------------------------------------------------------- */
-static int llog_run_tests(const struct lu_env *env, struct obd_device *obd)
-{
- struct llog_handle *llh = NULL;
- struct llog_ctxt *ctxt;
- int rc, err;
- char name[10];
-
- ctxt = llog_get_context(obd, LLOG_TEST_ORIG_CTXT);
- LASSERT(ctxt);
-
- sprintf(name, "%x", llog_test_rand);
-
- rc = llog_test_1(env, obd, name);
- if (rc)
- GOTO(cleanup_ctxt, rc);
-
- rc = llog_test_2(env, obd, name, &llh);
- if (rc)
- GOTO(cleanup_ctxt, rc);
-
- rc = llog_test_3(env, obd, llh);
- if (rc)
- GOTO(cleanup, rc);
-
- rc = llog_test_4(env, obd);
- if (rc)
- GOTO(cleanup, rc);
-
- rc = llog_test_5(env, obd);
- if (rc)
- GOTO(cleanup, rc);
-
- rc = llog_test_6(env, obd, name);
- if (rc)
- GOTO(cleanup, rc);
-
- rc = llog_test_7(env, obd);
- if (rc)
- GOTO(cleanup, rc);
-
-cleanup:
- err = llog_destroy(env, llh);
- if (err)
- CERROR("cleanup: llog_destroy failed: %d\n", err);
- llog_close(env, llh);
- if (rc == 0)
- rc = err;
-cleanup_ctxt:
- llog_ctxt_put(ctxt);
- return rc;
-}
-
-#if defined (CONFIG_PROC_FS)
-static struct lprocfs_vars lprocfs_llog_test_obd_vars[] = { { NULL } };
-static struct lprocfs_vars lprocfs_llog_test_module_vars[] = { { NULL } };
-static void lprocfs_llog_test_init_vars(struct lprocfs_static_vars *lvars)
-{
- lvars->module_vars = lprocfs_llog_test_module_vars;
- lvars->obd_vars = lprocfs_llog_test_obd_vars;
-}
-#else
-static void lprocfs_llog_test_init_vars(struct lprocfs_static_vars *lvars)
-{
-}
-#endif
-
-static int llog_test_cleanup(struct obd_device *obd)
-{
- struct obd_device *tgt;
- struct lu_env env;
- int rc;
-
- rc = lu_env_init(&env, LCT_LOCAL | LCT_MG_THREAD);
- if (rc)
- return rc;
-
- tgt = obd->obd_lvfs_ctxt.dt->dd_lu_dev.ld_obd;
- rc = llog_cleanup(&env, llog_get_context(tgt, LLOG_TEST_ORIG_CTXT));
- if (rc)
- CERROR("failed to llog_test_llog_finish: %d\n", rc);
- lu_env_fini(&env);
- return rc;
-}
-
-static int llog_test_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
-{
- struct obd_device *tgt;
- struct llog_ctxt *ctxt;
- struct dt_object *o;
- struct lu_env env;
- struct lu_context test_session;
- int rc;
-
- if (lcfg->lcfg_bufcount < 2) {
- CERROR("requires a TARGET OBD name\n");
- return -EINVAL;
- }
-
- if (lcfg->lcfg_buflens[1] < 1) {
- CERROR("requires a TARGET OBD name\n");
- return -EINVAL;
- }
-
- /* disk obd */
- tgt = class_name2obd(lustre_cfg_string(lcfg, 1));
- if (!tgt || !tgt->obd_attached || !tgt->obd_set_up) {
- CERROR("target device not attached or not set up (%s)\n",
- lustre_cfg_string(lcfg, 1));
- return -EINVAL;
- }
-
- rc = lu_env_init(&env, LCT_LOCAL | LCT_MG_THREAD);
- if (rc)
- return rc;
-
- rc = lu_context_init(&test_session, LCT_SESSION);
- if (rc)
- GOTO(cleanup_env, rc);
- test_session.lc_thread = (struct ptlrpc_thread *)current;
- lu_context_enter(&test_session);
- env.le_ses = &test_session;
-
- CWARN("Setup llog-test device over %s device\n",
- lustre_cfg_string(lcfg, 1));
-
- OBD_SET_CTXT_MAGIC(&obd->obd_lvfs_ctxt);
- obd->obd_lvfs_ctxt.dt = lu2dt_dev(tgt->obd_lu_dev);
-
- rc = llog_setup(&env, tgt, &tgt->obd_olg, LLOG_TEST_ORIG_CTXT, tgt,
- &llog_osd_ops);
- if (rc)
- GOTO(cleanup_session, rc);
-
- /* use MGS llog dir for tests */
- ctxt = llog_get_context(tgt, LLOG_CONFIG_ORIG_CTXT);
- LASSERT(ctxt);
- o = ctxt->loc_dir;
- llog_ctxt_put(ctxt);
-
- ctxt = llog_get_context(tgt, LLOG_TEST_ORIG_CTXT);
- LASSERT(ctxt);
- ctxt->loc_dir = o;
- llog_ctxt_put(ctxt);
-
- llog_test_rand = cfs_rand();
-
- rc = llog_run_tests(&env, tgt);
- if (rc)
- llog_test_cleanup(obd);
-cleanup_session:
- lu_context_exit(&test_session);
- lu_context_fini(&test_session);
-cleanup_env:
- lu_env_fini(&env);
- return rc;
-}
-
-static struct obd_ops llog_obd_ops = {
- .o_owner = THIS_MODULE,
- .o_setup = llog_test_setup,
- .o_cleanup = llog_test_cleanup,
-};
-
-static int __init llog_test_init(void)
-{
- struct lprocfs_static_vars uninitialized_var(lvars);
-
- lprocfs_llog_test_init_vars(&lvars);
- return class_register_type(&llog_obd_ops, NULL,
- lvars.module_vars, "llog_test", NULL);
-}
-
-static void __exit llog_test_exit(void)
-{
- class_unregister_type("llog_test");
-}
-
-MODULE_AUTHOR("Sun Microsystems, Inc. <http://www.lustre.org/>");
-MODULE_DESCRIPTION("llog test module");
-MODULE_LICENSE("GPL");
-
-module_init(llog_test_init);
-module_exit(llog_test_exit);
diff --git a/drivers/staging/lustre/lustre/obdclass/local_storage.c b/drivers/staging/lustre/lustre/obdclass/local_storage.c
deleted file mode 100644
index 78190225ac7a..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/local_storage.c
+++ /dev/null
@@ -1,894 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License version 2 for more details. A copy is
- * included in the COPYING file that accompanied this code.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * lustre/obdclass/local_storage.c
- *
- * Local storage for file/objects with fid generation. Works on top of OSD.
- *
- * Author: Mikhail Pershin <mike.pershin@intel.com>
- */
-
-#define DEBUG_SUBSYSTEM S_CLASS
-
-#include "local_storage.h"
-
-/* all initialized local storages on this node are linked on this */
-static LIST_HEAD(ls_list_head);
-static DEFINE_MUTEX(ls_list_mutex);
-
-static int ls_object_init(const struct lu_env *env, struct lu_object *o,
- const struct lu_object_conf *unused)
-{
- struct ls_device *ls;
- struct lu_object *below;
- struct lu_device *under;
-
- ls = container_of0(o->lo_dev, struct ls_device, ls_top_dev.dd_lu_dev);
- under = &ls->ls_osd->dd_lu_dev;
- below = under->ld_ops->ldo_object_alloc(env, o->lo_header, under);
- if (below == NULL)
- return -ENOMEM;
-
- lu_object_add(o, below);
-
- return 0;
-}
-
-static void ls_object_free(const struct lu_env *env, struct lu_object *o)
-{
- struct ls_object *obj = lu2ls_obj(o);
- struct lu_object_header *h = o->lo_header;
-
- dt_object_fini(&obj->ls_obj);
- lu_object_header_fini(h);
- OBD_FREE_PTR(obj);
-}
-
-struct lu_object_operations ls_lu_obj_ops = {
- .loo_object_init = ls_object_init,
- .loo_object_free = ls_object_free,
-};
-
-struct lu_object *ls_object_alloc(const struct lu_env *env,
- const struct lu_object_header *_h,
- struct lu_device *d)
-{
- struct lu_object_header *h;
- struct ls_object *o;
- struct lu_object *l;
-
- LASSERT(_h == NULL);
-
- OBD_ALLOC_PTR(o);
- if (o != NULL) {
- l = &o->ls_obj.do_lu;
- h = &o->ls_header;
-
- lu_object_header_init(h);
- dt_object_init(&o->ls_obj, h, d);
- lu_object_add_top(h, l);
-
- l->lo_ops = &ls_lu_obj_ops;
-
- return l;
- } else {
- return NULL;
- }
-}
-
-static struct lu_device_operations ls_lu_dev_ops = {
- .ldo_object_alloc = ls_object_alloc
-};
-
-static struct ls_device *__ls_find_dev(struct dt_device *dev)
-{
- struct ls_device *ls, *ret = NULL;
-
- list_for_each_entry(ls, &ls_list_head, ls_linkage) {
- if (ls->ls_osd == dev) {
- atomic_inc(&ls->ls_refcount);
- ret = ls;
- break;
- }
- }
- return ret;
-}
-
-struct ls_device *ls_find_dev(struct dt_device *dev)
-{
- struct ls_device *ls;
-
- mutex_lock(&ls_list_mutex);
- ls = __ls_find_dev(dev);
- mutex_unlock(&ls_list_mutex);
-
- return ls;
-}
-
-static struct lu_device_type_operations ls_device_type_ops = {
- .ldto_start = NULL,
- .ldto_stop = NULL,
-};
-
-static struct lu_device_type ls_lu_type = {
- .ldt_name = "local_storage",
- .ldt_ops = &ls_device_type_ops,
-};
-
-struct ls_device *ls_device_get(struct dt_device *dev)
-{
- struct ls_device *ls;
-
- mutex_lock(&ls_list_mutex);
- ls = __ls_find_dev(dev);
- if (ls)
- GOTO(out_ls, ls);
-
- /* not found, then create */
- OBD_ALLOC_PTR(ls);
- if (ls == NULL)
- GOTO(out_ls, ls = ERR_PTR(-ENOMEM));
-
- atomic_set(&ls->ls_refcount, 1);
- INIT_LIST_HEAD(&ls->ls_los_list);
- mutex_init(&ls->ls_los_mutex);
-
- ls->ls_osd = dev;
-
- LASSERT(dev->dd_lu_dev.ld_site);
- lu_device_init(&ls->ls_top_dev.dd_lu_dev, &ls_lu_type);
- ls->ls_top_dev.dd_lu_dev.ld_ops = &ls_lu_dev_ops;
- ls->ls_top_dev.dd_lu_dev.ld_site = dev->dd_lu_dev.ld_site;
-
- /* finally add ls to the list */
- list_add(&ls->ls_linkage, &ls_list_head);
-out_ls:
- mutex_unlock(&ls_list_mutex);
- return ls;
-}
-
-void ls_device_put(const struct lu_env *env, struct ls_device *ls)
-{
- LASSERT(env);
- if (!atomic_dec_and_test(&ls->ls_refcount))
- return;
-
- mutex_lock(&ls_list_mutex);
- if (atomic_read(&ls->ls_refcount) == 0) {
- LASSERT(list_empty(&ls->ls_los_list));
- list_del(&ls->ls_linkage);
- lu_site_purge(env, ls->ls_top_dev.dd_lu_dev.ld_site, ~0);
- lu_device_fini(&ls->ls_top_dev.dd_lu_dev);
- OBD_FREE_PTR(ls);
- }
- mutex_unlock(&ls_list_mutex);
-}
-
-/**
- * local file fid generation
- */
-int local_object_fid_generate(const struct lu_env *env,
- struct local_oid_storage *los,
- struct lu_fid *fid)
-{
- LASSERT(los->los_dev);
- LASSERT(los->los_obj);
-
- /* take next OID */
-
- /* to make it unique after reboot we store
- * the latest generated fid atomically with
- * object creation see local_object_create() */
-
- mutex_lock(&los->los_id_lock);
- fid->f_seq = los->los_seq;
- fid->f_oid = ++los->los_last_oid;
- fid->f_ver = 0;
- mutex_unlock(&los->los_id_lock);
-
- return 0;
-}
-
-int local_object_declare_create(const struct lu_env *env,
- struct local_oid_storage *los,
- struct dt_object *o, struct lu_attr *attr,
- struct dt_object_format *dof,
- struct thandle *th)
-{
- struct dt_thread_info *dti = dt_info(env);
- int rc;
-
- /* update fid generation file */
- if (los != NULL) {
- LASSERT(dt_object_exists(los->los_obj));
- rc = dt_declare_record_write(env, los->los_obj,
- sizeof(struct los_ondisk), 0, th);
- if (rc)
- return rc;
- }
-
- rc = dt_declare_create(env, o, attr, NULL, dof, th);
- if (rc)
- return rc;
-
- dti->dti_lb.lb_buf = NULL;
- dti->dti_lb.lb_len = sizeof(dti->dti_lma);
- rc = dt_declare_xattr_set(env, o, &dti->dti_lb, XATTR_NAME_LMA, 0, th);
-
- return rc;
-}
-
-int local_object_create(const struct lu_env *env,
- struct local_oid_storage *los,
- struct dt_object *o, struct lu_attr *attr,
- struct dt_object_format *dof, struct thandle *th)
-{
- struct dt_thread_info *dti = dt_info(env);
- __le64 lastid;
- int rc;
-
- rc = dt_create(env, o, attr, NULL, dof, th);
- if (rc)
- return rc;
-
- if (los == NULL)
- return rc;
-
- LASSERT(los->los_obj);
- LASSERT(dt_object_exists(los->los_obj));
-
- /* many threads can be updated this, serialize
- * them here to avoid the race where one thread
- * takes the value first, but writes it last */
- mutex_lock(&los->los_id_lock);
-
- /* update local oid number on disk so that
- * we know the last one used after reboot */
- lastid = cpu_to_le64(los->los_last_oid);
-
- dti->dti_off = 0;
- dti->dti_lb.lb_buf = &lastid;
- dti->dti_lb.lb_len = sizeof(lastid);
- rc = dt_record_write(env, los->los_obj, &dti->dti_lb, &dti->dti_off,
- th);
- mutex_unlock(&los->los_id_lock);
-
- return rc;
-}
-
-/*
- * Create local named object (file, directory or index) in parent directory.
- */
-struct dt_object *__local_file_create(const struct lu_env *env,
- const struct lu_fid *fid,
- struct local_oid_storage *los,
- struct ls_device *ls,
- struct dt_object *parent,
- const char *name, struct lu_attr *attr,
- struct dt_object_format *dof)
-{
- struct dt_thread_info *dti = dt_info(env);
- struct dt_object *dto;
- struct thandle *th;
- int rc;
-
- dto = ls_locate(env, ls, fid);
- if (unlikely(IS_ERR(dto)))
- return dto;
-
- LASSERT(dto != NULL);
- if (dt_object_exists(dto))
- GOTO(out, rc = -EEXIST);
-
- th = dt_trans_create(env, ls->ls_osd);
- if (IS_ERR(th))
- GOTO(out, rc = PTR_ERR(th));
-
- rc = local_object_declare_create(env, los, dto, attr, dof, th);
- if (rc)
- GOTO(trans_stop, rc);
-
- if (dti->dti_dof.dof_type == DFT_DIR) {
- dt_declare_ref_add(env, dto, th);
- dt_declare_ref_add(env, parent, th);
- }
-
- rc = dt_declare_insert(env, parent, (void *)fid, (void *)name, th);
- if (rc)
- GOTO(trans_stop, rc);
-
- rc = dt_trans_start_local(env, ls->ls_osd, th);
- if (rc)
- GOTO(trans_stop, rc);
-
- dt_write_lock(env, dto, 0);
- if (dt_object_exists(dto))
- GOTO(unlock, rc = 0);
-
- CDEBUG(D_OTHER, "create new object "DFID"\n",
- PFID(lu_object_fid(&dto->do_lu)));
- rc = local_object_create(env, los, dto, attr, dof, th);
- if (rc)
- GOTO(unlock, rc);
- LASSERT(dt_object_exists(dto));
-
- if (dti->dti_dof.dof_type == DFT_DIR) {
- if (!dt_try_as_dir(env, dto))
- GOTO(destroy, rc = -ENOTDIR);
- /* Add "." and ".." for newly created dir */
- rc = dt_insert(env, dto, (void *)fid, (void *)".", th,
- BYPASS_CAPA, 1);
- if (rc)
- GOTO(destroy, rc);
- dt_ref_add(env, dto, th);
- rc = dt_insert(env, dto, (void *)lu_object_fid(&parent->do_lu),
- (void *)"..", th, BYPASS_CAPA, 1);
- if (rc)
- GOTO(destroy, rc);
- }
-
- dt_write_lock(env, parent, 0);
- rc = dt_insert(env, parent, (const struct dt_rec *)fid,
- (const struct dt_key *)name, th, BYPASS_CAPA, 1);
- if (dti->dti_dof.dof_type == DFT_DIR)
- dt_ref_add(env, parent, th);
- dt_write_unlock(env, parent);
- if (rc)
- GOTO(destroy, rc);
-destroy:
- if (rc)
- dt_destroy(env, dto, th);
-unlock:
- dt_write_unlock(env, dto);
-trans_stop:
- dt_trans_stop(env, ls->ls_osd, th);
-out:
- if (rc) {
- lu_object_put_nocache(env, &dto->do_lu);
- dto = ERR_PTR(rc);
- }
- return dto;
-}
-
-/*
- * Look up and create (if it does not exist) a local named file or directory in
- * parent directory.
- */
-struct dt_object *local_file_find_or_create(const struct lu_env *env,
- struct local_oid_storage *los,
- struct dt_object *parent,
- const char *name, __u32 mode)
-{
- struct dt_thread_info *dti = dt_info(env);
- struct dt_object *dto;
- int rc;
-
- LASSERT(parent);
-
- rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
- if (rc == 0)
- /* name is found, get the object */
- dto = ls_locate(env, dt2ls_dev(los->los_dev), &dti->dti_fid);
- else if (rc != -ENOENT)
- dto = ERR_PTR(rc);
- else {
- rc = local_object_fid_generate(env, los, &dti->dti_fid);
- if (rc < 0) {
- dto = ERR_PTR(rc);
- } else {
- /* create the object */
- dti->dti_attr.la_valid = LA_MODE;
- dti->dti_attr.la_mode = mode;
- dti->dti_dof.dof_type = dt_mode_to_dft(mode & S_IFMT);
- dto = __local_file_create(env, &dti->dti_fid, los,
- dt2ls_dev(los->los_dev),
- parent, name, &dti->dti_attr,
- &dti->dti_dof);
- }
- }
- return dto;
-}
-EXPORT_SYMBOL(local_file_find_or_create);
-
-struct dt_object *local_file_find_or_create_with_fid(const struct lu_env *env,
- struct dt_device *dt,
- const struct lu_fid *fid,
- struct dt_object *parent,
- const char *name,
- __u32 mode)
-{
- struct dt_thread_info *dti = dt_info(env);
- struct dt_object *dto;
- int rc;
-
- LASSERT(parent);
-
- rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
- if (rc == 0) {
- dto = dt_locate(env, dt, &dti->dti_fid);
- } else if (rc != -ENOENT) {
- dto = ERR_PTR(rc);
- } else {
- struct ls_device *ls;
-
- ls = ls_device_get(dt);
- if (IS_ERR(ls)) {
- dto = ERR_CAST(ls);
- } else {
- /* create the object */
- dti->dti_attr.la_valid = LA_MODE;
- dti->dti_attr.la_mode = mode;
- dti->dti_dof.dof_type = dt_mode_to_dft(mode & S_IFMT);
- dto = __local_file_create(env, fid, NULL, ls, parent,
- name, &dti->dti_attr,
- &dti->dti_dof);
- /* ls_device_put() will finalize the ls device, we
- * have to open the object in other device stack */
- if (!IS_ERR(dto)) {
- dti->dti_fid = dto->do_lu.lo_header->loh_fid;
- lu_object_put_nocache(env, &dto->do_lu);
- dto = dt_locate(env, dt, &dti->dti_fid);
- }
- ls_device_put(env, ls);
- }
- }
- return dto;
-}
-EXPORT_SYMBOL(local_file_find_or_create_with_fid);
-
-/*
- * Look up and create (if it does not exist) a local named index file in parent
- * directory.
- */
-struct dt_object *local_index_find_or_create(const struct lu_env *env,
- struct local_oid_storage *los,
- struct dt_object *parent,
- const char *name, __u32 mode,
- const struct dt_index_features *ft)
-{
- struct dt_thread_info *dti = dt_info(env);
- struct dt_object *dto;
- int rc;
-
- LASSERT(parent);
-
- rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
- if (rc == 0) {
- /* name is found, get the object */
- dto = ls_locate(env, dt2ls_dev(los->los_dev), &dti->dti_fid);
- } else if (rc != -ENOENT) {
- dto = ERR_PTR(rc);
- } else {
- rc = local_object_fid_generate(env, los, &dti->dti_fid);
- if (rc < 0) {
- dto = ERR_PTR(rc);
- } else {
- /* create the object */
- dti->dti_attr.la_valid = LA_MODE;
- dti->dti_attr.la_mode = mode;
- dti->dti_dof.dof_type = DFT_INDEX;
- dti->dti_dof.u.dof_idx.di_feat = ft;
- dto = __local_file_create(env, &dti->dti_fid, los,
- dt2ls_dev(los->los_dev),
- parent, name, &dti->dti_attr,
- &dti->dti_dof);
- }
- }
- return dto;
-
-}
-EXPORT_SYMBOL(local_index_find_or_create);
-
-struct dt_object *
-local_index_find_or_create_with_fid(const struct lu_env *env,
- struct dt_device *dt,
- const struct lu_fid *fid,
- struct dt_object *parent,
- const char *name, __u32 mode,
- const struct dt_index_features *ft)
-{
- struct dt_thread_info *dti = dt_info(env);
- struct dt_object *dto;
- int rc;
-
- LASSERT(parent);
-
- rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
- if (rc == 0) {
- /* name is found, get the object */
- if (!lu_fid_eq(fid, &dti->dti_fid))
- dto = ERR_PTR(-EINVAL);
- else
- dto = dt_locate(env, dt, fid);
- } else if (rc != -ENOENT) {
- dto = ERR_PTR(rc);
- } else {
- struct ls_device *ls;
-
- ls = ls_device_get(dt);
- if (IS_ERR(ls)) {
- dto = ERR_CAST(ls);
- } else {
- /* create the object */
- dti->dti_attr.la_valid = LA_MODE;
- dti->dti_attr.la_mode = mode;
- dti->dti_dof.dof_type = DFT_INDEX;
- dti->dti_dof.u.dof_idx.di_feat = ft;
- dto = __local_file_create(env, fid, NULL, ls, parent,
- name, &dti->dti_attr,
- &dti->dti_dof);
- /* ls_device_put() will finalize the ls device, we
- * have to open the object in other device stack */
- if (!IS_ERR(dto)) {
- dti->dti_fid = dto->do_lu.lo_header->loh_fid;
- lu_object_put_nocache(env, &dto->do_lu);
- dto = dt_locate(env, dt, &dti->dti_fid);
- }
- ls_device_put(env, ls);
- }
- }
- return dto;
-}
-EXPORT_SYMBOL(local_index_find_or_create_with_fid);
-
-static int local_object_declare_unlink(const struct lu_env *env,
- struct dt_device *dt,
- struct dt_object *p,
- struct dt_object *c, const char *name,
- struct thandle *th)
-{
- int rc;
-
- rc = dt_declare_delete(env, p, (const struct dt_key *)name, th);
- if (rc < 0)
- return rc;
-
- rc = dt_declare_ref_del(env, c, th);
- if (rc < 0)
- return rc;
-
- return dt_declare_destroy(env, c, th);
-}
-
-int local_object_unlink(const struct lu_env *env, struct dt_device *dt,
- struct dt_object *parent, const char *name)
-{
- struct dt_thread_info *dti = dt_info(env);
- struct dt_object *dto;
- struct thandle *th;
- int rc;
-
- rc = dt_lookup_dir(env, parent, name, &dti->dti_fid);
- if (rc == -ENOENT)
- return 0;
- else if (rc < 0)
- return rc;
-
- dto = dt_locate(env, dt, &dti->dti_fid);
- if (unlikely(IS_ERR(dto)))
- return PTR_ERR(dto);
-
- th = dt_trans_create(env, dt);
- if (IS_ERR(th))
- GOTO(out, rc = PTR_ERR(th));
-
- rc = local_object_declare_unlink(env, dt, parent, dto, name, th);
- if (rc < 0)
- GOTO(stop, rc);
-
- rc = dt_trans_start_local(env, dt, th);
- if (rc < 0)
- GOTO(stop, rc);
-
- dt_write_lock(env, dto, 0);
- rc = dt_delete(env, parent, (struct dt_key *)name, th, BYPASS_CAPA);
- if (rc < 0)
- GOTO(unlock, rc);
-
- rc = dt_ref_del(env, dto, th);
- if (rc < 0) {
- rc = dt_insert(env, parent,
- (const struct dt_rec *)&dti->dti_fid,
- (const struct dt_key *)name, th, BYPASS_CAPA, 1);
- GOTO(unlock, rc);
- }
-
- rc = dt_destroy(env, dto, th);
-unlock:
- dt_write_unlock(env, dto);
-stop:
- dt_trans_stop(env, dt, th);
-out:
- lu_object_put_nocache(env, &dto->do_lu);
- return rc;
-}
-EXPORT_SYMBOL(local_object_unlink);
-
-struct local_oid_storage *dt_los_find(struct ls_device *ls, __u64 seq)
-{
- struct local_oid_storage *los, *ret = NULL;
-
- list_for_each_entry(los, &ls->ls_los_list, los_list) {
- if (los->los_seq == seq) {
- atomic_inc(&los->los_refcount);
- ret = los;
- break;
- }
- }
- return ret;
-}
-
-void dt_los_put(struct local_oid_storage *los)
-{
- if (atomic_dec_and_test(&los->los_refcount))
- /* should never happen, only local_oid_storage_fini should
- * drop refcount to zero */
- LBUG();
- return;
-}
-
-/* after Lustre 2.3 release there may be old file to store last generated FID
- * If such file exists then we have to read its content
- */
-int lastid_compat_check(const struct lu_env *env, struct dt_device *dev,
- __u64 lastid_seq, __u32 *first_oid, struct ls_device *ls)
-{
- struct dt_thread_info *dti = dt_info(env);
- struct dt_object *root = NULL;
- struct los_ondisk losd;
- struct dt_object *o = NULL;
- int rc = 0;
-
- rc = dt_root_get(env, dev, &dti->dti_fid);
- if (rc)
- return rc;
-
- root = ls_locate(env, ls, &dti->dti_fid);
- if (IS_ERR(root))
- return PTR_ERR(root);
-
- /* find old last_id file */
- snprintf(dti->dti_buf, sizeof(dti->dti_buf), "seq-%#llx-lastid",
- lastid_seq);
- rc = dt_lookup_dir(env, root, dti->dti_buf, &dti->dti_fid);
- lu_object_put_nocache(env, &root->do_lu);
- if (rc == -ENOENT) {
- /* old llog lastid accessed by FID only */
- if (lastid_seq != FID_SEQ_LLOG)
- return 0;
- dti->dti_fid.f_seq = FID_SEQ_LLOG;
- dti->dti_fid.f_oid = 1;
- dti->dti_fid.f_ver = 0;
- o = ls_locate(env, ls, &dti->dti_fid);
- if (IS_ERR(o))
- return PTR_ERR(o);
-
- if (!dt_object_exists(o)) {
- lu_object_put_nocache(env, &o->do_lu);
- return 0;
- }
- CDEBUG(D_INFO, "Found old llog lastid file\n");
- } else if (rc < 0) {
- return rc;
- } else {
- CDEBUG(D_INFO, "Found old lastid file for sequence %#llx\n",
- lastid_seq);
- o = ls_locate(env, ls, &dti->dti_fid);
- if (IS_ERR(o))
- return PTR_ERR(o);
- }
- /* let's read seq-NNNNNN-lastid file value */
- LASSERT(dt_object_exists(o));
- dti->dti_off = 0;
- dti->dti_lb.lb_buf = &losd;
- dti->dti_lb.lb_len = sizeof(losd);
- dt_read_lock(env, o, 0);
- rc = dt_record_read(env, o, &dti->dti_lb, &dti->dti_off);
- dt_read_unlock(env, o);
- lu_object_put_nocache(env, &o->do_lu);
- if (rc == 0 && le32_to_cpu(losd.lso_magic) != LOS_MAGIC) {
- CERROR("%s: wrong content of seq-%#llx-lastid file, magic %x\n",
- o->do_lu.lo_dev->ld_obd->obd_name, lastid_seq,
- le32_to_cpu(losd.lso_magic));
- return -EINVAL;
- } else if (rc < 0) {
- CERROR("%s: failed to read seq-%#llx-lastid: rc = %d\n",
- o->do_lu.lo_dev->ld_obd->obd_name, lastid_seq, rc);
- return rc;
- }
- *first_oid = le32_to_cpu(losd.lso_next_oid);
- return rc;
-}
-
-/**
- * Initialize local OID storage for required sequence.
- * That may be needed for services that uses local files and requires
- * dynamic OID allocation for them.
- *
- * Per each sequence we have an object with 'first_fid' identificator
- * containing the counter for OIDs of locally created files with that
- * sequence.
- *
- * It is used now by llog subsystem and MGS for NID tables
- *
- * Function gets first_fid to create counter object.
- * All dynamic fids will be generated with the same sequence and incremented
- * OIDs
- *
- * Returned local_oid_storage is in-memory representation of OID storage
- */
-int local_oid_storage_init(const struct lu_env *env, struct dt_device *dev,
- const struct lu_fid *first_fid,
- struct local_oid_storage **los)
-{
- struct dt_thread_info *dti = dt_info(env);
- struct ls_device *ls;
- obd_id lastid;
- struct dt_object *o = NULL;
- struct thandle *th;
- __u32 first_oid = fid_oid(first_fid);
- int rc = 0;
-
- ls = ls_device_get(dev);
- if (IS_ERR(ls))
- return PTR_ERR(ls);
-
- mutex_lock(&ls->ls_los_mutex);
- *los = dt_los_find(ls, fid_seq(first_fid));
- if (*los != NULL)
- GOTO(out, rc = 0);
-
- /* not found, then create */
- OBD_ALLOC_PTR(*los);
- if (*los == NULL)
- GOTO(out, rc = -ENOMEM);
-
- atomic_set(&(*los)->los_refcount, 1);
- mutex_init(&(*los)->los_id_lock);
- (*los)->los_dev = &ls->ls_top_dev;
- atomic_inc(&ls->ls_refcount);
- list_add(&(*los)->los_list, &ls->ls_los_list);
-
- /* Use {seq, 0, 0} to create the LAST_ID file for every
- * sequence. OIDs start at LUSTRE_FID_INIT_OID.
- */
- dti->dti_fid.f_seq = fid_seq(first_fid);
- dti->dti_fid.f_oid = LUSTRE_FID_LASTID_OID;
- dti->dti_fid.f_ver = 0;
- o = ls_locate(env, ls, &dti->dti_fid);
- if (IS_ERR(o))
- GOTO(out_los, rc = PTR_ERR(o));
-
- if (!dt_object_exists(o)) {
- rc = lastid_compat_check(env, dev, fid_seq(first_fid),
- &first_oid, ls);
- if (rc < 0)
- GOTO(out_los, rc);
-
- th = dt_trans_create(env, dev);
- if (IS_ERR(th))
- GOTO(out_los, rc = PTR_ERR(th));
-
- dti->dti_attr.la_valid = LA_MODE | LA_TYPE;
- dti->dti_attr.la_mode = S_IFREG | S_IRUGO | S_IWUSR;
- dti->dti_dof.dof_type = dt_mode_to_dft(S_IFREG);
-
- rc = dt_declare_create(env, o, &dti->dti_attr, NULL,
- &dti->dti_dof, th);
- if (rc)
- GOTO(out_trans, rc);
-
- rc = dt_declare_record_write(env, o, sizeof(lastid), 0, th);
- if (rc)
- GOTO(out_trans, rc);
-
- rc = dt_trans_start_local(env, dev, th);
- if (rc)
- GOTO(out_trans, rc);
-
- dt_write_lock(env, o, 0);
- if (dt_object_exists(o))
- GOTO(out_lock, rc = 0);
-
- rc = dt_create(env, o, &dti->dti_attr, NULL, &dti->dti_dof,
- th);
- if (rc)
- GOTO(out_lock, rc);
-
- lastid = cpu_to_le64(first_oid);
-
- dti->dti_off = 0;
- dti->dti_lb.lb_buf = &lastid;
- dti->dti_lb.lb_len = sizeof(lastid);
- rc = dt_record_write(env, o, &dti->dti_lb, &dti->dti_off, th);
- if (rc)
- GOTO(out_lock, rc);
-out_lock:
- dt_write_unlock(env, o);
-out_trans:
- dt_trans_stop(env, dev, th);
- } else {
- dti->dti_off = 0;
- dti->dti_lb.lb_buf = &lastid;
- dti->dti_lb.lb_len = sizeof(lastid);
- dt_read_lock(env, o, 0);
- rc = dt_record_read(env, o, &dti->dti_lb, &dti->dti_off);
- dt_read_unlock(env, o);
- if (rc == 0 && le64_to_cpu(lastid) > OBIF_MAX_OID) {
- CERROR("%s: bad oid %llu is read from LAST_ID\n",
- o->do_lu.lo_dev->ld_obd->obd_name,
- le64_to_cpu(lastid));
- rc = -EINVAL;
- }
- }
-out_los:
- if (rc != 0) {
- list_del(&(*los)->los_list);
- atomic_dec(&ls->ls_refcount);
- OBD_FREE_PTR(*los);
- *los = NULL;
- if (o != NULL && !IS_ERR(o))
- lu_object_put_nocache(env, &o->do_lu);
- } else {
- (*los)->los_seq = fid_seq(first_fid);
- (*los)->los_last_oid = le64_to_cpu(lastid);
- (*los)->los_obj = o;
- /* Read value should not be less than initial one
- * but possible after upgrade from older fs.
- * In this case just switch to the first_oid in memory and
- * it will be updated on disk with first object generated */
- if ((*los)->los_last_oid < first_oid)
- (*los)->los_last_oid = first_oid;
- }
-out:
- mutex_unlock(&ls->ls_los_mutex);
- ls_device_put(env, ls);
- return rc;
-}
-EXPORT_SYMBOL(local_oid_storage_init);
-
-void local_oid_storage_fini(const struct lu_env *env,
- struct local_oid_storage *los)
-{
- struct ls_device *ls;
-
- if (!atomic_dec_and_test(&los->los_refcount))
- return;
-
- LASSERT(env);
- LASSERT(los->los_dev);
- ls = dt2ls_dev(los->los_dev);
-
- mutex_lock(&ls->ls_los_mutex);
- if (atomic_read(&los->los_refcount) == 0) {
- if (los->los_obj)
- lu_object_put_nocache(env, &los->los_obj->do_lu);
- list_del(&los->los_list);
- OBD_FREE_PTR(los);
- }
- mutex_unlock(&ls->ls_los_mutex);
- ls_device_put(env, ls);
-}
-EXPORT_SYMBOL(local_oid_storage_fini);
diff --git a/drivers/staging/lustre/lustre/obdclass/local_storage.h b/drivers/staging/lustre/lustre/obdclass/local_storage.h
deleted file mode 100644
index 0b9ad33d1152..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/local_storage.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
-
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License version 2 for more details. A copy is
- * included in the COPYING file that accompanied this code.
-
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2012, Intel Corporation.
- */
-/*
- * lustre/obdclass/local_storage.c
- *
- * Local storage for file/objects with fid generation. Works on top of OSD.
- *
- * Author: Mikhail Pershin <mike.pershin@intel.com>
- */
-#ifndef __LOCAL_STORAGE_H
-#define __LOCAL_STORAGE_H
-
-#include "../include/dt_object.h"
-#include "../include/obd.h"
-#include "../include/lustre_fid.h"
-#include "../include/lustre_disk.h"
-
-struct ls_device {
- struct dt_device ls_top_dev;
- /* all initialized ls_devices on this node linked by this */
- struct list_head ls_linkage;
- /* how many handle's reference this local storage */
- atomic_t ls_refcount;
- /* underlaying OSD device */
- struct dt_device *ls_osd;
- /* list of all local OID storages */
- struct list_head ls_los_list;
- struct mutex ls_los_mutex;
-};
-
-static inline struct ls_device *dt2ls_dev(struct dt_device *d)
-{
- return container_of0(d, struct ls_device, ls_top_dev);
-}
-
-struct ls_object {
- struct lu_object_header ls_header;
- struct dt_object ls_obj;
-};
-
-static inline struct ls_object *lu2ls_obj(struct lu_object *o)
-{
- return container_of0(o, struct ls_object, ls_obj.do_lu);
-}
-
-static inline struct dt_object *ls_locate(const struct lu_env *env,
- struct ls_device *ls,
- const struct lu_fid *fid)
-{
- return dt_locate_at(env, ls->ls_osd, fid, &ls->ls_top_dev.dd_lu_dev);
-}
-
-struct ls_device *ls_device_get(struct dt_device *dev);
-void ls_device_put(const struct lu_env *env, struct ls_device *ls);
-struct local_oid_storage *dt_los_find(struct ls_device *ls, __u64 seq);
-void dt_los_put(struct local_oid_storage *los);
-
-/* Lustre 2.3 on-disk structure describing local object OIDs storage
- * the structure to be used with any sequence managed by
- * local object library.
- * Obsoleted since 2.4 but is kept for compatibility reasons,
- * see lastid_compat_check() in obdclass/local_storage.c */
-struct los_ondisk {
- __u32 lso_magic;
- __u32 lso_next_oid;
-};
-
-#define LOS_MAGIC 0xdecafbee
-#endif
diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_counters.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_counters.c
new file mode 100644
index 000000000000..c49dfe541925
--- /dev/null
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_counters.c
@@ -0,0 +1,139 @@
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ *
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Use is subject to license terms.
+ *
+ * Copyright (c) 2012, 2013, Intel Corporation.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
+ *
+ * lustre/obdclass/lprocfs_counters.c
+ *
+ * Lustre lprocfs counter routines
+ *
+ * Author: Andreas Dilger <andreas.dilger@intel.com>
+ */
+
+#include <linux/module.h>
+#include "../include/lprocfs_status.h"
+#include "../include/obd_support.h"
+
+struct lprocfs_stats *obd_memory = NULL;
+EXPORT_SYMBOL(obd_memory);
+
+void lprocfs_counter_add(struct lprocfs_stats *stats, int idx, long amount)
+{
+ struct lprocfs_counter *percpu_cntr;
+ struct lprocfs_counter_header *header;
+ int smp_id;
+ unsigned long flags = 0;
+
+ if (stats == NULL)
+ return;
+
+ LASSERTF(0 <= idx && idx < stats->ls_num,
+ "idx %d, ls_num %hu\n", idx, stats->ls_num);
+
+ /* With per-client stats, statistics are allocated only for
+ * single CPU area, so the smp_id should be 0 always. */
+ smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID, &flags);
+ if (smp_id < 0)
+ return;
+
+ header = &stats->ls_cnt_header[idx];
+ percpu_cntr = lprocfs_stats_counter_get(stats, smp_id, idx);
+ percpu_cntr->lc_count++;
+
+ if (header->lc_config & LPROCFS_CNTR_AVGMINMAX) {
+ /*
+ * lprocfs_counter_add() can be called in interrupt context,
+ * as memory allocation could trigger memory shrinker call
+ * ldlm_pool_shrink(), which calls lprocfs_counter_add().
+ * LU-1727.
+ *
+ * Only obd_memory uses LPROCFS_STATS_FLAG_IRQ_SAFE
+ * flag, because it needs accurate counting lest memory leak
+ * check reports error.
+ */
+ if (in_interrupt() &&
+ (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
+ percpu_cntr->lc_sum_irq += amount;
+ else
+ percpu_cntr->lc_sum += amount;
+
+ if (header->lc_config & LPROCFS_CNTR_STDDEV)
+ percpu_cntr->lc_sumsquare += (__s64)amount * amount;
+ if (amount < percpu_cntr->lc_min)
+ percpu_cntr->lc_min = amount;
+ if (amount > percpu_cntr->lc_max)
+ percpu_cntr->lc_max = amount;
+ }
+ lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID, &flags);
+}
+EXPORT_SYMBOL(lprocfs_counter_add);
+
+void lprocfs_counter_sub(struct lprocfs_stats *stats, int idx, long amount)
+{
+ struct lprocfs_counter *percpu_cntr;
+ struct lprocfs_counter_header *header;
+ int smp_id;
+ unsigned long flags = 0;
+
+ if (stats == NULL)
+ return;
+
+ LASSERTF(0 <= idx && idx < stats->ls_num,
+ "idx %d, ls_num %hu\n", idx, stats->ls_num);
+
+ /* With per-client stats, statistics are allocated only for
+ * single CPU area, so the smp_id should be 0 always. */
+ smp_id = lprocfs_stats_lock(stats, LPROCFS_GET_SMP_ID, &flags);
+ if (smp_id < 0)
+ return;
+
+ header = &stats->ls_cnt_header[idx];
+ percpu_cntr = lprocfs_stats_counter_get(stats, smp_id, idx);
+ if (header->lc_config & LPROCFS_CNTR_AVGMINMAX) {
+ /*
+ * Sometimes we use RCU callbacks to free memory which calls
+ * lprocfs_counter_sub(), and RCU callbacks may execute in
+ * softirq context - right now that's the only case we're in
+ * softirq context here, use separate counter for that.
+ * bz20650.
+ *
+ * Only obd_memory uses LPROCFS_STATS_FLAG_IRQ_SAFE
+ * flag, because it needs accurate counting lest memory leak
+ * check reports error.
+ */
+ if (in_interrupt() &&
+ (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
+ percpu_cntr->lc_sum_irq -= amount;
+ else
+ percpu_cntr->lc_sum -= amount;
+ }
+ lprocfs_stats_unlock(stats, LPROCFS_GET_SMP_ID, &flags);
+}
+EXPORT_SYMBOL(lprocfs_counter_sub);
diff --git a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
index 8309d4ce6d60..61e04af2464f 100644
--- a/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
+++ b/drivers/staging/lustre/lustre/obdclass/lprocfs_status.c
@@ -356,8 +356,10 @@ struct proc_dir_entry *lprocfs_register(const char *name,
struct proc_dir_entry *entry;
entry = proc_mkdir(name, parent);
- if (entry == NULL)
- GOTO(out, entry = ERR_PTR(-ENOMEM));
+ if (entry == NULL) {
+ entry = ERR_PTR(-ENOMEM);
+ goto out;
+ }
if (list != NULL) {
int rc = lprocfs_add_vars(entry, list, data);
@@ -751,7 +753,7 @@ int lprocfs_rd_import(struct seq_file *m, void *data)
ret.lc_sum, header->lc_units);
k = 0;
- for(j = 0; j < IMP_AT_MAX_PORTALS; j++) {
+ for (j = 0; j < IMP_AT_MAX_PORTALS; j++) {
if (imp->imp_at.iat_portal[j] == 0)
break;
k = max_t(unsigned int, k,
@@ -883,7 +885,7 @@ int lprocfs_rd_timeouts(struct seq_file *m, void *data)
"network", cur, worst, worstt, DHMS_VARS(&ts));
lprocfs_at_hist_helper(m, &imp->imp_at.iat_net_latency);
- for(i = 0; i < IMP_AT_MAX_PORTALS; i++) {
+ for (i = 0; i < IMP_AT_MAX_PORTALS; i++) {
if (imp->imp_at.iat_portal[i] == 0)
break;
cur = at_get(&imp->imp_at.iat_service_estimate[i]);
@@ -927,7 +929,7 @@ EXPORT_SYMBOL(lprocfs_rd_num_exports);
int lprocfs_rd_numrefs(struct seq_file *m, void *data)
{
- struct obd_type *class = (struct obd_type*) data;
+ struct obd_type *class = (struct obd_type *) data;
LASSERT(class != NULL);
return seq_printf(m, "%d\n", class->typ_refcnt);
@@ -947,7 +949,8 @@ int lprocfs_obd_setup(struct obd_device *obd, struct lprocfs_vars *list)
list, obd);
if (IS_ERR(obd->obd_proc_entry)) {
rc = PTR_ERR(obd->obd_proc_entry);
- CERROR("error %d setting up lprocfs for %s\n",rc,obd->obd_name);
+ CERROR("error %d setting up lprocfs for %s\n",
+ rc, obd->obd_name);
obd->obd_proc_entry = NULL;
}
return rc;
@@ -1011,6 +1014,43 @@ void lprocfs_free_per_client_stats(struct obd_device *obd)
}
EXPORT_SYMBOL(lprocfs_free_per_client_stats);
+int lprocfs_stats_alloc_one(struct lprocfs_stats *stats, unsigned int cpuid)
+{
+ struct lprocfs_counter *cntr;
+ unsigned int percpusize;
+ int rc = -ENOMEM;
+ unsigned long flags = 0;
+ int i;
+
+ LASSERT(stats->ls_percpu[cpuid] == NULL);
+ LASSERT((stats->ls_flags & LPROCFS_STATS_FLAG_NOPERCPU) == 0);
+
+ percpusize = lprocfs_stats_counter_size(stats);
+ LIBCFS_ALLOC_ATOMIC(stats->ls_percpu[cpuid], percpusize);
+ if (stats->ls_percpu[cpuid] != NULL) {
+ rc = 0;
+ if (unlikely(stats->ls_biggest_alloc_num <= cpuid)) {
+ if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
+ spin_lock_irqsave(&stats->ls_lock, flags);
+ else
+ spin_lock(&stats->ls_lock);
+ if (stats->ls_biggest_alloc_num <= cpuid)
+ stats->ls_biggest_alloc_num = cpuid + 1;
+ if (stats->ls_flags & LPROCFS_STATS_FLAG_IRQ_SAFE)
+ spin_unlock_irqrestore(&stats->ls_lock, flags);
+ else
+ spin_unlock(&stats->ls_lock);
+ }
+ /* initialize the ls_percpu[cpuid] non-zero counter */
+ for (i = 0; i < stats->ls_num; ++i) {
+ cntr = lprocfs_stats_counter_get(stats, cpuid, i);
+ cntr->lc_min = LC_MIN_INIT;
+ }
+ }
+ return rc;
+}
+EXPORT_SYMBOL(lprocfs_stats_alloc_one);
+
struct lprocfs_stats *lprocfs_alloc_stats(unsigned int num,
enum lprocfs_stats_flags flags)
{
@@ -1308,44 +1348,24 @@ void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats)
LPROCFS_OBD_OP_INIT(num_private_stats, stats, packmd);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, preallocate);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, precreate);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, create_async);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, setattr_async);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, getattr_async);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, brw);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, merge_lvb);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, adjust_kms);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, punch);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, sync);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, migrate);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, copy);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, iterate);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, preprw);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, commitrw);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, enqueue);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, change_cbdata);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, find_cbdata);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, cancel_unused);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, init_export);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy_export);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, extent_calc);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_init);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_connect);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, llog_finish);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, pin);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpin);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, import_event);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, notify);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, health_check);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, get_uuid);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotacheck);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, quotactl);
- LPROCFS_OBD_OP_INIT(num_private_stats, stats, ping);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_new);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_rem);
LPROCFS_OBD_OP_INIT(num_private_stats, stats, pool_add);
@@ -1572,7 +1592,10 @@ lproc_exp_hash_seq_show(struct seq_file *m, void *unused)
{
struct nid_stat *stats = (struct nid_stat *)m->private;
struct obd_device *obd = stats->nid_obd;
- struct exp_hash_cb_data cb_data = {m, true};
+ struct exp_hash_cb_data cb_data = {
+ .m = m,
+ .first = true
+ };
cfs_hash_for_each_key(obd->obd_nid_hash, &stats->nid,
lprocfs_exp_print_hash, &cb_data);
@@ -1593,7 +1616,7 @@ static int lprocfs_nid_stats_clear_write_cb(void *obj, void *data)
{
struct nid_stat *stat = obj;
- CDEBUG(D_INFO,"refcnt %d\n", atomic_read(&stat->nid_exp_ref_count));
+ CDEBUG(D_INFO, "refcnt %d\n", atomic_read(&stat->nid_exp_ref_count));
if (atomic_read(&stat->nid_exp_ref_count) == 1) {
/* object has only hash references. */
spin_lock(&stat->nid_obd->obd_nid_lock);
@@ -1679,12 +1702,15 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
* entry already has been created */
if (old_stat != new_stat) {
exp->exp_nid_stats = old_stat;
- GOTO(destroy_new, rc = -EALREADY);
+ rc = -EALREADY;
+ goto destroy_new;
}
/* not found - create */
OBD_ALLOC(buffer, LNET_NIDSTR_SIZE);
- if (buffer == NULL)
- GOTO(destroy_new, rc = -ENOMEM);
+ if (buffer == NULL) {
+ rc = -ENOMEM;
+ goto destroy_new;
+ }
memcpy(buffer, libcfs_nid2str(*nid), LNET_NIDSTR_SIZE);
new_stat->nid_proc = lprocfs_register(buffer,
@@ -1697,7 +1723,7 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
libcfs_nid2str(*nid));
rc = PTR_ERR(new_stat->nid_proc);
new_stat->nid_proc = NULL;
- GOTO(destroy_new_ns, rc);
+ goto destroy_new_ns;
}
entry = lprocfs_add_simple(new_stat->nid_proc, "uuid",
@@ -1705,7 +1731,7 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
if (IS_ERR(entry)) {
CWARN("Error adding the NID stats file\n");
rc = PTR_ERR(entry);
- GOTO(destroy_new_ns, rc);
+ goto destroy_new_ns;
}
entry = lprocfs_add_simple(new_stat->nid_proc, "hash",
@@ -1713,7 +1739,7 @@ int lprocfs_exp_setup(struct obd_export *exp, lnet_nid_t *nid, int *newnid)
if (IS_ERR(entry)) {
CWARN("Error adding the hash file\n");
rc = PTR_ERR(entry);
- GOTO(destroy_new_ns, rc);
+ goto destroy_new_ns;
}
exp->exp_nid_stats = new_stat;
@@ -1741,7 +1767,7 @@ int lprocfs_exp_cleanup(struct obd_export *exp)
{
struct nid_stat *stat = exp->exp_nid_stats;
- if(!stat || !exp->exp_obd)
+ if (!stat || !exp->exp_obd)
return 0;
nidstat_putref(exp->exp_nid_stats);
@@ -1751,6 +1777,48 @@ int lprocfs_exp_cleanup(struct obd_export *exp)
}
EXPORT_SYMBOL(lprocfs_exp_cleanup);
+__s64 lprocfs_read_helper(struct lprocfs_counter *lc,
+ struct lprocfs_counter_header *header,
+ enum lprocfs_stats_flags flags,
+ enum lprocfs_fields_flags field)
+{
+ __s64 ret = 0;
+
+ if (lc == NULL || header == NULL)
+ return 0;
+
+ switch (field) {
+ case LPROCFS_FIELDS_FLAGS_CONFIG:
+ ret = header->lc_config;
+ break;
+ case LPROCFS_FIELDS_FLAGS_SUM:
+ ret = lc->lc_sum;
+ if ((flags & LPROCFS_STATS_FLAG_IRQ_SAFE) != 0)
+ ret += lc->lc_sum_irq;
+ break;
+ case LPROCFS_FIELDS_FLAGS_MIN:
+ ret = lc->lc_min;
+ break;
+ case LPROCFS_FIELDS_FLAGS_MAX:
+ ret = lc->lc_max;
+ break;
+ case LPROCFS_FIELDS_FLAGS_AVG:
+ ret = (lc->lc_max - lc->lc_min) / 2;
+ break;
+ case LPROCFS_FIELDS_FLAGS_SUMSQUARE:
+ ret = lc->lc_sumsquare;
+ break;
+ case LPROCFS_FIELDS_FLAGS_COUNT:
+ ret = lc->lc_count;
+ break;
+ default:
+ break;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(lprocfs_read_helper);
+
int lprocfs_write_helper(const char *buffer, unsigned long count,
int *val)
{
@@ -1783,7 +1851,8 @@ int lprocfs_seq_read_frac_helper(struct seq_file *m, long val, int mult)
}
EXPORT_SYMBOL(lprocfs_seq_read_frac_helper);
-int lprocfs_write_u64_helper(const char *buffer, unsigned long count,__u64 *val)
+int lprocfs_write_u64_helper(const char *buffer, unsigned long count,
+ __u64 *val)
{
return lprocfs_write_frac_u64_helper(buffer, count, val, 1);
}
@@ -1828,7 +1897,7 @@ int lprocfs_write_frac_u64_helper(const char *buffer, unsigned long count,
}
units = 1;
- switch(*end) {
+ switch (*end) {
case 'p': case 'P':
units <<= 10;
case 't': case 'T':
@@ -1922,8 +1991,8 @@ int lprocfs_obd_seq_create(struct obd_device *dev,
const struct file_operations *seq_fops,
void *data)
{
- return (lprocfs_seq_create(dev->obd_proc_entry, name,
- mode, seq_fops, data));
+ return lprocfs_seq_create(dev->obd_proc_entry, name,
+ mode, seq_fops, data);
}
EXPORT_SYMBOL(lprocfs_obd_seq_create);
diff --git a/drivers/staging/lustre/lustre/obdclass/lu_ucred.c b/drivers/staging/lustre/lustre/obdclass/lu_ucred.c
deleted file mode 100644
index 3676563ab330..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/lu_ucred.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- *
- * Copyright (c) 2011, 2012, Intel Corporation.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- *
- * lustre/obdclass/lu_ucred.c
- *
- * Lustre user credentials context infrastructure.
- *
- * Author: Nikita Danilov <nikita.danilov@sun.com>
- * Author: Fan Yong <fan.yong@intel.com>
- * Author: Vitaly Fertman <vitaly_fertman@xyratex.com>
- */
-
-#define DEBUG_SUBSYSTEM S_CLASS
-
-#include "../../include/linux/libcfs/libcfs.h"
-#include "../include/obd_support.h"
-#include "../include/lu_object.h"
-#include "../include/md_object.h"
-
-/* context key constructor/destructor: lu_ucred_key_init, lu_ucred_key_fini */
-LU_KEY_INIT_FINI(lu_ucred, struct lu_ucred);
-
-static struct lu_context_key lu_ucred_key = {
- .lct_tags = LCT_SESSION,
- .lct_init = lu_ucred_key_init,
- .lct_fini = lu_ucred_key_fini
-};
-
-/**
- * Get ucred key if session exists and ucred key is allocated on it.
- * Return NULL otherwise.
- */
-struct lu_ucred *lu_ucred(const struct lu_env *env)
-{
- if (!env->le_ses)
- return NULL;
- return lu_context_key_get(env->le_ses, &lu_ucred_key);
-}
-EXPORT_SYMBOL(lu_ucred);
-
-/**
- * Get ucred key and check if it is properly initialized.
- * Return NULL otherwise.
- */
-struct lu_ucred *lu_ucred_check(const struct lu_env *env)
-{
- struct lu_ucred *uc = lu_ucred(env);
- if (uc && uc->uc_valid != UCRED_OLD && uc->uc_valid != UCRED_NEW)
- return NULL;
- return uc;
-}
-EXPORT_SYMBOL(lu_ucred_check);
-
-/**
- * Get ucred key, which must exist and must be properly initialized.
- * Assert otherwise.
- */
-struct lu_ucred *lu_ucred_assert(const struct lu_env *env)
-{
- struct lu_ucred *uc = lu_ucred_check(env);
- LASSERT(uc != NULL);
- return uc;
-}
-EXPORT_SYMBOL(lu_ucred_assert);
-
-int lu_ucred_global_init(void)
-{
- LU_CONTEXT_KEY_INIT(&lu_ucred_key);
- return lu_context_key_register(&lu_ucred_key);
-}
-
-void lu_ucred_global_fini(void)
-{
- lu_context_key_degister(&lu_ucred_key);
-}
diff --git a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
index 2010463429b1..f720e3183295 100644
--- a/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
+++ b/drivers/staging/lustre/lustre/obdclass/lustre_handles.c
@@ -178,7 +178,7 @@ void *class_handle2object(__u64 cookie)
}
EXPORT_SYMBOL(class_handle2object);
-void class_handle_free_cb(cfs_rcu_head_t *rcu)
+void class_handle_free_cb(struct rcu_head *rcu)
{
struct portals_handle *h = RCU2HANDLE(rcu);
void *ptr = (void *)(unsigned long)h->h_cookie;
diff --git a/drivers/staging/lustre/lustre/obdclass/md_attrs.c b/drivers/staging/lustre/lustre/obdclass/md_attrs.c
deleted file mode 100644
index d9e6348de4fa..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/md_attrs.c
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2012, Intel Corporation.
- * Use is subject to license terms.
- *
- * Author: Johann Lombardi <johann.lombardi@intel.com>
- */
-
-#include "../include/lustre/lustre_idl.h"
-#include "../include/obd.h"
-#include "../include/md_object.h"
-
-/**
- * Initialize new \a lma. Only fid is stored.
- *
- * \param lma - is the new LMA structure to be initialized
- * \param fid - is the FID of the object this LMA belongs to
- * \param incompat - features that MDS must understand to access object
- */
-void lustre_lma_init(struct lustre_mdt_attrs *lma, const struct lu_fid *fid,
- __u32 incompat)
-{
- lma->lma_compat = 0;
- lma->lma_incompat = incompat;
- lma->lma_self_fid = *fid;
-
- /* If a field is added in struct lustre_mdt_attrs, zero it explicitly
- * and change the test below. */
- LASSERT(sizeof(*lma) ==
- (offsetof(struct lustre_mdt_attrs, lma_self_fid) +
- sizeof(lma->lma_self_fid)));
-};
-EXPORT_SYMBOL(lustre_lma_init);
-
-/**
- * Swab, if needed, LMA structure which is stored on-disk in little-endian order.
- *
- * \param lma - is a pointer to the LMA structure to be swabbed.
- */
-void lustre_lma_swab(struct lustre_mdt_attrs *lma)
-{
- /* Use LUSTRE_MSG_MAGIC to detect local endianness. */
- if (LUSTRE_MSG_MAGIC != cpu_to_le32(LUSTRE_MSG_MAGIC)) {
- __swab32s(&lma->lma_compat);
- __swab32s(&lma->lma_incompat);
- lustre_swab_lu_fid(&lma->lma_self_fid);
- }
-};
-EXPORT_SYMBOL(lustre_lma_swab);
-
-/**
- * Swab, if needed, SOM structure which is stored on-disk in little-endian
- * order.
- *
- * \param attrs - is a pointer to the SOM structure to be swabbed.
- */
-void lustre_som_swab(struct som_attrs *attrs)
-{
- /* Use LUSTRE_MSG_MAGIC to detect local endianness. */
- if (LUSTRE_MSG_MAGIC != cpu_to_le32(LUSTRE_MSG_MAGIC)) {
- __swab32s(&attrs->som_compat);
- __swab32s(&attrs->som_incompat);
- __swab64s(&attrs->som_ioepoch);
- __swab64s(&attrs->som_size);
- __swab64s(&attrs->som_blocks);
- __swab64s(&attrs->som_mountid);
- }
-};
-EXPORT_SYMBOL(lustre_som_swab);
-
-/*
- * Swab and extract SOM attributes from on-disk xattr.
- *
- * \param buf - is a buffer containing the on-disk SOM extended attribute.
- * \param rc - is the SOM xattr stored in \a buf
- * \param msd - is the md_som_data structure where to extract SOM attributes.
- */
-int lustre_buf2som(void *buf, int rc, struct md_som_data *msd)
-{
- struct som_attrs *attrs = (struct som_attrs *)buf;
-
- if (rc == 0 || rc == -ENODATA)
- /* no SOM attributes */
- return -ENODATA;
-
- if (rc < 0)
- /* error hit while fetching xattr */
- return rc;
-
- /* check SOM compatibility */
- if (attrs->som_incompat & ~cpu_to_le32(SOM_INCOMPAT_SUPP))
- return -ENODATA;
-
- /* unpack SOM attributes */
- lustre_som_swab(attrs);
-
- /* fill in-memory msd structure */
- msd->msd_compat = attrs->som_compat;
- msd->msd_incompat = attrs->som_incompat;
- msd->msd_ioepoch = attrs->som_ioepoch;
- msd->msd_size = attrs->som_size;
- msd->msd_blocks = attrs->som_blocks;
- msd->msd_mountid = attrs->som_mountid;
-
- return 0;
-}
-EXPORT_SYMBOL(lustre_buf2som);
-
-/**
- * Swab, if needed, HSM structure which is stored on-disk in little-endian
- * order.
- *
- * \param attrs - is a pointer to the HSM structure to be swabbed.
- */
-void lustre_hsm_swab(struct hsm_attrs *attrs)
-{
- /* Use LUSTRE_MSG_MAGIC to detect local endianness. */
- if (LUSTRE_MSG_MAGIC != cpu_to_le32(LUSTRE_MSG_MAGIC)) {
- __swab32s(&attrs->hsm_compat);
- __swab32s(&attrs->hsm_flags);
- __swab64s(&attrs->hsm_arch_id);
- __swab64s(&attrs->hsm_arch_ver);
- }
-};
-EXPORT_SYMBOL(lustre_hsm_swab);
-
-/*
- * Swab and extract HSM attributes from on-disk xattr.
- *
- * \param buf - is a buffer containing the on-disk HSM extended attribute.
- * \param rc - is the HSM xattr stored in \a buf
- * \param mh - is the md_hsm structure where to extract HSM attributes.
- */
-int lustre_buf2hsm(void *buf, int rc, struct md_hsm *mh)
-{
- struct hsm_attrs *attrs = (struct hsm_attrs *)buf;
-
- if (rc == 0 || rc == -ENODATA)
- /* no HSM attributes */
- return -ENODATA;
-
- if (rc < 0)
- /* error hit while fetching xattr */
- return rc;
-
- /* unpack HSM attributes */
- lustre_hsm_swab(attrs);
-
- /* fill md_hsm structure */
- mh->mh_compat = attrs->hsm_compat;
- mh->mh_flags = attrs->hsm_flags;
- mh->mh_arch_id = attrs->hsm_arch_id;
- mh->mh_arch_ver = attrs->hsm_arch_ver;
-
- return 0;
-}
-EXPORT_SYMBOL(lustre_buf2hsm);
-
-/*
- * Pack HSM attributes.
- *
- * \param buf - is the output buffer where to pack the on-disk HSM xattr.
- * \param mh - is the md_hsm structure to pack.
- */
-void lustre_hsm2buf(void *buf, struct md_hsm *mh)
-{
- struct hsm_attrs *attrs = (struct hsm_attrs *)buf;
-
- /* copy HSM attributes */
- attrs->hsm_compat = mh->mh_compat;
- attrs->hsm_flags = mh->mh_flags;
- attrs->hsm_arch_id = mh->mh_arch_id;
- attrs->hsm_arch_ver = mh->mh_arch_ver;
-
- /* pack xattr */
- lustre_hsm_swab(attrs);
-}
-EXPORT_SYMBOL(lustre_hsm2buf);
diff --git a/drivers/staging/lustre/lustre/obdclass/mea.c b/drivers/staging/lustre/lustre/obdclass/mea.c
deleted file mode 100644
index d6ce084da902..000000000000
--- a/drivers/staging/lustre/lustre/obdclass/mea.c
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * GPL HEADER START
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 only,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License version 2 for more details (a copy is included
- * in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU General Public License
- * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- *
- * GPL HEADER END
- */
-/*
- * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
- * Use is subject to license terms.
- */
-/*
- * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
- */
-
-#define DEBUG_SUBSYSTEM S_CLASS
-#include "../include/obd_class.h"
-#include <linux/kmod.h> /* for request_module() */
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/pagemap.h>
-#include "../include/lprocfs_status.h"
-#include "../include/lustre/lustre_idl.h"
-
-static int mea_last_char_hash(int count, char *name, int namelen)
-{
- unsigned int c;
-
- c = name[namelen - 1];
- if (c == 0)
- CWARN("looks like wrong len is passed\n");
- c = c % count;
- return c;
-}
-
-static int mea_all_chars_hash(int count, char *name, int namelen)
-{
- unsigned int c = 0;
-
- while (--namelen >= 0)
- c += name[namelen];
- c = c % count;
- return c;
-}
-
-int raw_name2idx(int hashtype, int count, const char *name, int namelen)
-{
- unsigned int c = 0;
- int idx;
-
- LASSERT(namelen > 0);
-
- if (filename_is_volatile(name, namelen, &idx)) {
- if ((idx >= 0) && (idx < count))
- return idx;
- goto hashchoice;
- }
-
- if (count <= 1)
- return 0;
-
-hashchoice:
- switch (hashtype) {
- case MEA_MAGIC_LAST_CHAR:
- c = mea_last_char_hash(count, (char *)name, namelen);
- break;
- case MEA_MAGIC_ALL_CHARS:
- c = mea_all_chars_hash(count, (char *)name, namelen);
- break;
- case MEA_MAGIC_HASH_SEGMENT:
- CERROR("Unsupported hash type MEA_MAGIC_HASH_SEGMENT\n");
- break;
- default:
- CERROR("Unknown hash type 0x%x\n", hashtype);
- }
-
- LASSERT(c < count);
- return c;
-}
-EXPORT_SYMBOL(raw_name2idx);
-
-int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen)
-{
- unsigned int c;
-
- LASSERT(mea && mea->mea_count);
-
- c = raw_name2idx(mea->mea_magic, mea->mea_count, name, namelen);
-
- LASSERT(c < mea->mea_count);
- return c;
-}
-EXPORT_SYMBOL(mea_name2idx);
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_config.c b/drivers/staging/lustre/lustre/obdclass/obd_config.c
index 0d81d3232f31..5e7b3d7cc984 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_config.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_config.c
@@ -365,7 +365,7 @@ int class_attach(struct lustre_cfg *lcfg)
obd = NULL;
CERROR("Cannot create device %s of type %s : %d\n",
name, typename, rc);
- GOTO(out, rc);
+ goto out;
}
LASSERTF(obd != NULL, "Cannot get obd device %s of type %s\n",
name, typename);
@@ -412,15 +412,18 @@ int class_attach(struct lustre_cfg *lcfg)
if (len >= sizeof(obd->obd_uuid)) {
CERROR("uuid must be < %d bytes long\n",
(int)sizeof(obd->obd_uuid));
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
}
memcpy(obd->obd_uuid.uuid, uuid, len);
/* do the attach */
if (OBP(obd, attach)) {
rc = OBP(obd, attach)(obd, sizeof(*lcfg), lcfg);
- if (rc)
- GOTO(out, rc = -EINVAL);
+ if (rc) {
+ rc = -EINVAL;
+ goto out;
+ }
}
/* Detach drops this */
@@ -494,8 +497,10 @@ int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
CFS_HASH_MIN_THETA,
CFS_HASH_MAX_THETA,
&uuid_hash_ops, CFS_HASH_DEFAULT);
- if (!obd->obd_uuid_hash)
- GOTO(err_hash, err = -ENOMEM);
+ if (!obd->obd_uuid_hash) {
+ err = -ENOMEM;
+ goto err_hash;
+ }
/* create a nid-export lustre hash */
obd->obd_nid_hash = cfs_hash_create("NID_HASH",
@@ -505,8 +510,10 @@ int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
CFS_HASH_MIN_THETA,
CFS_HASH_MAX_THETA,
&nid_hash_ops, CFS_HASH_DEFAULT);
- if (!obd->obd_nid_hash)
- GOTO(err_hash, err = -ENOMEM);
+ if (!obd->obd_nid_hash) {
+ err = -ENOMEM;
+ goto err_hash;
+ }
/* create a nid-stats lustre hash */
obd->obd_nid_stats_hash = cfs_hash_create("NID_STATS",
@@ -516,12 +523,16 @@ int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
CFS_HASH_MIN_THETA,
CFS_HASH_MAX_THETA,
&nid_stat_hash_ops, CFS_HASH_DEFAULT);
- if (!obd->obd_nid_stats_hash)
- GOTO(err_hash, err = -ENOMEM);
+ if (!obd->obd_nid_stats_hash) {
+ err = -ENOMEM;
+ goto err_hash;
+ }
exp = class_new_export(obd, &obd->obd_uuid);
- if (IS_ERR(exp))
- GOTO(err_hash, err = PTR_ERR(exp));
+ if (IS_ERR(exp)) {
+ err = PTR_ERR(exp);
+ goto err_hash;
+ }
obd->obd_self_export = exp;
list_del_init(&exp->exp_obd_chain_timed);
@@ -529,7 +540,7 @@ int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
err = obd_setup(obd, lcfg);
if (err)
- GOTO(err_exp, err);
+ goto err_exp;
obd->obd_set_up = 1;
@@ -856,21 +867,27 @@ int class_add_profile(int proflen, char *prof, int osclen, char *osc,
LASSERT(proflen == (strlen(prof) + 1));
OBD_ALLOC(lprof->lp_profile, proflen);
- if (lprof->lp_profile == NULL)
- GOTO(out, err = -ENOMEM);
+ if (lprof->lp_profile == NULL) {
+ err = -ENOMEM;
+ goto out;
+ }
memcpy(lprof->lp_profile, prof, proflen);
LASSERT(osclen == (strlen(osc) + 1));
OBD_ALLOC(lprof->lp_dt, osclen);
- if (lprof->lp_dt == NULL)
- GOTO(out, err = -ENOMEM);
+ if (lprof->lp_dt == NULL) {
+ err = -ENOMEM;
+ goto out;
+ }
memcpy(lprof->lp_dt, osc, osclen);
if (mdclen > 0) {
LASSERT(mdclen == (strlen(mdc) + 1));
OBD_ALLOC(lprof->lp_md, mdclen);
- if (lprof->lp_md == NULL)
- GOTO(out, err = -ENOMEM);
+ if (lprof->lp_md == NULL) {
+ err = -ENOMEM;
+ goto out;
+ }
memcpy(lprof->lp_md, mdc, mdclen);
}
@@ -1050,7 +1067,7 @@ static int process_param2_config(struct lustre_cfg *lcfg)
}
do_gettimeofday(&start);
- rc = USERMODEHELPER(argv[0], argv, NULL);
+ rc = call_usermodehelper(argv[0], argv, NULL, 1);
do_gettimeofday(&end);
if (rc < 0) {
@@ -1087,10 +1104,10 @@ int class_process_config(struct lustre_cfg *lcfg)
CDEBUG(D_IOCTL, "processing cmd: %x\n", lcfg->lcfg_command);
/* Commands that don't need a device */
- switch(lcfg->lcfg_command) {
+ switch (lcfg->lcfg_command) {
case LCFG_ATTACH: {
err = class_attach(lcfg);
- GOTO(out, err);
+ goto out;
}
case LCFG_ADD_UUID: {
CDEBUG(D_IOCTL, "adding mapping from uuid %s to nid %#llx (%s)\n",
@@ -1098,7 +1115,7 @@ int class_process_config(struct lustre_cfg *lcfg)
libcfs_nid2str(lcfg->lcfg_nid));
err = class_add_uuid(lustre_cfg_string(lcfg, 1), lcfg->lcfg_nid);
- GOTO(out, err);
+ goto out;
}
case LCFG_DEL_UUID: {
CDEBUG(D_IOCTL, "removing mappings for uuid %s\n",
@@ -1106,7 +1123,7 @@ int class_process_config(struct lustre_cfg *lcfg)
? "<all uuids>" : lustre_cfg_string(lcfg, 1));
err = class_del_uuid(lustre_cfg_string(lcfg, 1));
- GOTO(out, err);
+ goto out;
}
case LCFG_MOUNTOPT: {
CDEBUG(D_IOCTL, "mountopt: profile %s osc %s mdc %s\n",
@@ -1121,20 +1138,22 @@ int class_process_config(struct lustre_cfg *lcfg)
lustre_cfg_string(lcfg, 2),
LUSTRE_CFG_BUFLEN(lcfg, 3),
lustre_cfg_string(lcfg, 3));
- GOTO(out, err);
+ goto out;
}
case LCFG_DEL_MOUNTOPT: {
CDEBUG(D_IOCTL, "mountopt: profile %s\n",
lustre_cfg_string(lcfg, 1));
class_del_profile(lustre_cfg_string(lcfg, 1));
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case LCFG_SET_TIMEOUT: {
CDEBUG(D_IOCTL, "changing lustre timeout from %d to %d\n",
obd_timeout, lcfg->lcfg_num);
obd_timeout = max(lcfg->lcfg_num, 1U);
obd_timeout_set = 1;
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case LCFG_SET_LDLM_TIMEOUT: {
CDEBUG(D_IOCTL, "changing lustre ldlm_timeout from %d to %d\n",
@@ -1143,19 +1162,22 @@ int class_process_config(struct lustre_cfg *lcfg)
if (ldlm_timeout >= obd_timeout)
ldlm_timeout = max(obd_timeout / 3, 1U);
ldlm_timeout_set = 1;
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case LCFG_SET_UPCALL: {
LCONSOLE_ERROR_MSG(0x15a, "recovery upcall is deprecated\n");
/* COMPAT_146 Don't fail on old configs */
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case LCFG_MARKER: {
struct cfg_marker *marker;
marker = lustre_cfg_buf(lcfg, 1);
CDEBUG(D_IOCTL, "marker %d (%#x) %.16s %s\n", marker->cm_step,
marker->cm_flags, marker->cm_tgtname, marker->cm_comment);
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case LCFG_PARAM: {
char *tmp;
@@ -1164,7 +1186,7 @@ int class_process_config(struct lustre_cfg *lcfg)
PARAM_LLITE, NULL) == 0) &&
client_process_config) {
err = (*client_process_config)(lcfg);
- GOTO(out, err);
+ goto out;
} else if ((class_match_param(lustre_cfg_string(lcfg, 1),
PARAM_SYS, &tmp) == 0)) {
/* Global param settings */
@@ -1176,19 +1198,20 @@ int class_process_config(struct lustre_cfg *lcfg)
if (err != 0)
CWARN("Ignoring unknown param %s\n", tmp);
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
} else if ((class_match_param(lustre_cfg_string(lcfg, 1),
PARAM_QUOTA, &tmp) == 0) &&
quota_process_config) {
err = (*quota_process_config)(lcfg);
- GOTO(out, err);
+ goto out;
}
break;
}
case LCFG_SET_PARAM: {
err = process_param2_config(lcfg);
- GOTO(out, 0);
+ goto out;
}
}
/* Commands that require a device */
@@ -1200,55 +1223,60 @@ int class_process_config(struct lustre_cfg *lcfg)
CERROR("no device for: %s\n",
lustre_cfg_string(lcfg, 0));
- GOTO(out, err = -EINVAL);
+ err = -EINVAL;
+ goto out;
}
- switch(lcfg->lcfg_command) {
+ switch (lcfg->lcfg_command) {
case LCFG_SETUP: {
err = class_setup(obd, lcfg);
- GOTO(out, err);
+ goto out;
}
case LCFG_DETACH: {
err = class_detach(obd, lcfg);
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case LCFG_CLEANUP: {
err = class_cleanup(obd, lcfg);
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case LCFG_ADD_CONN: {
err = class_add_conn(obd, lcfg);
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case LCFG_DEL_CONN: {
err = class_del_conn(obd, lcfg);
- GOTO(out, err = 0);
+ err = 0;
+ goto out;
}
case LCFG_POOL_NEW: {
err = obd_pool_new(obd, lustre_cfg_string(lcfg, 2));
- GOTO(out, err = 0);
- break;
+ err = 0;
+ goto out;
}
case LCFG_POOL_ADD: {
err = obd_pool_add(obd, lustre_cfg_string(lcfg, 2),
lustre_cfg_string(lcfg, 3));
- GOTO(out, err = 0);
- break;
+ err = 0;
+ goto out;
}
case LCFG_POOL_REM: {
err = obd_pool_rem(obd, lustre_cfg_string(lcfg, 2),
lustre_cfg_string(lcfg, 3));
- GOTO(out, err = 0);
- break;
+ err = 0;
+ goto out;
}
case LCFG_POOL_DEL: {
err = obd_pool_del(obd, lustre_cfg_string(lcfg, 2));
- GOTO(out, err = 0);
- break;
+ err = 0;
+ goto out;
}
default: {
err = obd_process_config(obd, sizeof(*lcfg), lcfg);
- GOTO(out, err);
+ goto out;
}
}
@@ -1361,7 +1389,7 @@ int class_config_llog_handler(const struct lu_env *env,
{
struct config_llog_instance *clli = data;
int cfg_len = rec->lrh_len;
- char *cfg_buf = (char*) (rec + 1);
+ char *cfg_buf = (char *) (rec + 1);
int rc = 0;
//class_config_dump_handler(handle, rec, data);
@@ -1382,7 +1410,7 @@ int class_config_llog_handler(const struct lu_env *env,
rc = lustre_cfg_sanity_check(cfg_buf, cfg_len);
if (rc)
- GOTO(out, rc);
+ goto out;
/* Figure out config state info */
if (lcfg->lcfg_command == LCFG_MARKER) {
@@ -1469,8 +1497,10 @@ int class_config_llog_handler(const struct lu_env *env,
inst_len = LUSTRE_CFG_BUFLEN(lcfg, 0) +
sizeof(clli->cfg_instance) * 2 + 4;
OBD_ALLOC(inst_name, inst_len);
- if (inst_name == NULL)
- GOTO(out, rc = -ENOMEM);
+ if (inst_name == NULL) {
+ rc = -ENOMEM;
+ goto out;
+ }
sprintf(inst_name, "%s-%p",
lustre_cfg_string(lcfg, 0),
clli->cfg_instance);
@@ -1562,7 +1592,7 @@ int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
if (rc)
- GOTO(parse_out, rc);
+ goto parse_out;
/* continue processing from where we last stopped to end-of-log */
if (cfg) {
@@ -1674,7 +1704,7 @@ int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
rc = llog_init_handle(env, llh, LLOG_F_IS_PLAIN, NULL);
if (rc)
- GOTO(parse_out, rc);
+ goto parse_out;
rc = llog_process(env, llh, class_config_dump_handler, cfg, NULL);
parse_out:
@@ -1717,7 +1747,7 @@ int class_manual_cleanup(struct obd_device *obd)
rc = class_process_config(lcfg);
if (rc) {
CERROR("cleanup failed %d: %s\n", rc, obd->obd_name);
- GOTO(out, rc);
+ goto out;
}
/* the lcfg is almost the same for both ops */
diff --git a/drivers/staging/lustre/lustre/obdclass/obd_mount.c b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
index d972f71c9d97..1260c8713bc6 100644
--- a/drivers/staging/lustre/lustre/obdclass/obd_mount.c
+++ b/drivers/staging/lustre/lustre/obdclass/obd_mount.c
@@ -46,7 +46,7 @@
#define PRINT_CMD CDEBUG
#include "../include/obd.h"
-#include "../include/lvfs.h"
+#include "../include/linux/lustre_compat25.h"
#include "../include/obd_class.h"
#include "../include/lustre/lustre_user.h"
#include "../include/lustre_log.h"
@@ -174,7 +174,7 @@ int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd,
lcfg->lcfg_nid = nid;
rc = class_process_config(lcfg);
lustre_cfg_free(lcfg);
- return(rc);
+ return rc;
}
EXPORT_SYMBOL(do_lcfg);
@@ -256,15 +256,19 @@ int lustre_start_mgc(struct super_block *sb)
len = strlen(LUSTRE_MGC_OBDNAME) + strlen(libcfs_nid2str(nid)) + 1;
OBD_ALLOC(mgcname, len);
OBD_ALLOC(niduuid, len + 2);
- if (!mgcname || !niduuid)
- GOTO(out_free, rc = -ENOMEM);
+ if (!mgcname || !niduuid) {
+ rc = -ENOMEM;
+ goto out_free;
+ }
sprintf(mgcname, "%s%s", LUSTRE_MGC_OBDNAME, libcfs_nid2str(nid));
mgssec = lsi->lsi_lmd->lmd_mgssec ? lsi->lsi_lmd->lmd_mgssec : "";
OBD_ALLOC_PTR(data);
- if (data == NULL)
- GOTO(out_free, rc = -ENOMEM);
+ if (data == NULL) {
+ rc = -ENOMEM;
+ goto out_free;
+ }
obd = class_name2obd(mgcname);
if (obd && !obd->obd_stopping) {
@@ -274,7 +278,7 @@ int lustre_start_mgc(struct super_block *sb)
strlen(KEY_MGSSEC), KEY_MGSSEC,
strlen(mgssec), mgssec, NULL);
if (rc)
- GOTO(out_free, rc);
+ goto out_free;
/* Re-using an existing MGC */
atomic_inc(&obd->u.cli.cl_mgc_refcount);
@@ -318,12 +322,14 @@ int lustre_start_mgc(struct super_block *sb)
(using its local copy of the log), but we do want to connect
if at all possible. */
recov_bk++;
- CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,recov_bk);
+ CDEBUG(D_MOUNT, "%s: Set MGC reconnect %d\n", mgcname,
+ recov_bk);
rc = obd_set_info_async(NULL, obd->obd_self_export,
sizeof(KEY_INIT_RECOV_BACKUP),
KEY_INIT_RECOV_BACKUP,
sizeof(recov_bk), &recov_bk, NULL);
- GOTO(out, rc = 0);
+ rc = 0;
+ goto out;
}
CDEBUG(D_MOUNT, "Start MGC '%s'\n", mgcname);
@@ -349,7 +355,8 @@ int lustre_start_mgc(struct super_block *sb)
} else if (class_find_param(ptr, PARAM_MGSNODE,
&ptr) != 0) {
CERROR("No MGS nids given.\n");
- GOTO(out_free, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out_free;
}
while (class_parse_nid(ptr, &nid, &ptr) == 0) {
rc = do_lcfg(mgcname, nid,
@@ -372,7 +379,8 @@ int lustre_start_mgc(struct super_block *sb)
}
if (i == 0) {
CERROR("No valid MGS nids found.\n");
- GOTO(out_free, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out_free;
}
lsi->lsi_lmd->lmd_mgs_failnodes = 1;
@@ -387,7 +395,7 @@ int lustre_start_mgc(struct super_block *sb)
niduuid, NULL, NULL);
OBD_FREE_PTR(uuid);
if (rc)
- GOTO(out_free, rc);
+ goto out_free;
/* Add any failover MGS nids */
i = 1;
@@ -417,14 +425,15 @@ int lustre_start_mgc(struct super_block *sb)
obd = class_name2obd(mgcname);
if (!obd) {
CERROR("Can't find mgcobd %s\n", mgcname);
- GOTO(out_free, rc = -ENOTCONN);
+ rc = -ENOTCONN;
+ goto out_free;
}
rc = obd_set_info_async(NULL, obd->obd_self_export,
strlen(KEY_MGSSEC), KEY_MGSSEC,
strlen(mgssec), mgssec, NULL);
if (rc)
- GOTO(out_free, rc);
+ goto out_free;
/* Keep a refcount of servers/clients who started with "mount",
so we know when we can get rid of the mgc. */
@@ -448,7 +457,7 @@ int lustre_start_mgc(struct super_block *sb)
rc = obd_connect(NULL, &exp, obd, &(obd->obd_uuid), data, NULL);
if (rc) {
CERROR("connect failed %d\n", rc);
- GOTO(out, rc);
+ goto out;
}
obd->u.cli.cl_mgc_mgsexp = exp;
@@ -490,7 +499,8 @@ static int lustre_stop_mgc(struct super_block *sb)
will call in here. */
CDEBUG(D_MOUNT, "mgc still has %d references.\n",
atomic_read(&obd->u.cli.cl_mgc_refcount));
- GOTO(out, rc = -EBUSY);
+ rc = -EBUSY;
+ goto out;
}
/* The MGC has no recoverable data in any case.
@@ -516,11 +526,13 @@ static int lustre_stop_mgc(struct super_block *sb)
rc = class_manual_cleanup(obd);
if (rc)
- GOTO(out, rc);
+ goto out;
/* Clean the nid uuids */
- if (!niduuid)
- GOTO(out, rc = -ENOMEM);
+ if (!niduuid) {
+ rc = -ENOMEM;
+ goto out;
+ }
for (i = 0; i < lsi->lsi_lmd->lmd_mgs_failnodes; i++) {
sprintf(ptr, "_%x", i);
@@ -817,7 +829,7 @@ int lustre_check_exclusion(struct super_block *sb, char *svname)
CDEBUG(D_MOUNT, "Check exclusion %s (%d) in %d of %s\n", svname,
index, lmd->lmd_exclude_count, lmd->lmd_dev);
- for(i = 0; i < lmd->lmd_exclude_count; i++) {
+ for (i = 0; i < lmd->lmd_exclude_count; i++) {
if (index == lmd->lmd_exclude[i]) {
CWARN("Excluding %s (on exclusion list)\n", svname);
return 1;
@@ -1211,7 +1223,8 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
/* Figure out the lmd from the mount options */
if (lmd_parse((char *)(lmd2->lmd2_data), lmd)) {
lustre_put_lsi(sb);
- GOTO(out, rc = -EINVAL);
+ rc = -EINVAL;
+ goto out;
}
if (lmd_is_client(lmd)) {
@@ -1228,7 +1241,7 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
rc = lustre_start_mgc(sb);
if (rc) {
lustre_put_lsi(sb);
- GOTO(out, rc);
+ goto out;
}
/* Connect and start */
/* (should always be ll_fill_super) */
@@ -1243,7 +1256,7 @@ int lustre_fill_super(struct super_block *sb, void *data, int silent)
/* If error happens in fill_super() call, @lsi will be killed there.
* This is why we do not put it here. */
- GOTO(out, rc);
+ goto out;
out:
if (rc) {
CERROR("Unable to mount %s (%d)\n",
@@ -1276,7 +1289,10 @@ EXPORT_SYMBOL(lustre_register_kill_super_cb);
struct dentry *lustre_mount(struct file_system_type *fs_type, int flags,
const char *devname, void *data)
{
- struct lustre_mount_data2 lmd2 = { data, NULL };
+ struct lustre_mount_data2 lmd2 = {
+ .lmd2_data = data,
+ .lmd2_mnt = NULL
+ };
return mount_nodev(fs_type, flags, &lmd2, lustre_fill_super);
}
diff --git a/drivers/staging/lustre/lustre/obdclass/obdo.c b/drivers/staging/lustre/lustre/obdclass/obdo.c
index c9fa36b17919..307ffe347186 100644
--- a/drivers/staging/lustre/lustre/obdclass/obdo.c
+++ b/drivers/staging/lustre/lustre/obdclass/obdo.c
@@ -56,9 +56,9 @@ EXPORT_SYMBOL(obdo_set_parent_fid);
/* WARNING: the file systems must take care not to tinker with
attributes they don't manage (such as blocks). */
-void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
+void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid)
{
- obd_flag newvalid = 0;
+ u32 newvalid = 0;
if (valid & (OBD_MD_FLCTIME | OBD_MD_FLMTIME))
CDEBUG(D_INODE, "valid %x, new time %lu/%lu\n",
@@ -86,7 +86,7 @@ void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
newvalid |= OBD_MD_FLBLOCKS;
}
if (valid & OBD_MD_FLBLKSZ) { /* optimal block size */
- dst->o_blksize = ll_inode_blksize(src);
+ dst->o_blksize = 1 << src->i_blkbits;
newvalid |= OBD_MD_FLBLKSZ;
}
if (valid & OBD_MD_FLTYPE) {
@@ -108,14 +108,14 @@ void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid)
newvalid |= OBD_MD_FLGID;
}
if (valid & OBD_MD_FLFLAGS) {
- dst->o_flags = ll_inode_flags(src);
+ dst->o_flags = src->i_flags;
newvalid |= OBD_MD_FLFLAGS;
}
dst->o_valid |= newvalid;
}
EXPORT_SYMBOL(obdo_from_inode);
-void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid)
+void obdo_cpy_md(struct obdo *dst, struct obdo *src, u32 valid)
{
CDEBUG(D_INODE, "src obdo "DOSTID" valid %#llx, dst obdo "DOSTID"\n",
POSTID(&src->o_oi), src->o_valid, POSTID(&dst->o_oi));
@@ -157,43 +157,43 @@ void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid)
EXPORT_SYMBOL(obdo_cpy_md);
/* returns FALSE if comparison (by flags) is same, TRUE if changed */
-int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare)
+int obdo_cmp_md(struct obdo *dst, struct obdo *src, u32 compare)
{
int res = 0;
- if ( compare & OBD_MD_FLATIME )
- res = (res || (dst->o_atime != src->o_atime));
- if ( compare & OBD_MD_FLMTIME )
- res = (res || (dst->o_mtime != src->o_mtime));
- if ( compare & OBD_MD_FLCTIME )
- res = (res || (dst->o_ctime != src->o_ctime));
- if ( compare & OBD_MD_FLSIZE )
- res = (res || (dst->o_size != src->o_size));
- if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
- res = (res || (dst->o_blocks != src->o_blocks));
- if ( compare & OBD_MD_FLBLKSZ )
- res = (res || (dst->o_blksize != src->o_blksize));
- if ( compare & OBD_MD_FLTYPE )
- res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
- if ( compare & OBD_MD_FLMODE )
- res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
- if ( compare & OBD_MD_FLUID )
- res = (res || (dst->o_uid != src->o_uid));
- if ( compare & OBD_MD_FLGID )
- res = (res || (dst->o_gid != src->o_gid));
- if ( compare & OBD_MD_FLFLAGS )
- res = (res || (dst->o_flags != src->o_flags));
- if ( compare & OBD_MD_FLNLINK )
- res = (res || (dst->o_nlink != src->o_nlink));
- if ( compare & OBD_MD_FLFID ) {
- res = (res || (dst->o_parent_seq != src->o_parent_seq));
- res = (res || (dst->o_parent_ver != src->o_parent_ver));
- }
- if ( compare & OBD_MD_FLGENER )
- res = (res || (dst->o_parent_oid != src->o_parent_oid));
+ if (compare & OBD_MD_FLATIME)
+ res |= dst->o_atime != src->o_atime;
+ if (compare & OBD_MD_FLMTIME)
+ res |= dst->o_mtime != src->o_mtime;
+ if (compare & OBD_MD_FLCTIME)
+ res |= dst->o_ctime != src->o_ctime;
+ if (compare & OBD_MD_FLSIZE)
+ res |= dst->o_size != src->o_size;
+ if (compare & OBD_MD_FLBLOCKS) /* allocation of space */
+ res |= dst->o_blocks != src->o_blocks;
+ if (compare & OBD_MD_FLBLKSZ)
+ res |= dst->o_blksize != src->o_blksize;
+ if (compare & OBD_MD_FLTYPE)
+ res |= ((dst->o_mode ^ src->o_mode) & S_IFMT) != 0;
+ if (compare & OBD_MD_FLMODE)
+ res |= ((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0;
+ if (compare & OBD_MD_FLUID)
+ res |= dst->o_uid != src->o_uid;
+ if (compare & OBD_MD_FLGID)
+ res |= dst->o_gid != src->o_gid;
+ if (compare & OBD_MD_FLFLAGS)
+ res |= dst->o_flags != src->o_flags;
+ if (compare & OBD_MD_FLNLINK)
+ res |= dst->o_nlink != src->o_nlink;
+ if (compare & OBD_MD_FLFID) {
+ res |= dst->o_parent_seq != src->o_parent_seq;
+ res |= dst->o_parent_ver != src->o_parent_ver;
+ }
+ if (compare & OBD_MD_FLGENER)
+ res |= dst->o_parent_oid != src->o_parent_oid;
/* XXX Don't know if these should be included here - wasn't previously
if ( compare & OBD_MD_FLINLINE )
- res = (res || memcmp(dst->o_inline, src->o_inline));
+ res |= memcmp(dst->o_inline, src->o_inline);
*/
return res;
}
@@ -247,7 +247,7 @@ void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned int ia_valid)
}
EXPORT_SYMBOL(obdo_from_iattr);
-void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid)
+void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid)
{
valid &= oa->o_valid;
@@ -296,7 +296,7 @@ void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid)
}
EXPORT_SYMBOL(iattr_from_obdo);
-void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid)
+void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid)
{
iattr_from_obdo(&op_data->op_attr, oa, valid);
if (valid & OBD_MD_FLBLOCKS) {
diff --git a/drivers/staging/lustre/lustre/obdclass/statfs_pack.c b/drivers/staging/lustre/lustre/obdclass/statfs_pack.c
index 33b1a83f4014..cc785ab3f29a 100644
--- a/drivers/staging/lustre/lustre/obdclass/statfs_pack.c
+++ b/drivers/staging/lustre/lustre/obdclass/statfs_pack.c
@@ -40,7 +40,7 @@
#define DEBUG_SUBSYSTEM S_CLASS
-
+#include <linux/statfs.h>
#include "../include/lustre_export.h"
#include "../include/lustre_net.h"
#include "../include/obd_support.h"