@@ -678,6 +678,8 @@ int osc_reconnect(const struct lu_env *env, struct obd_export *exp,
int osc_disconnect(struct obd_export *exp);
int osc_punch_send(struct obd_export *exp, struct obdo *oa,
obd_enqueue_update_f upcall, void *cookie);
+int osc_fallocate_base(struct obd_export *exp, struct obdo *oa,
+ obd_enqueue_update_f upcall, void *cookie, int mode);
/* osc_io.c */
int osc_io_submit(const struct lu_env *env, const struct cl_io_slice *ios,
@@ -712,6 +714,8 @@ void osc_io_lseek_end(const struct lu_env *env,
const struct cl_io_slice *slice);
int osc_io_lru_reserve(const struct lu_env *env, const struct cl_io_slice *ios,
loff_t pos, size_t count);
+int osc_punch_start(const struct lu_env *env, struct cl_io *io,
+ struct cl_object *obj);
/* osc_lock.c */
void osc_lock_to_lockless(const struct lu_env *env, struct osc_lock *ols,
@@ -35,6 +35,7 @@
#include <obd_class.h>
#include <lustre_osc.h>
+#include <linux/falloc.h>
#include <uapi/linux/lustre/lustre_param.h>
#include "mdc_internal.h"
@@ -1035,11 +1036,13 @@ static int mdc_io_setattr_start(const struct lu_env *env,
&oio->oi_trunc);
if (rc < 0)
return rc;
+ } else if (cl_io_is_fallocate(io) &&
+ io->u.ci_setattr.sa_falloc_mode & FALLOC_FL_PUNCH_HOLE) {
+ rc = osc_punch_start(env, io, obj);
+ if (rc < 0)
+ return rc;
}
- if (cl_io_is_fallocate(io))
- return -EOPNOTSUPP;
-
if (oio->oi_lockless == 0) {
cl_object_attr_lock(obj);
rc = cl_object_attr_get(env, obj, attr);
@@ -1070,7 +1073,7 @@ static int mdc_io_setattr_start(const struct lu_env *env,
return rc;
}
- if (!(ia_valid & ATTR_SIZE))
+ if (!(ia_valid & ATTR_SIZE) && !cl_io_is_fallocate(io))
return 0;
memset(oa, 0, sizeof(*oa));
@@ -1078,12 +1081,10 @@ static int mdc_io_setattr_start(const struct lu_env *env,
oa->o_mtime = attr->cat_mtime;
oa->o_atime = attr->cat_atime;
oa->o_ctime = attr->cat_ctime;
-
- oa->o_size = size;
- oa->o_blocks = OBD_OBJECT_EOF;
oa->o_valid = OBD_MD_FLID | OBD_MD_FLGROUP | OBD_MD_FLATIME |
OBD_MD_FLCTIME | OBD_MD_FLMTIME | OBD_MD_FLSIZE |
OBD_MD_FLBLOCKS;
+
if (oio->oi_lockless) {
oa->o_flags = OBD_FL_SRVLOCK;
oa->o_valid |= OBD_MD_FLFLAGS;
@@ -1095,9 +1096,19 @@ static int mdc_io_setattr_start(const struct lu_env *env,
}
init_completion(&cbargs->opc_sync);
+ if (cl_io_is_fallocate(io)) {
+ int falloc_mode = io->u.ci_setattr.sa_falloc_mode;
- rc = osc_punch_send(osc_export(cl2osc(obj)), oa,
- mdc_async_upcall, cbargs);
+ oa->o_size = io->u.ci_setattr.sa_falloc_offset;
+ oa->o_blocks = io->u.ci_setattr.sa_falloc_end;
+ rc = osc_fallocate_base(osc_export(cl2osc(obj)), oa,
+ mdc_async_upcall, cbargs, falloc_mode);
+ } else {
+ oa->o_size = size;
+ oa->o_blocks = OBD_OBJECT_EOF;
+ rc = osc_punch_send(osc_export(cl2osc(obj)), oa,
+ mdc_async_upcall, cbargs);
+ }
cbargs->opc_rpc_sent = rc == 0;
return rc;
}
@@ -548,8 +548,8 @@ static void osc_trunc_check(const struct lu_env *env, struct cl_io *io,
* if server doesn't support fallocate punch, we also need these data to be
* flushed first to prevent re-ordering with the punch
*/
-static int osc_punch_start(const struct lu_env *env, struct cl_io *io,
- struct cl_object *obj)
+int osc_punch_start(const struct lu_env *env, struct cl_io *io,
+ struct cl_object *obj)
{
struct osc_object *osc = cl2osc(obj);
pgoff_t pg_start = cl_index(obj, io->u.ci_setattr.sa_falloc_offset);
@@ -564,6 +564,7 @@ static int osc_punch_start(const struct lu_env *env, struct cl_io *io,
osc);
return 0;
}
+EXPORT_SYMBOL(osc_punch_start);
static int osc_io_setattr_start(const struct lu_env *env,
const struct cl_io_slice *slice)
@@ -472,7 +472,7 @@ int osc_fallocate_base(struct obd_export *exp, struct obdo *oa,
ptlrpc_request_set_replen(req);
- req->rq_interpret_reply = (ptlrpc_interpterer_t)osc_setattr_interpret;
+ req->rq_interpret_reply = osc_setattr_interpret;
BUILD_BUG_ON(sizeof(*sa) > sizeof(req->rq_async_args));
sa = ptlrpc_req_async_args(sa, req);
sa->sa_oa = oa;
@@ -482,6 +482,7 @@ int osc_fallocate_base(struct obd_export *exp, struct obdo *oa,
ptlrpcd_add_req(req);
return 0;
}
+EXPORT_SYMBOL(osc_fallocate_base);
static int osc_sync_interpret(const struct lu_env *env,
struct ptlrpc_request *req,