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>
33 #include <linux/lprocfs_status.h>
35 extern struct lprocfs_vars status_class_var[];
36 extern struct lprocfs_vars status_var_nm_1[];
38 static kmem_cache_t *filter_open_cache;
39 static kmem_cache_t *filter_dentry_cache;
41 #define FILTER_ROOTINO 2
42 #define FILTER_ROOTINO_STR __stringify(FILTER_ROOTINO)
45 static char *obd_type_by_mode[S_IFMT >> S_SHIFT] = {
47 [S_IFREG >> S_SHIFT] "R",
48 [S_IFDIR >> S_SHIFT] "D",
49 [S_IFCHR >> S_SHIFT] "C",
50 [S_IFBLK >> S_SHIFT] "B",
51 [S_IFIFO >> S_SHIFT] "F",
52 [S_IFSOCK >> S_SHIFT] "S",
53 [S_IFLNK >> S_SHIFT] "L"
56 static inline const char *obd_mode_to_type(int mode)
58 return obd_type_by_mode[(mode & S_IFMT) >> S_SHIFT];
61 /* write the pathname into the string */
62 static int filter_id(char *buf, obd_id id, obd_mode mode)
64 return sprintf(buf, "O/%s/"LPU64, obd_mode_to_type(mode), id);
67 static inline void f_dput(struct dentry *dentry)
69 /* Can't go inside filter_ddelete because it can block */
70 CDEBUG(D_INODE, "putting %s: %p, count = %d\n",
71 dentry->d_name.name, dentry, atomic_read(&dentry->d_count) - 1);
72 LASSERT(atomic_read(&dentry->d_count) > 0);
77 /* Not racy w.r.t. others, because we are the only user of this dentry */
78 static void filter_drelease(struct dentry *dentry)
81 kmem_cache_free(filter_dentry_cache, dentry->d_fsdata);
84 struct dentry_operations filter_dops = {
85 .d_release = filter_drelease,
88 /* setup the object store with correct subdirectories */
89 static int filter_prep(struct obd_device *obd)
91 struct obd_run_ctxt saved;
92 struct filter_obd *filter = &obd->u.filter;
93 struct dentry *dentry;
101 push_ctxt(&saved, &filter->fo_ctxt, NULL);
102 dentry = simple_mkdir(current->fs->pwd, "O", 0700);
103 CDEBUG(D_INODE, "got/created O: %p\n", dentry);
104 if (IS_ERR(dentry)) {
105 rc = PTR_ERR(dentry);
106 CERROR("cannot open/create O: rc = %d\n", rc);
109 filter->fo_dentry_O = dentry;
110 dentry = simple_mkdir(current->fs->pwd, "P", 0700);
111 CDEBUG(D_INODE, "got/created P: %p\n", dentry);
112 if (IS_ERR(dentry)) {
113 rc = PTR_ERR(dentry);
114 CERROR("cannot open/create P: rc = %d\n", rc);
118 dentry = simple_mkdir(current->fs->pwd, "D", 0700);
119 CDEBUG(D_INODE, "got/created D: %p\n", dentry);
120 if (IS_ERR(dentry)) {
121 rc = PTR_ERR(dentry);
122 CERROR("cannot open/create D: rc = %d\n", rc);
126 root = simple_mknod(dentry, FILTER_ROOTINO_STR, S_IFREG | 0755);
130 CERROR("OBD filter: cannot open/create root %d: rc = %d\n",
137 * Create directories and/or get dentries for each object type.
138 * This saves us from having to do multiple lookups for each one.
140 for (mode = 0; mode < (S_IFMT >> S_SHIFT); mode++) {
141 char *type = obd_type_by_mode[mode];
144 filter->fo_dentry_O_mode[mode] = NULL;
147 dentry = simple_mkdir(filter->fo_dentry_O, type, 0700);
148 CDEBUG(D_INODE, "got/created O/%s: %p\n", type, dentry);
149 if (IS_ERR(dentry)) {
150 rc = PTR_ERR(dentry);
151 CERROR("cannot create O/%s: rc = %d\n", type, rc);
152 GOTO(out_O_mode, rc);
154 filter->fo_dentry_O_mode[mode] = dentry;
157 file = filp_open("D/status", O_RDWR | O_CREAT, 0700);
158 if ( !file || IS_ERR(file) ) {
160 CERROR("OBD filter: cannot open/create status %s: rc = %d\n",
162 GOTO(out_O_mode, rc);
165 /* steal operations */
166 inode = file->f_dentry->d_inode;
167 filter->fo_fop = file->f_op;
168 filter->fo_iop = inode->i_op;
169 filter->fo_aops = inode->i_mapping->a_ops;
171 if (inode->i_size == 0) {
172 __u64 disk_lastobjid = cpu_to_le64(lastobjid);
173 ssize_t retval = file->f_op->write(file,(char *)&disk_lastobjid,
174 sizeof(disk_lastobjid),
176 if (retval != sizeof(disk_lastobjid)) {
177 CDEBUG(D_INODE,"OBD filter: error writing lastobjid\n");
179 GOTO(out_O_mode, rc = -EIO);
182 __u64 disk_lastobjid;
183 ssize_t retval = file->f_op->read(file, (char *)&disk_lastobjid,
184 sizeof(disk_lastobjid),
186 if (retval != sizeof(disk_lastobjid)) {
187 CDEBUG(D_INODE,"OBD filter: error reading lastobjid\n");
189 GOTO(out_O_mode, rc = -EIO);
191 lastobjid = le64_to_cpu(disk_lastobjid);
193 filter->fo_lastobjid = lastobjid;
204 struct dentry *dentry = filter->fo_dentry_O_mode[mode];
207 filter->fo_dentry_O_mode[mode] = NULL;
211 f_dput(filter->fo_dentry_O);
212 filter->fo_dentry_O = NULL;
216 /* cleanup the filter: write last used object id to status file */
217 static void filter_post(struct obd_device *obd)
219 struct obd_run_ctxt saved;
220 struct filter_obd *filter = &obd->u.filter;
221 __u64 disk_lastobjid;
226 push_ctxt(&saved, &filter->fo_ctxt, NULL);
227 file = filp_open("D/status", O_RDWR | O_CREAT, 0700);
229 CERROR("OBD filter: cannot create status file\n");
234 disk_lastobjid = cpu_to_le64(filter->fo_lastobjid);
235 rc = file->f_op->write(file, (char *)&disk_lastobjid,
236 sizeof(disk_lastobjid), &file->f_pos);
237 if (rc != sizeof(disk_lastobjid))
238 CERROR("OBD filter: error writing lastobjid: rc = %ld\n", rc);
240 rc = filp_close(file, NULL);
242 CERROR("OBD filter: cannot close status file: rc = %ld\n", rc);
244 for (mode = 0; mode < (S_IFMT >> S_SHIFT); mode++) {
245 struct dentry *dentry = filter->fo_dentry_O_mode[mode];
248 filter->fo_dentry_O_mode[mode] = NULL;
251 f_dput(filter->fo_dentry_O);
257 static __u64 filter_next_id(struct obd_device *obd)
261 spin_lock(&obd->u.filter.fo_objidlock);
262 id = ++obd->u.filter.fo_lastobjid;
263 spin_unlock(&obd->u.filter.fo_objidlock);
265 /* FIXME: write the lastobjid to disk here */
269 /* how to get files, dentries, inodes from object id's */
270 /* parent i_sem is already held if needed for exclusivity */
271 static struct dentry *filter_fid2dentry(struct obd_device *obd,
272 struct dentry *dparent,
273 __u64 id, __u32 type)
275 struct super_block *sb = obd->u.filter.fo_sb;
276 struct dentry *dchild;
281 if (!sb || !sb->s_dev) {
282 CERROR("fatal: device not initialized.\n");
283 RETURN(ERR_PTR(-ENXIO));
287 CERROR("fatal: invalid object #0\n");
289 RETURN(ERR_PTR(-ESTALE));
292 if (!(type & S_IFMT)) {
293 CERROR("OBD %s, object "LPU64" has bad type: %o\n",
294 __FUNCTION__, id, type);
295 RETURN(ERR_PTR(-EINVAL));
298 len = sprintf(name, LPU64, id);
299 CDEBUG(D_INODE, "opening object O/%s/%s\n", obd_mode_to_type(type),
301 dchild = lookup_one_len(name, dparent, len);
302 if (IS_ERR(dchild)) {
303 CERROR("child lookup error %ld\n", PTR_ERR(dchild));
307 CDEBUG(D_INODE, "got child obj O/%s/%s: %p, count = %d\n",
308 obd_mode_to_type(type), name, dchild,
309 atomic_read(&dchild->d_count));
311 LASSERT(atomic_read(&dchild->d_count) > 0);
316 static inline struct dentry *filter_parent(struct obd_device *obd,
319 struct filter_obd *filter = &obd->u.filter;
321 return filter->fo_dentry_O_mode[(mode & S_IFMT) >> S_SHIFT];
324 static struct file *filter_obj_open(struct obd_export *export,
325 __u64 id, __u32 type)
327 struct filter_obd *filter = &export->exp_obd->u.filter;
328 struct super_block *sb = filter->fo_sb;
329 struct dentry *dentry;
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 dentry = file->f_dentry;
376 spin_lock(&filter->fo_fddlock);
377 if (dentry->d_fsdata) {
378 spin_unlock(&filter->fo_fddlock);
379 kmem_cache_free(filter_dentry_cache, fdd);
380 fdd = dentry->d_fsdata;
381 LASSERT(kmem_cache_validate(filter_dentry_cache, fdd));
382 /* should only happen during client recovery */
383 if (fdd->fdd_flags & FILTER_FLAG_DESTROY)
384 CDEBUG(D_INODE,"opening destroyed object "LPX64"\n",id);
385 atomic_inc(&fdd->fdd_open_count);
387 atomic_set(&fdd->fdd_open_count, 1);
389 /* If this is racy, then we can use {cmp}xchg and atomic_add */
390 dentry->d_fsdata = fdd;
391 spin_unlock(&filter->fo_fddlock);
394 get_random_bytes(&ffd->ffd_servercookie, sizeof(ffd->ffd_servercookie));
395 ffd->ffd_file = file;
396 file->private_data = ffd;
399 dentry->d_op = &filter_dops;
401 LASSERT(dentry->d_op == &filter_dops);
403 spin_lock(&fed->fed_lock);
404 list_add(&ffd->ffd_export_list, &fed->fed_open_head);
405 spin_unlock(&fed->fed_lock);
407 CDEBUG(D_INODE, "opening objid "LPX64": rc = %p\n", id, file);
413 kmem_cache_free(filter_dentry_cache, fdd);
415 ffd->ffd_servercookie = DEAD_HANDLE_MAGIC;
416 kmem_cache_free(filter_open_cache, ffd);
420 /* Caller must hold i_sem on dir_dentry->d_inode */
421 static int filter_destroy_internal(struct obd_device *obd,
422 struct dentry *dir_dentry,
423 struct dentry *object_dentry)
425 struct obd_run_ctxt saved;
426 struct inode *inode = object_dentry->d_inode;
430 if (inode->i_nlink != 1 || atomic_read(&inode->i_count) != 1) {
431 CERROR("destroying objid %*s nlink = %d, count = %d\n",
432 object_dentry->d_name.len,
433 object_dentry->d_name.name,
434 inode->i_nlink, atomic_read(&inode->i_count));
437 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
438 rc = vfs_unlink(dir_dentry->d_inode, object_dentry);
439 /* XXX unlink from PENDING directory now too */
443 CERROR("error unlinking objid %*s: rc %d\n",
444 object_dentry->d_name.len,
445 object_dentry->d_name.name, rc);
450 static int filter_close_internal(struct obd_device *obd,
451 struct filter_file_data *ffd)
453 struct file *filp = ffd->ffd_file;
454 struct dentry *object_dentry = dget(filp->f_dentry);
455 struct filter_dentry_data *fdd = object_dentry->d_fsdata;
459 LASSERT(filp->private_data == ffd);
462 rc = filp_close(filp, 0);
464 if (atomic_dec_and_test(&fdd->fdd_open_count) &&
465 fdd->fdd_flags & FILTER_FLAG_DESTROY) {
466 struct dentry *dir_dentry = filter_parent(obd, S_IFREG);
468 down(&dir_dentry->d_inode->i_sem);
469 rc2 = filter_destroy_internal(obd, dir_dentry, object_dentry);
472 up(&dir_dentry->d_inode->i_sem);
475 f_dput(object_dentry);
476 kmem_cache_free(filter_open_cache, ffd);
482 static int filter_connect(struct lustre_handle *conn, struct obd_device *obd,
483 obd_uuid_t cluuid, struct recovd_obd *recovd,
484 ptlrpc_recovery_cb_t recover)
486 struct obd_export *exp;
491 rc = class_connect(conn, obd, cluuid);
494 exp = class_conn2export(conn);
497 INIT_LIST_HEAD(&exp->exp_filter_data.fed_open_head);
498 spin_lock_init(&exp->exp_filter_data.fed_lock);
507 static int filter_disconnect(struct lustre_handle *conn)
509 struct obd_export *exp = class_conn2export(conn);
510 struct filter_export_data *fed;
515 fed = &exp->exp_filter_data;
516 spin_lock(&fed->fed_lock);
517 while (!list_empty(&fed->fed_open_head)) {
518 struct filter_file_data *ffd;
520 ffd = list_entry(fed->fed_open_head.next, typeof(*ffd),
522 list_del(&ffd->ffd_export_list);
523 spin_unlock(&fed->fed_lock);
525 CERROR("force closing file %*s on disconnect\n",
526 ffd->ffd_file->f_dentry->d_name.len,
527 ffd->ffd_file->f_dentry->d_name.name);
529 filter_close_internal(exp->exp_obd, ffd);
530 spin_lock(&fed->fed_lock);
532 spin_unlock(&fed->fed_lock);
534 ldlm_cancel_locks_for_export(exp);
535 rc = class_disconnect(conn);
539 /* XXX cleanup preallocated inodes */
543 /* mount the file system (secretly) */
544 static int filter_setup(struct obd_device *obd, obd_count len, void *buf)
546 struct obd_ioctl_data* data = buf;
547 struct filter_obd *filter;
548 struct vfsmount *mnt;
552 if (!data->ioc_inlbuf1 || !data->ioc_inlbuf2)
556 mnt = do_kern_mount(data->ioc_inlbuf2, 0, data->ioc_inlbuf1, NULL);
561 filter = &obd->u.filter;;
562 filter->fo_vfsmnt = mnt;
563 filter->fo_fstype = strdup(data->ioc_inlbuf2);
564 filter->fo_sb = mnt->mnt_root->d_inode->i_sb;
565 CERROR("%s: mnt is %p\n", data->ioc_inlbuf1, filter->fo_vfsmnt);
566 /* XXX is this even possible if do_kern_mount succeeded? */
568 GOTO(err_kfree, err = -ENODEV);
570 OBD_SET_CTXT_MAGIC(&filter->fo_ctxt);
571 filter->fo_ctxt.pwdmnt = mnt;
572 filter->fo_ctxt.pwd = mnt->mnt_root;
573 filter->fo_ctxt.fs = get_ds();
575 err = filter_prep(obd);
577 GOTO(err_kfree, err);
578 spin_lock_init(&filter->fo_fddlock);
579 spin_lock_init(&filter->fo_objidlock);
580 INIT_LIST_HEAD(&filter->fo_export_list);
583 ldlm_namespace_new("filter-tgt", LDLM_NAMESPACE_SERVER);
584 if (obd->obd_namespace == NULL)
587 ptlrpc_init_client(LDLM_CB_REQUEST_PORTAL, LDLM_CB_REPLY_PORTAL,
588 "filter_ldlm_cb_client", &obd->obd_ldlm_client);
593 kfree(filter->fo_fstype);
595 mntput(filter->fo_vfsmnt);
605 static int filter_cleanup(struct obd_device *obd)
607 struct super_block *sb;
610 if (!list_empty(&obd->obd_exports)) {
611 CERROR("still has clients!\n");
612 class_disconnect_all(obd);
613 if (!list_empty(&obd->obd_exports)) {
614 CERROR("still has exports after forced cleanup?\n");
619 ldlm_namespace_free(obd->obd_namespace);
621 sb = obd->u.filter.fo_sb;
622 if (!obd->u.filter.fo_sb)
627 shrink_dcache_parent(sb->s_root);
629 mntput(obd->u.filter.fo_vfsmnt);
630 obd->u.filter.fo_sb = 0;
631 kfree(obd->u.filter.fo_fstype);
640 static void filter_from_inode(struct obdo *oa, struct inode *inode, int valid)
642 int type = oa->o_mode & S_IFMT;
645 CDEBUG(D_INFO, "src inode %ld (%p), dst obdo %ld valid 0x%08x\n",
646 inode->i_ino, inode, (long)oa->o_id, valid);
647 /* Don't copy the inode number in place of the object ID */
648 obdo_from_inode(oa, inode, valid);
649 oa->o_mode &= ~S_IFMT;
652 if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {
653 obd_rdev rdev = kdev_t_to_nr(inode->i_rdev);
655 oa->o_valid |= OBD_MD_FLRDEV;
661 static struct filter_file_data *filter_handle2ffd(struct lustre_handle *handle)
663 struct filter_file_data *ffd = NULL;
666 if (!handle || !handle->addr)
669 ffd = (struct filter_file_data *)(unsigned long)(handle->addr);
670 if (!kmem_cache_validate(filter_open_cache, (void *)ffd))
673 if (ffd->ffd_servercookie != handle->cookie)
676 LASSERT(ffd->ffd_file->private_data == ffd);
680 static struct dentry *__filter_oa2dentry(struct lustre_handle *conn,
681 struct obdo *oa, char *what)
683 struct dentry *dentry = NULL;
685 if (oa->o_valid & OBD_MD_FLHANDLE) {
686 struct lustre_handle *ost_handle = obdo_handle(oa);
687 struct filter_file_data *ffd = filter_handle2ffd(ost_handle);
690 dentry = dget(ffd->ffd_file->f_dentry);
694 struct obd_device *obd = class_conn2obd(conn);
696 CERROR("invalid client "LPX64"\n", conn->addr);
697 RETURN(ERR_PTR(-EINVAL));
699 dentry = filter_fid2dentry(obd, filter_parent(obd, oa->o_mode),
700 oa->o_id, oa->o_mode);
703 if (!dentry->d_inode) {
704 CERROR("%s on non-existent object: "LPU64"\n", what, oa->o_id);
706 dentry = ERR_PTR(-ENOENT);
712 #define filter_oa2dentry(conn, oa) __filter_oa2dentry(conn, oa, __FUNCTION__)
714 static int filter_getattr(struct lustre_handle *conn, struct obdo *oa,
715 struct lov_stripe_md *md)
717 struct dentry *dentry = NULL;
721 dentry = filter_oa2dentry(conn, oa);
723 RETURN(PTR_ERR(dentry));
725 filter_from_inode(oa, dentry->d_inode, oa->o_valid);
731 static int filter_setattr(struct lustre_handle *conn, struct obdo *oa,
732 struct lov_stripe_md *md)
734 struct obd_run_ctxt saved;
735 struct obd_device *obd = class_conn2obd(conn);
736 struct dentry *dentry;
742 dentry = filter_oa2dentry(conn, oa);
745 RETURN(PTR_ERR(dentry));
747 iattr_from_obdo(&iattr, oa, oa->o_valid);
748 iattr.ia_mode = (iattr.ia_mode & ~S_IFMT) | S_IFREG;
749 inode = dentry->d_inode;
752 if (iattr.ia_valid & ATTR_SIZE)
754 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
755 if (inode->i_op->setattr)
756 rc = inode->i_op->setattr(dentry, &iattr);
758 rc = inode_setattr(inode, &iattr);
760 if (iattr.ia_valid & ATTR_SIZE) {
762 oa->o_valid = OBD_MD_FLBLOCKS | OBD_MD_FLCTIME | OBD_MD_FLMTIME;
763 obdo_from_inode(oa, inode, oa->o_valid);
771 static int filter_open(struct lustre_handle *conn, struct obdo *oa,
772 struct lov_stripe_md *ea)
774 struct obd_export *export;
775 struct lustre_handle *handle;
776 struct filter_file_data *ffd;
781 export = class_conn2export(conn);
783 CDEBUG(D_IOCTL, "fatal: invalid client "LPX64"\n", conn->addr);
787 filp = filter_obj_open(export, oa->o_id, oa->o_mode);
789 GOTO(out, rc = PTR_ERR(filp));
791 filter_from_inode(oa, filp->f_dentry->d_inode, oa->o_valid);
793 ffd = filp->private_data;
794 handle = obdo_handle(oa);
795 handle->addr = (__u64)(unsigned long)ffd;
796 handle->cookie = ffd->ffd_servercookie;
797 oa->o_valid |= OBD_MD_FLHANDLE;
802 static int filter_close(struct lustre_handle *conn, struct obdo *oa,
803 struct lov_stripe_md *ea)
805 struct obd_export *exp;
806 struct filter_file_data *ffd;
807 struct filter_export_data *fed;
811 exp = class_conn2export(conn);
813 CDEBUG(D_IOCTL, "fatal: invalid client "LPX64"\n", conn->addr);
817 if (!(oa->o_valid & OBD_MD_FLHANDLE)) {
818 CERROR("no handle for close of objid "LPX64"\n", oa->o_id);
822 ffd = filter_handle2ffd(obdo_handle(oa));
824 struct lustre_handle *handle = obdo_handle(oa);
825 CERROR("bad handle ("LPX64") or cookie ("LPX64") for close\n",
826 handle->addr, handle->cookie);
830 fed = &exp->exp_filter_data;
831 spin_lock(&fed->fed_lock);
832 list_del(&ffd->ffd_export_list);
833 spin_unlock(&fed->fed_lock);
835 rc = filter_close_internal(exp->exp_obd, ffd);
840 static int filter_create(struct lustre_handle *conn, struct obdo *oa,
841 struct lov_stripe_md **ea)
843 struct obd_device *obd = class_conn2obd(conn);
845 struct obd_run_ctxt saved;
851 CERROR("invalid client "LPX64"\n", conn->addr);
855 if (!(oa->o_mode & S_IFMT)) {
856 CERROR("OBD %s, object "LPU64" has bad type: %o\n",
857 __FUNCTION__, oa->o_id, oa->o_mode);
861 oa->o_id = filter_next_id(obd);
863 //filter_id(name, oa->o_id, oa->o_mode);
864 sprintf(name, LPU64, oa->o_id);
865 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
866 new = simple_mknod(filter_parent(obd, oa->o_mode), name, oa->o_mode);
869 CERROR("Error mknod obj %s, err %ld\n", name, PTR_ERR(new));
873 /* Set flags for fields we have set in the inode struct */
874 oa->o_valid = OBD_MD_FLID | OBD_MD_FLBLKSZ | OBD_MD_FLBLOCKS |
875 OBD_MD_FLMTIME | OBD_MD_FLATIME | OBD_MD_FLCTIME;
876 filter_from_inode(oa, new->d_inode, oa->o_valid);
882 static int filter_destroy(struct lustre_handle *conn, struct obdo *oa,
883 struct lov_stripe_md *ea)
885 struct obd_device *obd = class_conn2obd(conn);
886 struct dentry *dir_dentry, *object_dentry;
887 struct filter_dentry_data *fdd;
892 CERROR("invalid client "LPX64"\n", conn->addr);
896 CDEBUG(D_INODE, "destroying objid "LPX64"\n", oa->o_id);
898 dir_dentry = filter_parent(obd, oa->o_mode);
899 down(&dir_dentry->d_inode->i_sem);
901 object_dentry = filter_oa2dentry(conn, oa);
902 if (IS_ERR(object_dentry))
903 GOTO(out, rc = -ENOENT);
905 fdd = object_dentry->d_fsdata;
906 if (fdd && atomic_read(&fdd->fdd_open_count)) {
907 if (!(fdd->fdd_flags & FILTER_FLAG_DESTROY)) {
908 fdd->fdd_flags |= FILTER_FLAG_DESTROY;
909 /* XXX put into PENDING directory in case of crash */
911 "defer destroy of %dx open objid "LPX64"\n",
912 atomic_read(&fdd->fdd_open_count), oa->o_id);
915 "repeat destroy of %dx open objid "LPX64"\n",
916 atomic_read(&fdd->fdd_open_count), oa->o_id);
917 GOTO(out_dput, rc = 0);
920 rc = filter_destroy_internal(obd, dir_dentry, object_dentry);
922 f_dput(object_dentry);
926 up(&dir_dentry->d_inode->i_sem);
930 /* NB count and offset are used for punch, but not truncate */
931 static int filter_truncate(struct lustre_handle *conn, struct obdo *oa,
932 struct lov_stripe_md *lsm,
933 obd_off start, obd_off end)
938 if (end != OBD_OBJECT_EOF)
939 CERROR("PUNCH not supported, only truncate works\n");
941 CDEBUG(D_INODE, "calling truncate for object "LPX64", valid = %x, "
942 "o_size = "LPD64"\n", oa->o_id, oa->o_valid, start);
944 error = filter_setattr(conn, oa, NULL);
948 static int filter_pgcache_brw(int cmd, struct lustre_handle *conn,
949 struct lov_stripe_md *lsm, obd_count oa_bufs,
950 struct brw_page *pga, brw_cb_t callback,
951 struct brw_cb_data *brw_cbd)
953 struct obd_export *export = class_conn2export(conn);
954 struct obd_run_ctxt saved;
955 struct super_block *sb;
956 int pnum; /* index to pages (bufs) */
957 unsigned long retval;
964 CDEBUG(D_IOCTL, "invalid client "LPX64"\n", conn->addr);
968 sb = export->exp_obd->u.filter.fo_sb;
969 push_ctxt(&saved, &export->exp_obd->u.filter.fo_ctxt, NULL);
970 pnum = 0; /* pnum indexes buf 0..num_pages */
972 file = filter_obj_open(export, lsm->lsm_object_id, S_IFREG);
974 GOTO(out, retval = PTR_ERR(file));
976 /* count doubles as retval */
977 for (pg = 0; pg < oa_bufs; pg++) {
978 CDEBUG(D_INODE, "OP %d obdo pgno: (%d) (%ld,"LPU64
979 ") off count ("LPU64",%d)\n",
980 cmd, pnum, file->f_dentry->d_inode->i_ino,
981 pga[pnum].off >> PAGE_CACHE_SHIFT, pga[pnum].off,
982 (int)pga[pnum].count);
983 if (cmd & OBD_BRW_WRITE) {
987 buffer = kmap(pga[pnum].pg);
988 retval = file->f_op->write(file, buffer,
991 kunmap(pga[pnum].pg);
992 CDEBUG(D_INODE, "retval %ld\n", retval);
994 loff_t off = pga[pnum].off;
995 char *buffer = kmap(pga[pnum].pg);
997 if (off >= file->f_dentry->d_inode->i_size) {
998 memset(buffer, 0, pga[pnum].count);
999 retval = pga[pnum].count;
1001 retval = file->f_op->read(file, buffer,
1002 pga[pnum].count, &off);
1004 kunmap(pga[pnum].pg);
1006 if (retval != pga[pnum].count) {
1007 filp_close(file, 0);
1008 GOTO(out, retval = -EIO);
1010 CDEBUG(D_INODE, "retval %ld\n", retval);
1014 /* sizes and blocks are set by generic_file_write */
1015 /* ctimes/mtimes will follow with a setattr call */
1016 filp_close(file, 0);
1018 /* XXX: do something with callback if it is set? */
1023 error = (retval >= 0) ? 0 : retval;
1028 * Calculate the number of buffer credits needed to write multiple pages in
1029 * a single ext3/extN transaction. No, this shouldn't be here, but as yet
1030 * ext3 doesn't have a nice API for calculating this sort of thing in advance.
1032 * See comment above ext3_writepage_trans_blocks for details. We assume
1033 * no data journaling is being done, but it does allow for all of the pages
1034 * being non-contiguous. If we are guaranteed contiguous pages we could
1035 * reduce the number of (d)indirect blocks a lot.
1037 * With N blocks per page and P pages, for each inode we have at most:
1039 * min(N*P, blocksize/4 + 1) dindirect blocks
1042 * For the entire filesystem, we have at most:
1043 * min(sum(nindir + P), ngroups) bitmap blocks (from the above)
1044 * min(sum(nindir + P), gdblocks) group descriptor blocks (from the above)
1047 * 2 * EXT3_SINGLEDATA_TRANS_BLOCKS for the quota files
1049 static int ext3_credits_needed(struct super_block *sb, int objcount,
1050 struct obd_ioobj *obj)
1052 struct obd_ioobj *o = obj;
1053 int blockpp = 1 << (PAGE_CACHE_SHIFT - sb->s_blocksize_bits);
1054 int addrpp = EXT3_ADDR_PER_BLOCK(sb) * blockpp;
1057 int needed = objcount + 1;
1060 for (i = 0; i < objcount; i++, o++) {
1061 int nblocks = o->ioo_bufcnt * blockpp;
1062 int ndindirect = min(nblocks, addrpp + 1);
1063 int nindir = nblocks + ndindirect + 1;
1065 nbitmaps += nindir + nblocks;
1066 ngdblocks += nindir + nblocks;
1071 /* Assumes ext3 and extN have same sb_info layout at the start. */
1072 if (nbitmaps > EXT3_SB(sb)->s_groups_count)
1073 nbitmaps = EXT3_SB(sb)->s_groups_count;
1074 if (ngdblocks > EXT3_SB(sb)->s_gdb_count)
1075 ngdblocks = EXT3_SB(sb)->s_gdb_count;
1077 needed += nbitmaps + ngdblocks;
1080 /* We assume that there will be 1 bit set in s_dquot.flags for each
1081 * quota file that is active. This is at least true for now.
1083 needed += hweight32(sb_any_quota_enabled(sb)) *
1084 EXT3_SINGLEDATA_TRANS_BLOCKS;
1090 /* We have to start a huge journal transaction here to hold all of the
1091 * metadata for the pages being written here. This is necessitated by
1092 * the fact that we do lots of prepare_write operations before we do
1093 * any of the matching commit_write operations, so even if we split
1094 * up to use "smaller" transactions none of them could complete until
1095 * all of them were opened. By having a single journal transaction,
1096 * we eliminate duplicate reservations for common blocks like the
1097 * superblock and group descriptors or bitmaps.
1099 * We will start the transaction here, but each prepare_write will
1100 * add a refcount to the transaction, and each commit_write will
1101 * remove a refcount. The transaction will be closed when all of
1102 * the pages have been written.
1104 static void *ext3_filter_journal_start(struct filter_obd *filter,
1105 int objcount, struct obd_ioobj *obj,
1106 int niocount, struct niobuf_remote *nb)
1108 journal_t *journal = NULL;
1109 handle_t *handle = NULL;
1112 /* It appears that some kernels have different values for
1113 * EXT*_MAX_GROUP_LOADED (either 8 or 32), so we cannot
1114 * assume anything after s_inode_bitmap_number is the same.
1116 if (!strcmp(filter->fo_fstype, "ext3"))
1117 journal = EXT3_SB(filter->fo_sb)->s_journal;
1118 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1119 else if (!strcmp(filter->fo_fstype, "extN"))
1120 journal = EXTN_SB(filter->fo_sb)->s_journal;
1122 needed = ext3_credits_needed(filter->fo_sb, objcount, obj);
1124 /* The number of blocks we could _possibly_ dirty can very large.
1125 * We reduce our request if it is absurd (and we couldn't get that
1126 * many credits for a single handle anyways).
1128 * At some point we have to limit the size of I/Os sent at one time,
1129 * increase the size of the journal, or we have to calculate the
1130 * actual journal requirements more carefully by checking all of
1131 * the blocks instead of being maximally pessimistic. It remains to
1132 * be seen if this is a real problem or not.
1134 if (needed > journal->j_max_transaction_buffers) {
1135 CERROR("want too many journal credits (%d) using %d instead\n",
1136 needed, journal->j_max_transaction_buffers);
1137 needed = journal->j_max_transaction_buffers;
1141 handle = journal_start(journal, needed);
1144 CERROR("can't get handle for %d credits: rc = %ld\n", needed,
1150 static void *filter_journal_start(void **journal_save,
1151 struct filter_obd *filter,
1152 int objcount, struct obd_ioobj *obj,
1153 int niocount, struct niobuf_remote *nb)
1155 void *handle = NULL;
1157 /* This may not be necessary - we probably never have a
1158 * transaction started when we enter here, so we can
1159 * remove the saving of the journal state entirely.
1160 * For now leave it in just to see if it ever happens.
1162 *journal_save = current->journal_info;
1163 if (*journal_save) {
1164 CERROR("Already have handle %p???\n", *journal_save);
1166 current->journal_info = NULL;
1169 if (!strcmp(filter->fo_fstype, "ext3") ||
1170 !strcmp(filter->fo_fstype, "extN"))
1171 handle = ext3_filter_journal_start(filter, objcount, obj,
1176 static int ext3_filter_journal_stop(void *handle)
1180 /* We got a refcount on the handle for each call to prepare_write,
1181 * so we can drop the "parent" handle here to avoid the need for
1182 * osc to call back into filterobd to close the handle. The
1183 * remaining references will be dropped in commit_write.
1186 rc = journal_stop((handle_t *)handle);
1192 static int filter_journal_stop(void *journal_save, struct filter_obd *filter,
1197 if (!strcmp(filter->fo_fstype, "ext3") ||
1198 !strcmp(filter->fo_fstype, "extN"))
1199 rc = ext3_filter_journal_stop(handle);
1202 CERROR("error on journal stop: rc = %d\n", rc);
1204 current->journal_info = journal_save;
1209 static inline void lustre_put_page(struct page *page)
1212 page_cache_release(page);
1216 static struct page *
1217 lustre_get_page_read(struct inode *inode, struct niobuf_remote *rnb)
1219 unsigned long index = rnb->offset >> PAGE_SHIFT;
1220 struct address_space *mapping = inode->i_mapping;
1224 page = read_cache_page(mapping, index,
1225 (filler_t*)mapping->a_ops->readpage, NULL);
1226 if (!IS_ERR(page)) {
1229 if (!PageUptodate(page)) {
1230 CERROR("page index %lu not uptodate\n", index);
1231 GOTO(err_page, rc = -EIO);
1233 if (PageError(page)) {
1234 CERROR("page index %lu has error\n", index);
1235 GOTO(err_page, rc = -EIO);
1241 lustre_put_page(page);
1245 static struct page *
1246 lustre_get_page_write(struct inode *inode, unsigned long index)
1248 struct address_space *mapping = inode->i_mapping;
1252 page = grab_cache_page(mapping, index); /* locked page */
1254 if (!IS_ERR(page)) {
1256 /* Note: Called with "O" and "PAGE_SIZE" this is essentially
1257 * a no-op for most filesystems, because we write the whole
1258 * page. For partial-page I/O this will read in the page.
1260 rc = mapping->a_ops->prepare_write(NULL, page, 0, PAGE_SIZE);
1262 CERROR("page index %lu, rc = %d\n", index, rc);
1265 GOTO(err_unlock, rc);
1267 /* XXX not sure if we need this if we are overwriting page */
1268 if (PageError(page)) {
1269 CERROR("error on page index %lu, rc = %d\n", index, rc);
1271 GOTO(err_unlock, rc = -EIO);
1278 lustre_put_page(page);
1282 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1283 int waitfor_one_page(struct page *page)
1285 wait_on_page_locked(page);
1290 static int lustre_commit_write(struct page *page, unsigned from, unsigned to)
1292 struct inode *inode = page->mapping->host;
1295 err = page->mapping->a_ops->commit_write(NULL, page, from, to);
1296 if (!err && IS_SYNC(inode))
1297 err = waitfor_one_page(page);
1298 //SetPageUptodate(page); // the client commit_write will do this
1300 SetPageReferenced(page);
1302 lustre_put_page(page);
1306 struct page *filter_get_page_write(struct inode *inode,
1307 struct niobuf_remote *rnb,
1308 struct niobuf_local *lnb, int *pglocked)
1310 unsigned long index = rnb->offset >> PAGE_SHIFT;
1311 struct address_space *mapping = inode->i_mapping;
1316 //ASSERT_PAGE_INDEX(index, GOTO(err, rc = -EINVAL));
1318 page = grab_cache_page_nowait(mapping, index); /* locked page */
1320 page = grab_cache_page(mapping, index); /* locked page */
1323 /* This page is currently locked, so get a temporary page instead. */
1324 /* XXX I believe this is a very dangerous thing to do - consider if
1325 * we had multiple writers for the same file (definitely the case
1326 * if we are using this codepath). If writer A locks the page,
1327 * writer B writes to a copy (as here), writer A drops the page
1328 * lock, and writer C grabs the lock before B does, then B will
1329 * later overwrite the data from C, even if C had LDLM locked
1330 * and initiated the write after B did.
1334 CDEBUG(D_PAGE, "ino %ld page %ld locked\n", inode->i_ino,index);
1335 addr = __get_free_pages(GFP_KERNEL, 0); /* locked page */
1337 CERROR("no memory for a temp page\n");
1339 GOTO(err, rc = -ENOMEM);
1342 memset((void *)addr, 0xBA, PAGE_SIZE);
1343 page = virt_to_page(addr);
1345 page->index = index;
1346 lnb->flags |= N_LOCAL_TEMP_PAGE;
1347 } else if (!IS_ERR(page)) {
1351 rc = mapping->a_ops->prepare_write(NULL, page,
1352 rnb->offset % PAGE_SIZE,
1355 CERROR("page index %lu, rc = %d\n", index, rc);
1358 GOTO(err_unlock, rc);
1360 /* XXX not sure if we need this if we are overwriting page */
1361 if (PageError(page)) {
1362 CERROR("error on page index %lu, rc = %d\n", index, rc);
1364 GOTO(err_unlock, rc = -EIO);
1371 lustre_put_page(page);
1377 * We need to balance prepare_write() calls with commit_write() calls.
1378 * If the page has been prepared, but we have no data for it, we don't
1379 * want to overwrite valid data on disk, but we still need to zero out
1380 * data for space which was newly allocated. Like part of what happens
1381 * in __block_prepare_write() for newly allocated blocks.
1383 * XXX currently __block_prepare_write() creates buffers for all the
1384 * pages, and the filesystems mark these buffers as BH_New if they
1385 * were newly allocated from disk. We use the BH_New flag similarly.
1387 static int filter_commit_write(struct page *page, unsigned from, unsigned to,
1390 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1392 unsigned block_start, block_end;
1393 struct buffer_head *bh, *head = page->buffers;
1394 unsigned blocksize = head->b_size;
1395 void *addr = page_address(page);
1397 /* debugging: just seeing if this ever happens */
1398 CERROR("called filter_commit_write for obj %ld:%ld on err %d\n",
1399 page->index, page->mapping->host->i_ino, err);
1401 /* Currently one buffer per page, but in the future... */
1402 for (bh = head, block_start = 0; bh != head || !block_start;
1403 block_start = block_end, bh = bh->b_this_page) {
1404 block_end = block_start + blocksize;
1406 memset(addr + block_start, 0, blocksize);
1410 return lustre_commit_write(page, from, to);
1413 static int filter_preprw(int cmd, struct lustre_handle *conn,
1414 int objcount, struct obd_ioobj *obj,
1415 int niocount, struct niobuf_remote *nb,
1416 struct niobuf_local *res, void **desc_private)
1418 struct obd_run_ctxt saved;
1419 struct obd_device *obd;
1420 struct obd_ioobj *o = obj;
1421 struct niobuf_remote *rnb = nb;
1422 struct niobuf_local *lnb = res;
1423 void *journal_save = NULL;
1429 obd = class_conn2obd(conn);
1431 CDEBUG(D_IOCTL, "invalid client "LPX64"\n", conn->addr);
1434 memset(res, 0, sizeof(*res) * niocount);
1436 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
1438 if (cmd & OBD_BRW_WRITE) {
1439 *desc_private = filter_journal_start(&journal_save,
1441 objcount, obj, niocount,
1443 if (IS_ERR(*desc_private))
1444 GOTO(out_ctxt, rc = PTR_ERR(*desc_private));
1447 obd_kmap_get(niocount, 1);
1449 for (i = 0; i < objcount; i++, o++) {
1450 struct dentry *dentry;
1451 struct inode *inode;
1454 dentry = filter_fid2dentry(obd, filter_parent(obd, S_IFREG),
1455 o->ioo_id, S_IFREG);
1457 GOTO(out_clean, rc = PTR_ERR(dentry));
1458 inode = dentry->d_inode;
1460 CERROR("trying to BRW to non-existent file "LPU64"\n",
1463 GOTO(out_clean, rc = -ENOENT);
1466 for (j = 0; j < o->ioo_bufcnt; j++, rnb++, lnb++) {
1470 lnb->dentry = dentry;
1472 lnb->dentry = dget(dentry);
1474 if (cmd & OBD_BRW_WRITE)
1475 page = filter_get_page_write(inode, rnb, lnb,
1478 page = lustre_get_page_read(inode, rnb);
1482 GOTO(out_clean, rc = PTR_ERR(page));
1485 lnb->addr = page_address(page);
1486 lnb->offset = rnb->offset;
1488 lnb->len = rnb->len;
1493 if (cmd & OBD_BRW_WRITE) {
1494 int err = filter_journal_stop(journal_save, &obd->u.filter,
1503 while (lnb-- > res) {
1504 CERROR("error cleanup on brw\n");
1505 f_dput(lnb->dentry);
1506 if (cmd & OBD_BRW_WRITE)
1507 filter_commit_write(lnb->page, 0, PAGE_SIZE, rc);
1509 lustre_put_page(lnb->page);
1511 obd_kmap_put(niocount);
1515 static int filter_write_locked_page(struct niobuf_local *lnb)
1520 lpage = lustre_get_page_write(lnb->dentry->d_inode, lnb->page->index);
1521 if (IS_ERR(lpage)) {
1522 /* It is highly unlikely that we would ever get an error here.
1523 * The page we want to get was previously locked, so it had to
1524 * have already allocated the space, and we were just writing
1525 * over the same data, so there would be no hole in the file.
1527 * XXX: possibility of a race with truncate could exist, need
1528 * to check that. There are no guarantees w.r.t.
1529 * write order even on a local filesystem, although the
1530 * normal response would be to return the number of bytes
1531 * successfully written and leave the rest to the app.
1533 rc = PTR_ERR(lpage);
1534 CERROR("error getting locked page index %ld: rc = %d\n",
1535 lnb->page->index, rc);
1539 /* lpage is kmapped in lustre_get_page_write() above and kunmapped in
1540 * lustre_commit_write() below, lnb->page was kmapped previously in
1541 * filter_get_page_write() and kunmapped in lustre_put_page() below.
1543 memcpy(page_address(lpage), page_address(lnb->page), PAGE_SIZE);
1544 rc = lustre_commit_write(lpage, 0, PAGE_SIZE);
1546 CERROR("error committing locked page %ld: rc = %d\n",
1547 lnb->page->index, rc);
1549 lustre_put_page(lnb->page);
1554 static int filter_commitrw(int cmd, struct lustre_handle *conn,
1555 int objcount, struct obd_ioobj *obj,
1556 int niocount, struct niobuf_local *res,
1559 struct obd_run_ctxt saved;
1560 struct obd_ioobj *o;
1561 struct niobuf_local *r;
1562 struct obd_device *obd = class_conn2obd(conn);
1564 int found_locked = 0;
1569 push_ctxt(&saved, &obd->u.filter.fo_ctxt, NULL);
1571 journal_save = current->journal_info;
1572 LASSERT(!journal_save);
1574 current->journal_info = private;
1576 for (i = 0, o = obj, r = res; i < objcount; i++, o++) {
1578 for (j = 0 ; j < o->ioo_bufcnt ; j++, r++) {
1579 struct page *page = r->page;
1584 if (r->flags & N_LOCAL_TEMP_PAGE) {
1589 if (cmd & OBD_BRW_WRITE) {
1590 int err = filter_commit_write(page, 0,
1596 lustre_put_page(page);
1603 current->journal_info = journal_save;
1609 for (i = 0, o = obj, r = res; i < objcount; i++, o++) {
1611 for (j = 0 ; j < o->ioo_bufcnt ; j++, r++) {
1613 if (!(r->flags & N_LOCAL_TEMP_PAGE))
1616 err = filter_write_locked_page(r);
1629 static int filter_statfs(struct lustre_handle *conn, struct obd_statfs *osfs)
1631 struct obd_device *obd = class_conn2obd(conn);
1636 rc = vfs_statfs(obd->u.filter.fo_sb, &sfs);
1638 statfs_pack(osfs, &sfs);
1643 static int filter_get_info(struct lustre_handle *conn, obd_count keylen,
1644 void *key, obd_count *vallen, void **val)
1646 struct obd_device *obd;
1649 obd = class_conn2obd(conn);
1651 CDEBUG(D_IOCTL, "invalid client "LPX64"\n", conn->addr);
1655 if ( keylen == strlen("blocksize") &&
1656 memcmp(key, "blocksize", keylen) == 0 ) {
1657 *vallen = sizeof(long);
1658 *val = (void *)(long)obd->u.filter.fo_sb->s_blocksize;
1662 if ( keylen == strlen("blocksize_bits") &&
1663 memcmp(key, "blocksize_bits", keylen) == 0 ){
1664 *vallen = sizeof(long);
1665 *val = (void *)(long)obd->u.filter.fo_sb->s_blocksize_bits;
1669 if ( keylen == strlen("root_ino") &&
1670 memcmp(key, "root_ino", keylen) == 0 ){
1671 *vallen = sizeof(obd_id);
1672 *val = (void *)(obd_id)FILTER_ROOTINO;
1676 CDEBUG(D_IOCTL, "invalid key\n");
1680 int filter_copy_data(struct lustre_handle *dst_conn, struct obdo *dst,
1681 struct lustre_handle *src_conn, struct obdo *src,
1682 obd_size count, obd_off offset)
1685 struct lov_stripe_md srcmd, dstmd;
1686 unsigned long index = 0;
1689 memset(&srcmd, 0, sizeof(srcmd));
1690 memset(&dstmd, 0, sizeof(dstmd));
1691 srcmd.lsm_object_id = src->o_id;
1692 dstmd.lsm_object_id = dst->o_id;
1695 CDEBUG(D_INFO, "src: ino "LPU64" blocks "LPU64", size "LPU64
1696 ", dst: ino "LPU64"\n",
1697 src->o_id, src->o_blocks, src->o_size, dst->o_id);
1698 page = alloc_page(GFP_USER);
1702 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1703 while (TryLockPage(page))
1704 ___wait_on_page(page);
1706 wait_on_page_locked(page);
1709 /* XXX with brw vector I/O, we could batch up reads and writes here,
1710 * all we need to do is allocate multiple pages to handle the I/Os
1711 * and arrays to handle the request parameters.
1713 while (index < ((src->o_size + PAGE_SIZE - 1) >> PAGE_SHIFT)) {
1715 struct brw_cb_data *brw_cbd = ll_init_brw_cb_data();
1724 pg.count = PAGE_SIZE;
1725 pg.off = (page->index) << PAGE_SHIFT;
1728 page->index = index;
1729 err = obd_brw(OBD_BRW_READ, src_conn, &srcmd, 1, &pg,
1730 ll_sync_brw_cb, brw_cbd);
1737 brw_cbd = ll_init_brw_cb_data();
1743 pg.flag = OBD_BRW_CREATE;
1744 CDEBUG(D_INFO, "Read page %ld ...\n", page->index);
1746 err = obd_brw(OBD_BRW_WRITE, dst_conn, &dstmd, 1, &pg,
1747 ll_sync_brw_cb, brw_cbd);
1749 /* XXX should handle dst->o_size, dst->o_blocks here */
1755 CDEBUG(D_INFO, "Wrote page %ld ...\n", page->index);
1759 dst->o_size = src->o_size;
1760 dst->o_blocks = src->o_blocks;
1761 dst->o_valid |= OBD_MD_FLSIZE | OBD_MD_FLBLOCKS;
1767 int filter_attach(struct obd_device *dev,
1768 obd_count len, void *data)
1770 return lprocfs_reg_obd(dev, status_var_nm_1, dev);
1773 int filter_detach(struct obd_device *dev)
1775 return lprocfs_dereg_obd(dev);
1777 static struct obd_ops filter_obd_ops = {
1778 o_attach: filter_attach,
1779 o_detach: filter_detach,
1780 o_get_info: filter_get_info,
1781 o_setup: filter_setup,
1782 o_cleanup: filter_cleanup,
1783 o_connect: filter_connect,
1784 o_disconnect: filter_disconnect,
1785 o_statfs: filter_statfs,
1786 o_getattr: filter_getattr,
1787 o_create: filter_create,
1788 o_setattr: filter_setattr,
1789 o_destroy: filter_destroy,
1790 o_open: filter_open,
1791 o_close: filter_close,
1792 o_brw: filter_pgcache_brw,
1793 o_punch: filter_truncate,
1794 o_preprw: filter_preprw,
1795 o_commitrw: filter_commitrw
1797 o_preallocate: filter_preallocate_inodes,
1798 o_migrate: filter_migrate,
1799 o_copy: filter_copy_data,
1800 o_iterate: filter_iterate
1805 static int __init obdfilter_init(void)
1807 printk(KERN_INFO "Filtering OBD driver v0.001, info@clusterfs.com\n");
1808 filter_open_cache = kmem_cache_create("ll_filter_fdata",
1809 sizeof(struct filter_file_data),
1811 if (!filter_open_cache)
1814 filter_dentry_cache = kmem_cache_create("ll_filter_dentry",
1815 sizeof(struct filter_dentry_data),
1817 if (!filter_dentry_cache) {
1818 kmem_cache_destroy(filter_open_cache);
1822 return class_register_type(&filter_obd_ops, status_class_var,
1823 OBD_FILTER_DEVICENAME);
1826 static void __exit obdfilter_exit(void)
1828 class_unregister_type(OBD_FILTER_DEVICENAME);
1829 if (kmem_cache_destroy(filter_dentry_cache))
1830 CERROR("couldn't free obdfilter dentry cache\n");
1831 if (kmem_cache_destroy(filter_open_cache))
1832 CERROR("couldn't free obdfilter open cache\n");
1835 MODULE_AUTHOR("Cluster File Systems, Inc. <info@clusterfs.com>");
1836 MODULE_DESCRIPTION("Lustre Filtering OBD driver v1.0");
1837 MODULE_LICENSE("GPL");
1839 module_init(obdfilter_init);
1840 module_exit(obdfilter_exit);