1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * linux/fs/obdfilter/filter.c
6 * Copyright (C) 2001, 2002 Cluster File Systems, Inc.
8 * This code is issued under the GNU General Public License.
9 * See the file COPYING in this distribution
11 * by Peter Braam <braam@clusterfs.com>
12 * and Andreas Dilger <adilger@clusterfs.com>
16 #define DEBUG_SUBSYSTEM S_FILTER
18 #include <linux/module.h>
19 #include <linux/pagemap.h>
21 #include <linux/dcache.h>
22 #include <linux/obd_class.h>
23 #include <linux/lustre_dlm.h>
24 #include <linux/obd_filter.h>
25 #include <linux/ext3_jbd.h>
26 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
27 #include <linux/extN_jbd.h>
29 #include <linux/quotaops.h>
30 #include <linux/init.h>
31 #include <linux/random.h>
32 #include <linux/stringify.h>
34 static kmem_cache_t *filter_open_cache;
35 static kmem_cache_t *filter_dentry_cache;
37 #define FILTER_ROOTINO 2
38 #define FILTER_ROOTINO_STR __stringify(FILTER_ROOTINO)
41 static char *obd_type_by_mode[S_IFMT >> S_SHIFT] = {
43 [S_IFREG >> S_SHIFT] "R",
44 [S_IFDIR >> S_SHIFT] "D",
45 [S_IFCHR >> S_SHIFT] "C",
46 [S_IFBLK >> S_SHIFT] "B",
47 [S_IFIFO >> S_SHIFT] "F",
48 [S_IFSOCK >> S_SHIFT] "S",
49 [S_IFLNK >> S_SHIFT] "L"
52 static inline const char *obd_mode_to_type(int mode)
54 return obd_type_by_mode[(mode & S_IFMT) >> S_SHIFT];
57 /* write the pathname into the string */
58 static int filter_id(char *buf, obd_id id, obd_mode mode)
60 return sprintf(buf, "O/%s/"LPU64, obd_mode_to_type(mode), id);
63 static inline void f_dput(struct dentry *dentry)
65 /* Can't go inside filter_ddelete because it can block */
66 CDEBUG(D_INODE, "putting %s: %p, count = %d\n",
67 dentry->d_name.name, dentry, atomic_read(&dentry->d_count) - 1);
68 LASSERT(atomic_read(&dentry->d_count) > 0);
73 /* Not racy w.r.t. others, because we are the only user of this dentry */
74 static void filter_drelease(struct dentry *dentry)
77 kmem_cache_free(filter_dentry_cache, dentry->d_fsdata);
80 struct dentry_operations filter_dops = {
81 .d_release = filter_drelease,
84 /* setup the object store with correct subdirectories */
85 static int filter_prep(struct obd_device *obd)
87 struct obd_run_ctxt saved;
88 struct filter_obd *filter = &obd->u.filter;
89 struct dentry *dentry;
97 push_ctxt(&saved, &filter->fo_ctxt, NULL);
98 dentry = simple_mkdir(current->fs->pwd, "O", 0700);
99 CDEBUG(D_INODE, "got/created O: %p\n", dentry);
100 if (IS_ERR(dentry)) {
101 rc = PTR_ERR(dentry);
102 CERROR("cannot open/create O: rc = %d\n", rc);
105 filter->fo_dentry_O = dentry;
106 dentry = simple_mkdir(current->fs->pwd, "P", 0700);
107 CDEBUG(D_INODE, "got/created P: %p\n", dentry);
108 if (IS_ERR(dentry)) {
109 rc = PTR_ERR(dentry);
110 CERROR("cannot open/create P: rc = %d\n", rc);
114 dentry = simple_mkdir(current->fs->pwd, "D", 0700);
115 CDEBUG(D_INODE, "got/created D: %p\n", dentry);
116 if (IS_ERR(dentry)) {
117 rc = PTR_ERR(dentry);
118 CERROR("cannot open/create D: rc = %d\n", rc);
122 root = simple_mknod(dentry, FILTER_ROOTINO_STR, S_IFREG | 0755);
126 CERROR("OBD filter: cannot open/create root %d: rc = %d\n",
133 * Create directories and/or get dentries for each object type.
134 * This saves us from having to do multiple lookups for each one.
136 for (mode = 0; mode < (S_IFMT >> S_SHIFT); mode++) {
137 char *type = obd_type_by_mode[mode];
140 filter->fo_dentry_O_mode[mode] = NULL;
143 dentry = simple_mkdir(filter->fo_dentry_O, type, 0700);
144 CDEBUG(D_INODE, "got/created O/%s: %p\n", type, dentry);
145 if (IS_ERR(dentry)) {
146 rc = PTR_ERR(dentry);
147 CERROR("cannot create O/%s: rc = %d\n", type, rc);
148 GOTO(out_O_mode, rc);
150 filter->fo_dentry_O_mode[mode] = dentry;
153 file = filp_open("D/status", O_RDWR | O_CREAT, 0700);
154 if ( !file || IS_ERR(file) ) {
156 CERROR("OBD filter: cannot open/create status %s: rc = %d\n",
158 GOTO(out_O_mode, rc);
161 /* steal operations */
162 inode = file->f_dentry->d_inode;
163 filter->fo_fop = file->f_op;
164 filter->fo_iop = inode->i_op;
165 filter->fo_aops = inode->i_mapping->a_ops;
167 if (inode->i_size == 0) {
168 __u64 disk_lastobjid = cpu_to_le64(lastobjid);
169 ssize_t retval = file->f_op->write(file,(char *)&disk_lastobjid,
170 sizeof(disk_lastobjid),
172 if (retval != sizeof(disk_lastobjid)) {
173 CDEBUG(D_INODE,"OBD filter: error writing lastobjid\n");
175 GOTO(out_O_mode, rc = -EIO);
178 __u64 disk_lastobjid;
179 ssize_t retval = file->f_op->read(file, (char *)&disk_lastobjid,
180 sizeof(disk_lastobjid),
182 if (retval != sizeof(disk_lastobjid)) {
183 CDEBUG(D_INODE,"OBD filter: error reading lastobjid\n");
185 GOTO(out_O_mode, rc = -EIO);
187 lastobjid = le64_to_cpu(disk_lastobjid);
189 filter->fo_lastobjid = lastobjid;
200 struct dentry *dentry = filter->fo_dentry_O_mode[mode];
203 filter->fo_dentry_O_mode[mode] = NULL;
207 f_dput(filter->fo_dentry_O);
208 filter->fo_dentry_O = NULL;
212 /* cleanup the filter: write last used object id to status file */
213 static void filter_post(struct obd_device *obd)
215 struct obd_run_ctxt saved;
216 struct filter_obd *filter = &obd->u.filter;
217 __u64 disk_lastobjid;
222 push_ctxt(&saved, &filter->fo_ctxt, NULL);
223 file = filp_open("D/status", O_RDWR | O_CREAT, 0700);
225 CERROR("OBD filter: cannot create status file\n");
230 disk_lastobjid = cpu_to_le64(filter->fo_lastobjid);
231 rc = file->f_op->write(file, (char *)&disk_lastobjid,
232 sizeof(disk_lastobjid), &file->f_pos);
233 if (rc != sizeof(disk_lastobjid))
234 CERROR("OBD filter: error writing lastobjid: rc = %ld\n", rc);
236 rc = filp_close(file, NULL);
238 CERROR("OBD filter: cannot close status file: rc = %ld\n", rc);
240 for (mode = 0; mode < (S_IFMT >> S_SHIFT); mode++) {
241 struct dentry *dentry = filter->fo_dentry_O_mode[mode];
244 filter->fo_dentry_O_mode[mode] = NULL;
247 f_dput(filter->fo_dentry_O);
253 static __u64 filter_next_id(struct obd_device *obd)
257 spin_lock(&obd->u.filter.fo_objidlock);
258 id = ++obd->u.filter.fo_lastobjid;
259 spin_unlock(&obd->u.filter.fo_objidlock);
261 /* FIXME: write the lastobjid to disk here */
265 /* how to get files, dentries, inodes from object id's */
266 /* parent i_sem is already held if needed for exclusivity */
267 static struct dentry *filter_fid2dentry(struct obd_device *obd,
268 struct dentry *dparent,
269 __u64 id, __u32 type)
271 struct super_block *sb = obd->u.filter.fo_sb;
272 struct dentry *dchild;
277 if (!sb || !sb->s_dev) {
278 CERROR("fatal: device not initialized.\n");
279 RETURN(ERR_PTR(-ENXIO));
283 CERROR("fatal: invalid object #0\n");
285 RETURN(ERR_PTR(-ESTALE));
288 if (!(type & S_IFMT)) {
289 CERROR("OBD %s, object "LPU64" has bad type: %o\n",
290 __FUNCTION__, id, type);
291 RETURN(ERR_PTR(-EINVAL));
294 len = sprintf(name, LPU64, id);
295 CDEBUG(D_INODE, "opening object O/%s/%s\n", obd_mode_to_type(type),
297 dchild = lookup_one_len(name, dparent, len);
298 if (IS_ERR(dchild)) {
299 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
304 dchild->d_op = &filter_dops;
306 LASSERT(dchild->d_op == &filter_dops);
308 CDEBUG(D_INODE, "got child obj O/%s/%s: %p, count = %d\n",
309 obd_mode_to_type(type), name, dchild,
310 atomic_read(&dchild->d_count));
312 LASSERT(atomic_read(&dchild->d_count) > 0);
317 static inline struct dentry *filter_parent(struct obd_device *obd,
320 struct filter_obd *filter = &obd->u.filter;
322 return filter->fo_dentry_O_mode[(mode & S_IFMT) >> S_SHIFT];
325 static struct file *filter_obj_open(struct obd_export *export,
326 __u64 id, __u32 type)
328 struct filter_obd *filter = &export->exp_obd->u.filter;
329 struct super_block *sb = filter->fo_sb;
330 struct filter_export_data *fed = &export->exp_filter_data;
331 struct filter_dentry_data *fdd;
332 struct filter_file_data *ffd;
333 struct obd_run_ctxt saved;
338 if (!sb || !sb->s_dev) {
339 CERROR("fatal: device not initialized.\n");
340 RETURN(ERR_PTR(-ENXIO));
344 CERROR("fatal: invalid obdo "LPU64"\n", id);
345 RETURN(ERR_PTR(-ESTALE));
348 if (!(type & S_IFMT)) {
349 CERROR("OBD %s, object "LPU64" has bad type: %o\n",
350 __FUNCTION__, id, type);
351 RETURN(ERR_PTR(-EINVAL));
354 ffd = kmem_cache_alloc(filter_open_cache, SLAB_KERNEL);
356 CERROR("obdfilter: out of memory\n");
357 RETURN(ERR_PTR(-ENOMEM));
360 /* We preallocate this to avoid blocking while holding fo_fddlock */
361 fdd = kmem_cache_alloc(filter_dentry_cache, SLAB_KERNEL);
363 CERROR("obdfilter: out of memory\n");
364 GOTO(out_ffd, file = ERR_PTR(-ENOMEM));
367 filter_id(name, id, type);
368 push_ctxt(&saved, &filter->fo_ctxt, NULL);
369 file = filp_open(name, O_RDONLY | O_LARGEFILE, 0 /* type? */);
375 spin_lock(&filter->fo_fddlock);
376 if (file->f_dentry->d_fsdata) {
377 spin_unlock(&filter->fo_fddlock);
378 kmem_cache_free(filter_dentry_cache, fdd);
379 fdd = file->f_dentry->d_fsdata;
380 LASSERT(kmem_cache_validate(filter_dentry_cache, fdd));
381 /* should only happen during client recovery */
382 if (fdd->fdd_flags & FILTER_FLAG_DESTROY)
383 CDEBUG(D_INODE,"opening destroyed object "LPX64"\n",id);
384 atomic_inc(&fdd->fdd_open_count);
386 atomic_set(&fdd->fdd_open_count, 1);
388 /* If this is racy, then we can use {cmp}xchg and atomic_add */
389 file->f_dentry->d_fsdata = fdd;
390 spin_unlock(&filter->fo_fddlock);
393 get_random_bytes(&ffd->ffd_servercookie, sizeof(ffd->ffd_servercookie));
394 ffd->ffd_file = file;
395 file->private_data = ffd;
397 spin_lock(&fed->fed_lock);
398 list_add(&ffd->ffd_export_list, &fed->fed_open_head);
399 spin_unlock(&fed->fed_lock);
401 CDEBUG(D_INODE, "opening objid "LPX64": rc = %p\n", id, file);
407 kmem_cache_free(filter_dentry_cache, fdd);
409 ffd->ffd_servercookie = DEAD_HANDLE_MAGIC;
410 kmem_cache_free(filter_open_cache, ffd);
414 /* Caller must hold i_sem on dir_dentry->d_inode */
415 static int filter_destroy_internal(struct obd_device *obd,
416 struct dentry *dir_dentry,
417 struct dentry *object_dentry)
419 struct obd_run_ctxt saved;
420 struct inode *inode = object_dentry->d_inode;
424 if (inode->i_nlink != 1 || atomic_read(&inode->i_count) != 1) {
425 CERROR("destroying objid %*s nlink = %d, count = %d\n",
426 object_dentry->d_name.len,
427 object_dentry->d_name.name,
428 inode->i_nlink, atomic_read(&inode->i_count));
431 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
432 rc = vfs_unlink(dir_dentry->d_inode, object_dentry);
433 /* XXX unlink from PENDING directory now too */
437 CERROR("error unlinking objid %*s: rc %d\n",
438 object_dentry->d_name.len,
439 object_dentry->d_name.name, rc);
444 static int filter_close_internal(struct obd_device *obd,
445 struct filter_file_data *ffd)
447 struct file *filp = ffd->ffd_file;
448 struct dentry *object_dentry = dget(filp->f_dentry);
449 struct filter_dentry_data *fdd = object_dentry->d_fsdata;
453 LASSERT(filp->private_data == ffd);
456 rc = filp_close(filp, 0);
458 if (atomic_dec_and_test(&fdd->fdd_open_count) &&
459 fdd->fdd_flags & FILTER_FLAG_DESTROY) {
460 struct dentry *dir_dentry = filter_parent(obd, S_IFREG);
462 down(&dir_dentry->d_inode->i_sem);
463 rc2 = filter_destroy_internal(obd, dir_dentry, object_dentry);
466 up(&dir_dentry->d_inode->i_sem);
469 f_dput(object_dentry);
470 kmem_cache_free(filter_open_cache, ffd);
476 static int filter_connect(struct lustre_handle *conn, struct obd_device *obd,
477 obd_uuid_t cluuid, struct recovd_obd *recovd,
478 ptlrpc_recovery_cb_t recover)
480 struct obd_export *exp;
485 rc = class_connect(conn, obd, cluuid);
488 exp = class_conn2export(conn);
491 INIT_LIST_HEAD(&exp->exp_filter_data.fed_open_head);
492 spin_lock_init(&exp->exp_filter_data.fed_lock);
501 static int filter_disconnect(struct lustre_handle *conn)
503 struct obd_export *exp = class_conn2export(conn);
504 struct filter_export_data *fed;
509 fed = &exp->exp_filter_data;
510 spin_lock(&fed->fed_lock);
511 while (!list_empty(&fed->fed_open_head)) {
512 struct filter_file_data *ffd;
514 ffd = list_entry(fed->fed_open_head.next, typeof(*ffd),
516 list_del(&ffd->ffd_export_list);
517 spin_unlock(&fed->fed_lock);
519 CERROR("force closing file %*s on disconnect\n",
520 ffd->ffd_file->f_dentry->d_name.len,
521 ffd->ffd_file->f_dentry->d_name.name);
523 filter_close_internal(exp->exp_obd, ffd);
524 spin_lock(&fed->fed_lock);
526 spin_unlock(&fed->fed_lock);
528 ldlm_cancel_locks_for_export(exp);
529 rc = class_disconnect(conn);
533 /* XXX cleanup preallocated inodes */
537 /* mount the file system (secretly) */
538 static int filter_setup(struct obd_device *obd, obd_count len, void *buf)
540 struct obd_ioctl_data* data = buf;
541 struct filter_obd *filter;
542 struct vfsmount *mnt;
546 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2)
550 mnt = do_kern_mount(data->ioc_inlbuf2, 0, data->ioc_inlbuf1, NULL);
555 filter = &obd->u.filter;;
556 filter->fo_vfsmnt = mnt;
557 filter->fo_fstype = strdup(data->ioc_inlbuf2);
558 filter->fo_sb = mnt->mnt_root->d_inode->i_sb;
559 CERROR("%s: mnt is %p\n", data->ioc_inlbuf1, filter->fo_vfsmnt);
560 /* XXX is this even possible if do_kern_mount succeeded? */
562 GOTO(err_kfree, err = -ENODEV);
564 OBD_SET_CTXT_MAGIC(&filter->fo_ctxt);
565 filter->fo_ctxt.pwdmnt = mnt;
566 filter->fo_ctxt.pwd = mnt->mnt_root;
567 filter->fo_ctxt.fs = get_ds();
569 err = filter_prep(obd);
571 GOTO(err_kfree, err);
572 spin_lock_init(&filter->fo_fddlock);
573 spin_lock_init(&filter->fo_objidlock);
574 INIT_LIST_HEAD(&filter->fo_export_list);
577 ldlm_namespace_new("filter-tgt", LDLM_NAMESPACE_SERVER);
578 if (obd->obd_namespace == NULL)
581 ptlrpc_init_client(LDLM_REQUEST_PORTAL, LDLM_REPLY_PORTAL,
582 "filter_ldlm_client", &obd->obd_ldlm_client);
587 kfree(filter->fo_fstype);
589 mntput(filter->fo_vfsmnt);
599 static int filter_cleanup(struct obd_device *obd)
601 struct super_block *sb;
604 if (!list_empty(&obd->obd_exports)) {
605 CERROR("still has clients!\n");
606 class_disconnect_all(obd);
607 if (!list_empty(&obd->obd_exports)) {
608 CERROR("still has exports after forced cleanup?\n");
613 ldlm_namespace_free(obd->obd_namespace);
615 sb = obd->u.filter.fo_sb;
616 if (!obd->u.filter.fo_sb)
621 shrink_dcache_parent(sb->s_root);
623 mntput(obd->u.filter.fo_vfsmnt);
624 obd->u.filter.fo_sb = 0;
625 kfree(obd->u.filter.fo_fstype);
634 static void filter_from_inode(struct obdo *oa, struct inode *inode, int valid)
636 int type = oa->o_mode & S_IFMT;
639 CDEBUG(D_INFO, "src inode %ld (%p), dst obdo %ld valid 0x%08x\n",
640 inode->i_ino, inode, (long)oa->o_id, valid);
641 /* Don't copy the inode number in place of the object ID */
642 obdo_from_inode(oa, inode, valid);
643 oa->o_mode &= ~S_IFMT;
646 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
647 obd_rdev rdev = kdev_t_to_nr(inode->i_rdev);
649 oa->o_valid |= OBD_MD_FLRDEV;
655 static struct filter_file_data *filter_handle2ffd(struct lustre_handle *handle)
657 struct filter_file_data *ffd = NULL;
660 if (!handle || !handle->addr)
663 ffd = (struct filter_file_data *)(unsigned long)(handle->addr);
664 if (!kmem_cache_validate(filter_open_cache, (void *)ffd))
667 if (ffd->ffd_servercookie != handle->cookie)
670 LASSERT(ffd->ffd_file->private_data == ffd);
674 static struct dentry *__filter_oa2dentry(struct lustre_handle *conn,
675 struct obdo *oa, char *what)
677 struct dentry *dentry = NULL;
679 if (oa->o_valid & OBD_MD_FLHANDLE) {
680 struct lustre_handle *ost_handle = obdo_handle(oa);
681 struct filter_file_data *ffd = filter_handle2ffd(ost_handle);
684 dentry = dget(ffd->ffd_file->f_dentry);
688 struct obd_device *obd = class_conn2obd(conn);
690 CERROR("invalid client "LPX64"\n", conn->addr);
691 RETURN(ERR_PTR(-EINVAL));
693 dentry = filter_fid2dentry(obd, filter_parent(obd, oa->o_mode),
694 oa->o_id, oa->o_mode);
697 if (!dentry->d_inode) {
698 CERROR("%s on non-existent object: "LPU64"\n", what, oa->o_id);
700 dentry = ERR_PTR(-ENOENT);
706 #define filter_oa2dentry(conn, oa) __filter_oa2dentry(conn, oa, __FUNCTION__)
708 static int filter_getattr(struct lustre_handle *conn, struct obdo *oa,
709 struct lov_stripe_md *md)
711 struct dentry *dentry = NULL;
715 dentry = filter_oa2dentry(conn, oa);
717 RETURN(PTR_ERR(dentry));
719 filter_from_inode(oa, dentry->d_inode, oa->o_valid);
725 static int filter_setattr(struct lustre_handle *conn, struct obdo *oa,
726 struct lov_stripe_md *md)
728 struct obd_run_ctxt saved;
729 struct obd_device *obd = class_conn2obd(conn);
730 struct dentry *dentry;
736 dentry = filter_oa2dentry(conn, oa);
739 RETURN(PTR_ERR(dentry));
741 iattr_from_obdo(&iattr, oa, oa->o_valid);
742 iattr.ia_mode = (iattr.ia_mode & ~S_IFMT) | S_IFREG;
743 inode = dentry->d_inode;
746 if (iattr.ia_valid & ATTR_SIZE)
748 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
749 if (inode->i_op->setattr)
750 rc = inode->i_op->setattr(dentry, &iattr);
752 rc = inode_setattr(inode, &iattr);
754 if (iattr.ia_valid & ATTR_SIZE) {
756 oa->o_valid = OBD_MD_FLBLOCKS | OBD_MD_FLCTIME | OBD_MD_FLMTIME;
757 obdo_from_inode(oa, inode, oa->o_valid);
765 static int filter_open(struct lustre_handle *conn, struct obdo *oa,
766 struct lov_stripe_md *ea)
768 struct obd_export *export;
769 struct lustre_handle *handle;
770 struct filter_file_data *ffd;
775 export = class_conn2export(conn);
777 CDEBUG(D_IOCTL, "fatal: invalid client "LPX64"\n", conn->addr);
781 filp = filter_obj_open(export, oa->o_id, oa->o_mode);
783 GOTO(out, rc = PTR_ERR(filp));
785 filter_from_inode(oa, filp->f_dentry->d_inode, oa->o_valid);
787 ffd = filp->private_data;
788 handle = obdo_handle(oa);
789 handle->addr = (__u64)(unsigned long)ffd;
790 handle->cookie = ffd->ffd_servercookie;
791 oa->o_valid |= OBD_MD_FLHANDLE;
796 static int filter_close(struct lustre_handle *conn, struct obdo *oa,
797 struct lov_stripe_md *ea)
799 struct obd_export *exp;
800 struct filter_file_data *ffd;
801 struct filter_export_data *fed;
805 exp = class_conn2export(conn);
807 CDEBUG(D_IOCTL, "fatal: invalid client "LPX64"\n", conn->addr);
811 if (!(oa->o_valid & OBD_MD_FLHANDLE)) {
812 CERROR("no handle for close of objid "LPX64"\n", oa->o_id);
816 ffd = filter_handle2ffd(obdo_handle(oa));
818 struct lustre_handle *handle = obdo_handle(oa);
819 CERROR("bad handle ("LPX64") or cookie ("LPX64") for close\n",
820 handle->addr, handle->cookie);
824 fed = &exp->exp_filter_data;
825 spin_lock(&fed->fed_lock);
826 list_del(&ffd->ffd_export_list);
827 spin_unlock(&fed->fed_lock);
829 rc = filter_close_internal(exp->exp_obd, ffd);
834 static int filter_create(struct lustre_handle *conn, struct obdo *oa,
835 struct lov_stripe_md **ea)
837 struct obd_device *obd = class_conn2obd(conn);
839 struct obd_run_ctxt saved;
845 CERROR("invalid client "LPX64"\n", conn->addr);
849 if (!(oa->o_mode & S_IFMT)) {
850 CERROR("OBD %s, object "LPU64" has bad type: %o\n",
851 __FUNCTION__, oa->o_id, oa->o_mode);
855 oa->o_id = filter_next_id(obd);
857 //filter_id(name, oa->o_id, oa->o_mode);
858 sprintf(name, LPU64, oa->o_id);
859 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
860 new = simple_mknod(filter_parent(obd, oa->o_mode), name, oa->o_mode);
863 CERROR("Error mknod obj %s, err %ld\n", name, PTR_ERR(new));
867 /* Set flags for fields we have set in the inode struct */
868 oa->o_valid = OBD_MD_FLID | OBD_MD_FLBLKSZ | OBD_MD_FLBLOCKS |
869 OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME;
870 filter_from_inode(oa, new->d_inode, oa->o_valid);
876 static int filter_destroy(struct lustre_handle *conn, struct obdo *oa,
877 struct lov_stripe_md *ea)
879 struct obd_device *obd = class_conn2obd(conn);
880 struct dentry *dir_dentry, *object_dentry;
881 struct filter_dentry_data *fdd = object_dentry->d_fsdata;
886 CERROR("invalid client "LPX64"\n", conn->addr);
890 CDEBUG(D_INODE, "destroying objid "LPX64"\n", oa->o_id);
892 dir_dentry = filter_parent(obd, oa->o_mode);
893 down(&dir_dentry->d_inode->i_sem);
895 object_dentry = filter_oa2dentry(conn, oa);
896 if (IS_ERR(object_dentry))
897 GOTO(out, rc = -ENOENT);
899 if (fdd && atomic_read(&fdd->fdd_open_count)) {
900 struct filter_dentry_data *fdd = object_dentry->d_fsdata;
902 if (!(fdd->fdd_flags & FILTER_FLAG_DESTROY)) {
903 fdd->fdd_flags |= FILTER_FLAG_DESTROY;
904 /* XXX put into PENDING directory in case of crash */
906 "defer destroy of %dx open objid "LPX64"\n",
907 atomic_read(&fdd->fdd_open_count), oa->o_id);
910 "repeat destroy of %dx open objid "LPX64"\n",
911 atomic_read(&fdd->fdd_open_count), oa->o_id);
912 GOTO(out_dput, rc = 0);
915 rc = filter_destroy_internal(obd, dir_dentry, object_dentry);
917 f_dput(object_dentry);
921 up(&dir_dentry->d_inode->i_sem);
925 /* NB count and offset are used for punch, but not truncate */
926 static int filter_truncate(struct lustre_handle *conn, struct obdo *oa,
927 struct lov_stripe_md *lsm,
928 obd_off start, obd_off end)
933 if (end != OBD_OBJECT_EOF)
934 CERROR("PUNCH not supported, only truncate works\n");
936 CDEBUG(D_INODE, "calling truncate for object "LPX64", valid = %x, "
937 "o_size = "LPD64"\n", oa->o_id, oa->o_valid, start);
939 error = filter_setattr(conn, oa, NULL);
943 static int filter_pgcache_brw(int cmd, struct lustre_handle *conn,
944 struct lov_stripe_md *lsm, obd_count oa_bufs,
945 struct brw_page *pga, brw_callback_t callback,
946 struct io_cb_data *data)
948 struct obd_export *export = class_conn2export(conn);
949 struct obd_run_ctxt saved;
950 struct super_block *sb;
951 int pnum; /* index to pages (bufs) */
952 unsigned long retval;
959 CDEBUG(D_IOCTL, "invalid client "LPX64"\n", conn->addr);
963 sb = export->exp_obd->u.filter.fo_sb;
964 push_ctxt(&saved, &export->exp_obd->u.filter.fo_ctxt, NULL);
965 pnum = 0; /* pnum indexes buf 0..num_pages */
967 file = filter_obj_open(export, lsm->lsm_object_id, S_IFREG);
969 GOTO(out, retval = PTR_ERR(file));
971 /* count doubles as retval */
972 for (pg = 0; pg < oa_bufs; pg++) {
973 CDEBUG(D_INODE, "OP %d obdo pgno: (%d) (%ld,"LPU64
974 ") off count ("LPU64",%d)\n",
975 cmd, pnum, file->f_dentry->d_inode->i_ino,
976 pga[pnum].off >> PAGE_CACHE_SHIFT, pga[pnum].off,
977 (int)pga[pnum].count);
978 if (cmd & OBD_BRW_WRITE) {
982 buffer = kmap(pga[pnum].pg);
983 retval = file->f_op->write(file, buffer,
986 kunmap(pga[pnum].pg);
987 CDEBUG(D_INODE, "retval %ld\n", retval);
989 loff_t off = pga[pnum].off;
990 char *buffer = kmap(pga[pnum].pg);
992 if (off >= file->f_dentry->d_inode->i_size) {
993 memset(buffer, 0, pga[pnum].count);
994 retval = pga[pnum].count;
996 retval = file->f_op->read(file, buffer,
997 pga[pnum].count, &off);
999 kunmap(pga[pnum].pg);
1001 if (retval != pga[pnum].count) {
1002 filp_close(file, 0);
1003 GOTO(out, retval = -EIO);
1005 CDEBUG(D_INODE, "retval %ld\n", retval);
1009 /* sizes and blocks are set by generic_file_write */
1010 /* ctimes/mtimes will follow with a setattr call */
1011 filp_close(file, 0);
1013 /* XXX: do something with callback if it is set? */
1018 error = (retval >= 0) ? 0 : retval;
1023 * Calculate the number of buffer credits needed to write multiple pages in
1024 * a single ext3/extN transaction. No, this shouldn't be here, but as yet
1025 * ext3 doesn't have a nice API for calculating this sort of thing in advance.
1027 * See comment above ext3_writepage_trans_blocks for details. We assume
1028 * no data journaling is being done, but it does allow for all of the pages
1029 * being non-contiguous. If we are guaranteed contiguous pages we could
1030 * reduce the number of (d)indirect blocks a lot.
1032 * With N blocks per page and P pages, for each inode we have at most:
1034 * min(N*P, blocksize/4 + 1) dindirect blocks
1037 * For the entire filesystem, we have at most:
1038 * min(sum(nindir + P), ngroups) bitmap blocks (from the above)
1039 * min(sum(nindir + P), gdblocks) group descriptor blocks (from the above)
1042 * 2 * EXT3_SINGLEDATA_TRANS_BLOCKS for the quota files
1044 static int ext3_credits_needed(struct super_block *sb, int objcount,
1045 struct obd_ioobj *obj)
1047 struct obd_ioobj *o = obj;
1048 int blockpp = 1 << (PAGE_CACHE_SHIFT - sb->s_blocksize_bits);
1049 int addrpp = EXT3_ADDR_PER_BLOCK(sb) * blockpp;
1052 int needed = objcount + 1;
1055 for (i = 0; i < objcount; i++, o++) {
1056 int nblocks = o->ioo_bufcnt * blockpp;
1057 int ndindirect = min(nblocks, addrpp + 1);
1058 int nindir = nblocks + ndindirect + 1;
1060 nbitmaps += nindir + nblocks;
1061 ngdblocks += nindir + nblocks;
1066 /* Assumes ext3 and extN have same sb_info layout at the start. */
1067 if (nbitmaps > EXT3_SB(sb)->s_groups_count)
1068 nbitmaps = EXT3_SB(sb)->s_groups_count;
1069 if (ngdblocks > EXT3_SB(sb)->s_gdb_count)
1070 ngdblocks = EXT3_SB(sb)->s_gdb_count;
1072 needed += nbitmaps + ngdblocks;
1075 /* We assume that there will be 1 bit set in s_dquot.flags for each
1076 * quota file that is active. This is at least true for now.
1078 needed += hweight32(sb_any_quota_enabled(sb)) *
1079 EXT3_SINGLEDATA_TRANS_BLOCKS;
1085 /* We have to start a huge journal transaction here to hold all of the
1086 * metadata for the pages being written here. This is necessitated by
1087 * the fact that we do lots of prepare_write operations before we do
1088 * any of the matching commit_write operations, so even if we split
1089 * up to use "smaller" transactions none of them could complete until
1090 * all of them were opened. By having a single journal transaction,
1091 * we eliminate duplicate reservations for common blocks like the
1092 * superblock and group descriptors or bitmaps.
1094 * We will start the transaction here, but each prepare_write will
1095 * add a refcount to the transaction, and each commit_write will
1096 * remove a refcount. The transaction will be closed when all of
1097 * the pages have been written.
1099 static void *ext3_filter_journal_start(struct filter_obd *filter,
1100 int objcount, struct obd_ioobj *obj,
1101 int niocount, struct niobuf_remote *nb)
1103 journal_t *journal = NULL;
1104 handle_t *handle = NULL;
1107 /* It appears that some kernels have different values for
1108 * EXT*_MAX_GROUP_LOADED (either 8 or 32), so we cannot
1109 * assume anything after s_inode_bitmap_number is the same.
1111 if (!strcmp(filter->fo_fstype, "ext3"))
1112 journal = EXT3_SB(filter->fo_sb)->s_journal;
1113 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1114 else if (!strcmp(filter->fo_fstype, "extN"))
1115 journal = EXTN_SB(filter->fo_sb)->s_journal;
1117 needed = ext3_credits_needed(filter->fo_sb, objcount, obj);
1119 /* The number of blocks we could _possibly_ dirty can very large.
1120 * We reduce our request if it is absurd (and we couldn't get that
1121 * many credits for a single handle anyways).
1123 * At some point we have to limit the size of I/Os sent at one time,
1124 * increase the size of the journal, or we have to calculate the
1125 * actual journal requirements more carefully by checking all of
1126 * the blocks instead of being maximally pessimistic. It remains to
1127 * be seen if this is a real problem or not.
1129 if (needed > journal->j_max_transaction_buffers) {
1130 CERROR("want too many journal credits (%d) using %d instead\n",
1131 needed, journal->j_max_transaction_buffers);
1132 needed = journal->j_max_transaction_buffers;
1136 handle = journal_start(journal, needed);
1139 CERROR("can't get handle for %d credits: rc = %ld\n", needed,
1145 static void *filter_journal_start(void **journal_save,
1146 struct filter_obd *filter,
1147 int objcount, struct obd_ioobj *obj,
1148 int niocount, struct niobuf_remote *nb)
1150 void *handle = NULL;
1152 /* This may not be necessary - we probably never have a
1153 * transaction started when we enter here, so we can
1154 * remove the saving of the journal state entirely.
1155 * For now leave it in just to see if it ever happens.
1157 *journal_save = current->journal_info;
1158 if (*journal_save) {
1159 CERROR("Already have handle %p???\n", *journal_save);
1161 current->journal_info = NULL;
1164 if (!strcmp(filter->fo_fstype, "ext3") ||
1165 !strcmp(filter->fo_fstype, "extN"))
1166 handle = ext3_filter_journal_start(filter, objcount, obj,
1171 static int ext3_filter_journal_stop(void *handle)
1175 /* We got a refcount on the handle for each call to prepare_write,
1176 * so we can drop the "parent" handle here to avoid the need for
1177 * osc to call back into filterobd to close the handle. The
1178 * remaining references will be dropped in commit_write.
1181 rc = journal_stop((handle_t *)handle);
1187 static int filter_journal_stop(void *journal_save, struct filter_obd *filter,
1192 if (!strcmp(filter->fo_fstype, "ext3") ||
1193 !strcmp(filter->fo_fstype, "extN"))
1194 rc = ext3_filter_journal_stop(handle);
1197 CERROR("error on journal stop: rc = %d\n", rc);
1199 current->journal_info = journal_save;
1204 static inline void lustre_put_page(struct page *page)
1207 page_cache_release(page);
1211 #ifndef PageUptodate
1212 #define PageUptodate(page) Page_Uptodate(page)
1214 static struct page *
1215 lustre_get_page_read(struct inode *inode,
1216 struct niobuf_remote *rnb)
1218 unsigned long index = rnb->offset >> PAGE_SHIFT;
1219 struct address_space *mapping = inode->i_mapping;
1223 page = read_cache_page(mapping, index,
1224 (filler_t*)mapping->a_ops->readpage, NULL);
1225 if (!IS_ERR(page)) {
1228 if (!PageUptodate(page)) {
1229 CERROR("page index %lu not uptodate\n", index);
1230 GOTO(err_page, rc = -EIO);
1232 if (PageError(page)) {
1233 CERROR("page index %lu has error\n", index);
1234 GOTO(err_page, rc = -EIO);
1240 lustre_put_page(page);
1244 static struct page *
1245 lustre_get_page_write(struct inode *inode, unsigned long index)
1247 struct address_space *mapping = inode->i_mapping;
1251 page = grab_cache_page(mapping, index); /* locked page */
1253 if (!IS_ERR(page)) {
1255 /* Note: Called with "O" and "PAGE_SIZE" this is essentially
1256 * a no-op for most filesystems, because we write the whole
1257 * page. For partial-page I/O this will read in the page.
1259 rc = mapping->a_ops->prepare_write(NULL, page, 0, PAGE_SIZE);
1261 CERROR("page index %lu, rc = %d\n", index, rc);
1264 GOTO(err_unlock, rc);
1266 /* XXX not sure if we need this if we are overwriting page */
1267 if (PageError(page)) {
1268 CERROR("error on page index %lu, rc = %d\n", index, rc);
1270 GOTO(err_unlock, rc = -EIO);
1277 lustre_put_page(page);
1281 static int lustre_commit_write(struct page *page, unsigned from, unsigned to)
1283 struct inode *inode = page->mapping->host;
1286 err = page->mapping->a_ops->commit_write(NULL, page, from, to);
1287 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1288 if (!err && IS_SYNC(inode))
1289 err = waitfor_one_page(page);
1291 #warning ADD 2.5 waiting code here?
1293 //SetPageUptodate(page); // the client commit_write will do this
1295 SetPageReferenced(page);
1297 lustre_put_page(page);
1301 struct page *filter_get_page_write(struct inode *inode,
1302 struct niobuf_remote *rnb,
1303 struct niobuf_local *lnb, int *pglocked)
1305 unsigned long index = rnb->offset >> PAGE_SHIFT;
1306 struct address_space *mapping = inode->i_mapping;
1311 //ASSERT_PAGE_INDEX(index, GOTO(err, rc = -EINVAL));
1313 page = grab_cache_page_nowait(mapping, index); /* locked page */
1315 page = grab_cache_page(mapping, index); /* locked page */
1318 /* This page is currently locked, so get a temporary page instead. */
1319 /* XXX I believe this is a very dangerous thing to do - consider if
1320 * we had multiple writers for the same file (definitely the case
1321 * if we are using this codepath). If writer A locks the page,
1322 * writer B writes to a copy (as here), writer A drops the page
1323 * lock, and writer C grabs the lock before B does, then B will
1324 * later overwrite the data from C, even if C had LDLM locked
1325 * and initiated the write after B did.
1329 CDEBUG(D_PAGE, "ino %ld page %ld locked\n", inode->i_ino,index);
1330 addr = __get_free_pages(GFP_KERNEL, 0); /* locked page */
1332 CERROR("no memory for a temp page\n");
1334 GOTO(err, rc = -ENOMEM);
1337 memset((void *)addr, 0xBA, PAGE_SIZE);
1338 page = virt_to_page(addr);
1340 page->index = index;
1341 lnb->flags |= N_LOCAL_TEMP_PAGE;
1342 } else if (!IS_ERR(page)) {
1346 rc = mapping->a_ops->prepare_write(NULL, page,
1347 rnb->offset % PAGE_SIZE,
1350 CERROR("page index %lu, rc = %d\n", index, rc);
1353 GOTO(err_unlock, rc);
1355 /* XXX not sure if we need this if we are overwriting page */
1356 if (PageError(page)) {
1357 CERROR("error on page index %lu, rc = %d\n", index, rc);
1359 GOTO(err_unlock, rc = -EIO);
1366 lustre_put_page(page);
1372 * We need to balance prepare_write() calls with commit_write() calls.
1373 * If the page has been prepared, but we have no data for it, we don't
1374 * want to overwrite valid data on disk, but we still need to zero out
1375 * data for space which was newly allocated. Like part of what happens
1376 * in __block_prepare_write() for newly allocated blocks.
1378 * XXX currently __block_prepare_write() creates buffers for all the
1379 * pages, and the filesystems mark these buffers as BH_New if they
1380 * were newly allocated from disk. We use the BH_New flag similarly.
1382 static int filter_commit_write(struct page *page, unsigned from, unsigned to,
1385 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1387 unsigned block_start, block_end;
1388 struct buffer_head *bh, *head = page->buffers;
1389 unsigned blocksize = head->b_size;
1390 void *addr = page_address(page);
1392 /* debugging: just seeing if this ever happens */
1393 CERROR("called filter_commit_write for obj %ld:%ld on err %d\n",
1394 page->index, page->mapping->host->i_ino, err);
1396 /* Currently one buffer per page, but in the future... */
1397 for (bh = head, block_start = 0; bh != head || !block_start;
1398 block_start = block_end, bh = bh->b_this_page) {
1399 block_end = block_start + blocksize;
1401 memset(addr + block_start, 0, blocksize);
1405 return lustre_commit_write(page, from, to);
1408 static int filter_preprw(int cmd, struct lustre_handle *conn,
1409 int objcount, struct obd_ioobj *obj,
1410 int niocount, struct niobuf_remote *nb,
1411 struct niobuf_local *res, void **desc_private)
1413 struct obd_run_ctxt saved;
1414 struct obd_device *obd;
1415 struct obd_ioobj *o = obj;
1416 struct niobuf_remote *rnb = nb;
1417 struct niobuf_local *lnb = res;
1418 void *journal_save = NULL;
1424 obd = class_conn2obd(conn);
1426 CDEBUG(D_IOCTL, "invalid client "LPX64"\n", conn->addr);
1429 memset(res, 0, sizeof(*res) * niocount);
1431 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
1433 if (cmd & OBD_BRW_WRITE) {
1434 *desc_private = filter_journal_start(&journal_save,
1436 objcount, obj, niocount,
1438 if (IS_ERR(*desc_private))
1439 GOTO(out_ctxt, rc = PTR_ERR(*desc_private));
1442 for (i = 0; i < objcount; i++, o++) {
1443 struct dentry *dentry;
1444 struct inode *inode;
1447 dentry = filter_fid2dentry(obd, filter_parent(obd, S_IFREG),
1448 o->ioo_id, S_IFREG);
1450 GOTO(out_clean, rc = PTR_ERR(dentry));
1451 inode = dentry->d_inode;
1453 CERROR("trying to BRW to non-existent file "LPU64"\n",
1456 GOTO(out_clean, rc = -ENOENT);
1459 for (j = 0; j < o->ioo_bufcnt; j++, rnb++, lnb++) {
1463 lnb->dentry = dentry;
1465 lnb->dentry = dget(dentry);
1467 if (cmd & OBD_BRW_WRITE)
1468 page = filter_get_page_write(inode, rnb, lnb,
1471 page = lustre_get_page_read(inode, rnb);
1475 GOTO(out_clean, rc = PTR_ERR(page));
1478 lnb->addr = page_address(page);
1479 lnb->offset = rnb->offset;
1481 lnb->len = rnb->len;
1486 if (cmd & OBD_BRW_WRITE) {
1487 int err = filter_journal_stop(journal_save, &obd->u.filter,
1496 while (lnb-- > res) {
1497 CERROR("error cleanup on brw\n");
1498 f_dput(lnb->dentry);
1499 if (cmd & OBD_BRW_WRITE)
1500 filter_commit_write(lnb->page, 0, PAGE_SIZE, rc);
1502 lustre_put_page(lnb->page);
1507 static int filter_write_locked_page(struct niobuf_local *lnb)
1512 lpage = lustre_get_page_write(lnb->dentry->d_inode, lnb->page->index);
1513 if (IS_ERR(lpage)) {
1514 /* It is highly unlikely that we would ever get an error here.
1515 * The page we want to get was previously locked, so it had to
1516 * have already allocated the space, and we were just writing
1517 * over the same data, so there would be no hole in the file.
1519 * XXX: possibility of a race with truncate could exist, need
1520 * to check that. There are no guarantees w.r.t.
1521 * write order even on a local filesystem, although the
1522 * normal response would be to return the number of bytes
1523 * successfully written and leave the rest to the app.
1525 rc = PTR_ERR(lpage);
1526 CERROR("error getting locked page index %ld: rc = %d\n",
1527 lnb->page->index, rc);
1531 /* lpage is kmapped in lustre_get_page_write() above and kunmapped in
1532 * lustre_commit_write() below, lnb->page was kmapped previously in
1533 * filter_get_page_write() and kunmapped in lustre_put_page() below.
1535 memcpy(page_address(lpage), page_address(lnb->page), PAGE_SIZE);
1536 rc = lustre_commit_write(lpage, 0, PAGE_SIZE);
1538 CERROR("error committing locked page %ld: rc = %d\n",
1539 lnb->page->index, rc);
1541 lustre_put_page(lnb->page);
1546 static int filter_commitrw(int cmd, struct lustre_handle *conn,
1547 int objcount, struct obd_ioobj *obj,
1548 int niocount, struct niobuf_local *res,
1551 struct obd_run_ctxt saved;
1552 struct obd_ioobj *o;
1553 struct niobuf_local *r;
1554 struct obd_device *obd = class_conn2obd(conn);
1556 int found_locked = 0;
1561 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
1563 journal_save = current->journal_info;
1564 LASSERT(!journal_save);
1566 current->journal_info = private;
1568 for (i = 0, o = obj, r = res; i < objcount; i++, o++) {
1570 for (j = 0 ; j < o->ioo_bufcnt ; j++, r++) {
1571 struct page *page = r->page;
1576 if (r->flags & N_LOCAL_TEMP_PAGE) {
1581 if (cmd & OBD_BRW_WRITE) {
1582 int err = filter_commit_write(page, 0,
1588 lustre_put_page(page);
1594 current->journal_info = journal_save;
1600 for (i = 0, o = obj, r = res; i < objcount; i++, o++) {
1602 for (j = 0 ; j < o->ioo_bufcnt ; j++, r++) {
1604 if (!(r->flags & N_LOCAL_TEMP_PAGE))
1607 err = filter_write_locked_page(r);
1619 static int filter_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
1621 struct obd_device *obd = class_conn2obd(conn);
1626 rc = vfs_statfs(obd->u.filter.fo_sb, &sfs);
1628 statfs_pack(osfs, &sfs);
1633 static int filter_get_info(struct lustre_handle *conn, obd_count keylen,
1634 void *key, obd_count *vallen, void **val)
1636 struct obd_device *obd;
1639 obd = class_conn2obd(conn);
1641 CDEBUG(D_IOCTL, "invalid client "LPX64"\n", conn->addr);
1645 if ( keylen == strlen("blocksize") &&
1646 memcmp(key, "blocksize", keylen) == 0 ) {
1647 *vallen = sizeof(long);
1648 *val = (void *)(long)obd->u.filter.fo_sb->s_blocksize;
1652 if ( keylen == strlen("blocksize_bits") &&
1653 memcmp(key, "blocksize_bits", keylen) == 0 ){
1654 *vallen = sizeof(long);
1655 *val = (void *)(long)obd->u.filter.fo_sb->s_blocksize_bits;
1659 if ( keylen == strlen("root_ino") &&
1660 memcmp(key, "root_ino", keylen) == 0 ){
1661 *vallen = sizeof(obd_id);
1662 *val = (void *)(obd_id)FILTER_ROOTINO;
1666 CDEBUG(D_IOCTL, "invalid key\n");
1670 int filter_copy_data(struct lustre_handle *dst_conn, struct obdo *dst,
1671 struct lustre_handle *src_conn, struct obdo *src,
1672 obd_size count, obd_off offset)
1675 struct lov_stripe_md srcmd, dstmd;
1676 unsigned long index = 0;
1679 memset(&srcmd, 0, sizeof(srcmd));
1680 memset(&dstmd, 0, sizeof(dstmd));
1681 srcmd.lsm_object_id = src->o_id;
1682 dstmd.lsm_object_id = dst->o_id;
1685 CDEBUG(D_INFO, "src: ino "LPU64" blocks "LPU64", size "LPU64
1686 ", dst: ino "LPU64"\n",
1687 src->o_id, src->o_blocks, src->o_size, dst->o_id);
1688 page = alloc_page(GFP_USER);
1692 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1693 while (TryLockPage(page))
1694 ___wait_on_page(page);
1696 wait_on_page_locked(page);
1699 /* XXX with brw vector I/O, we could batch up reads and writes here,
1700 * all we need to do is allocate multiple pages to handle the I/Os
1701 * and arrays to handle the request parameters.
1703 while (index < ((src->o_size + PAGE_SIZE - 1) >> PAGE_SHIFT)) {
1705 struct io_cb_data *cbd = ll_init_cb();
1714 pg.count = PAGE_SIZE;
1715 pg.off = (page->index) << PAGE_SHIFT;
1718 page->index = index;
1719 err = obd_brw(OBD_BRW_READ, src_conn, &srcmd, 1, &pg,
1720 ll_sync_io_cb, cbd);
1733 pg.flag = OBD_BRW_CREATE;
1734 CDEBUG(D_INFO, "Read page %ld ...\n", page->index);
1736 err = obd_brw(OBD_BRW_WRITE, dst_conn, &dstmd, 1, &pg,
1737 ll_sync_io_cb, cbd);
1739 /* XXX should handle dst->o_size, dst->o_blocks here */
1745 CDEBUG(D_INFO, "Wrote page %ld ...\n", page->index);
1749 dst->o_size = src->o_size;
1750 dst->o_blocks = src->o_blocks;
1751 dst->o_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
1759 static struct obd_ops filter_obd_ops = {
1760 o_get_info: filter_get_info,
1761 o_setup: filter_setup,
1762 o_cleanup: filter_cleanup,
1763 o_connect: filter_connect,
1764 o_disconnect: filter_disconnect,
1765 o_statfs: filter_statfs,
1766 o_getattr: filter_getattr,
1767 o_create: filter_create,
1768 o_setattr: filter_setattr,
1769 o_destroy: filter_destroy,
1770 o_open: filter_open,
1771 o_close: filter_close,
1772 o_brw: filter_pgcache_brw,
1773 o_punch: filter_truncate,
1774 o_preprw: filter_preprw,
1775 o_commitrw: filter_commitrw
1777 o_preallocate: filter_preallocate_inodes,
1778 o_migrate: filter_migrate,
1779 o_copy: filter_copy_data,
1780 o_iterate: filter_iterate
1785 static int __init obdfilter_init(void)
1787 printk(KERN_INFO "Filtering OBD driver v0.001, info@clusterfs.com\n");
1788 filter_open_cache = kmem_cache_create("ll_filter_fdata",
1789 sizeof(struct filter_file_data),
1791 if (!filter_open_cache)
1794 filter_dentry_cache = kmem_cache_create("ll_filter_dentry",
1795 sizeof(struct filter_dentry_data),
1797 if (!filter_dentry_cache) {
1798 kmem_cache_destroy(filter_open_cache);
1802 return class_register_type(&filter_obd_ops, OBD_FILTER_DEVICENAME);
1805 static void __exit obdfilter_exit(void)
1807 class_unregister_type(OBD_FILTER_DEVICENAME);
1808 if (kmem_cache_destroy(filter_dentry_cache))
1809 CERROR("couldn't free obdfilter dentry cache\n");
1810 if (kmem_cache_destroy(filter_open_cache))
1811 CERROR("couldn't free obdfilter open cache\n");
1814 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1815 MODULE_DESCRIPTION("Lustre Filtering OBD driver v1.0");
1816 MODULE_LICENSE("GPL");
1818 module_init(obdfilter_init);
1819 module_exit(obdfilter_exit);