---
name: "io_uring_prep_cmd_discard"
section: "3"
platform: "linux"
package: "liburing"
version: "2.15-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/io_uring_prep_cmd_discard"
---

# io\_uring\_prep\_cmd\_discard(3)

prepare a discard command

## NAME

io\_uring\_prep\_cmd\_discard - prepare a discard command

## SYNOPSIS

```
#include <liburing.h>
```

**void io\_uring\_prep\_cmd\_discard(struct io\_uring\_sqe \****sqe***,**                           **int** *fd***,**                           **uint64\_t** *offset***,**                           **uint64\_t** *nbytes***);**

## DESCRIPTION

The [**io\_uring\_prep\_cmd\_discard**(3)](/io_uring_prep_cmd_discard/3.md) function prepares a discard command request. The submission queue entry *sqe* is setup to use the file descriptor *fd* to start discarding *nbytes* at the specified *offset*.

The command is an asynchronous equivalent of **BLOCK\_URING\_CMD\_DISCARD** ioctl with a few differences. It allows multiple parallel discards, and it does not exclude concurrent writes and reads. As a result, it may lead to races for the data on the disk, if the application has IO inflight for the same ranges that the discard operates on. It's the user's responsibility to account for that. Furthermore, only best efforts are done to invalidate page caches. The user has to make sure that no other inflight requests are modifying or reading the range(s). If that is the case, it might result in stale page cache and data inconsistencies.

Available since 6.12.

## RETURN VALUE

None

## ERRORS

The CQE *res* field will contain the result of the operation. On success, this field will be set to **0 .** On error, a negative error value is returned. Note that where synchronous system calls will return **-1** on failure and set *errno* to the actual error value, io\_uring never uses *errno*. Instead it returns the negated *errno* directly in the CQE *res* field.

## SEE ALSO

[**io\_uring\_get\_sqe**(3)](/io_uring_get_sqe/3.md), [**io\_uring\_submit**(3)](/io_uring_submit/3.md),
